• 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

Revisionfd5fbab09273fa440075895004141974f1e21d4a (tree)
Time2015-05-30 16:55:47
AuthorShyouzou Sugitani <shy@user...>
CommiterShyouzou Sugitani

Log Message

assorted fixes(27)

Change Summary

Incremental Difference

--- a/lib/ninix/communicate.rb
+++ b/lib/ninix/communicate.rb
@@ -125,13 +125,13 @@ module Communicate
125125 end
126126 refs = refs.join('\x01')
127127 Logging::Logging.debug("NOTIFY OTHER: " \
128- + on_other_event + ", " \
129- + name + ", " \
130- + self_name + ", " \
131- + flags + ", " \
132- + event + ", " \
133- + script + ", " \
134- + refs)
128+ + on_other_event.to_s + ", " \
129+ + name.to_s + ", " \
130+ + selfname.to_s + ", " \
131+ + flags.to_s + ", " \
132+ + event.to_s + ", " \
133+ + script.to_s + ", " \
134+ + refs.to_s)
135135 args = [name, selfname, flags, event, script, refs]
136136 else # XXX: should not reach here
137137 return
--- a/lib/ninix/sakura.rb
+++ b/lib/ninix/sakura.rb
@@ -279,10 +279,10 @@ module Sakura
279279 path = File.join(get_prefix(), 'HISTORY')
280280 begin
281281 open(path, 'w') do |file|
282- file.write("time, ", @ghost_time.to_s, "\n")
283- file.write("vanished_count, ", @vanished_count.to_s, "\n")
282+ file.write("time, " + @ghost_time.to_s + "\n")
283+ file.write("vanished_count, " + @vanished_count.to_s + "\n")
284284 end
285- rescue #except IOError as e:
285+ rescue IOError => e
286286 #code, message = e.args
287287 Logging::Logging.error('cannot write ' + path)
288288 end
@@ -293,13 +293,13 @@ module Sakura
293293 begin
294294 open(path, 'w') do |file|
295295 if @balloon_directory != nil
296- file.write("balloon_directory, ", @balloon_directory, "\n")
296+ file.write("balloon_directory, " + @balloon_directory + "\n")
297297 end
298298 if @shell_directory != nil
299- file.write("shell_directory, ", @shell_directory, "\n")
299+ file.write("shell_directory, " + @shell_directory + "\n")
300300 end
301301 end
302- rescue #except IOError as e:
302+ rescue IOError => e
303303 #code, message = e.args
304304 Logging::Logging.error('cannot write ' + path)
305305 end
@@ -316,23 +316,23 @@ module Sakura
316316 if not line.include?(',')
317317 next
318318 end
319- key, value = line.split(',', 1)
319+ key, value = line.split(',', 2)
320320 key = key.strip()
321321 if key == 'time'
322322 begin
323323 ghost_time = value.strip().to_i
324- rescue #except:
324+ rescue
325325 #pass
326326 end
327327 elsif key == 'vanished_count'
328328 begin
329329 ghost_vanished_count = value.strip().to_i
330- rescue #except:
330+ rescue
331331 #pass
332332 end
333333 end
334334 end
335- rescue #except IOError as e:
335+ rescue IOError => e
336336 #code, message = e.args
337337 Logging::Logging.error('cannot read ' + path)
338338 @ghost_time = ghost_time
@@ -355,7 +355,7 @@ module Sakura
355355 if not line.include?(',')
356356 next
357357 end
358- key, value = line.split(',', 1)
358+ key, value = line.split(',', 2)
359359 if key.strip() == 'balloon_directory'
360360 balloon_directory = value.strip()
361361 end
@@ -363,7 +363,7 @@ module Sakura
363363 shell_directory = value.strip()
364364 end
365365 end
366- rescue #except IOError as e:
366+ rescue IOError => e
367367 #code, message = e.args
368368 Logging::Logging.error('cannot read ' + path)
369369 end
@@ -1212,12 +1212,11 @@ module Sakura
12121212 script, communication = [default, nil]
12131213 end
12141214 if not script.empty? or (script.empty? and event != 'OnSecondChange')
1215- t = Time.new.localtime.to_a
1216- m = MONTH_NAMES[t[4] - 1]
1217- ## FIXME
1218- #Logging::Logging.debug(
1219- # '\n[{0:02d}/{1}/{2:d}:{3:02d}:{4:02d}:{5:02d} {6:+05d}]'.format(
1220- # t[2], m, t[0], t[3], t[4], t[5], (- time.timezone / 36).to_i))
1215+ t = Time.new.localtime
1216+ m = MONTH_NAMES[t.month - 1]
1217+ Logging::Logging.debug(
1218+ sprintf("\n[%02d/%s/%d:%02d:%02d:%02d %+05d]",
1219+ t.day, m, t.year, t.hour, t.min, t.sec, t.utc_offset / 36))
12211220 Logging::Logging.debug('Event: ' + event)
12221221 for n in 0..arglist.length-1
12231222 value = arglist[n]
@@ -1380,7 +1379,7 @@ module Sakura
13801379 color_r = [0, [255, color_r.to_i].min].max
13811380 color_g = [0, [255, color_g.to_i].min].max
13821381 color_b = [0, [255, color_b.to_i].min].max
1383- rescue #except:
1382+ rescue
13841383 #pass
13851384 else
13861385 background = [color_r, color_g, color_b]
@@ -1392,7 +1391,7 @@ module Sakura
13921391 color_r = [0, [255, color_r.to_i].min].max
13931392 color_g = [0, [255, color_g.to_i].min].max
13941393 color_b = [0, [255, color_b.to_i].min].max
1395- rescue #except:
1394+ rescue
13961395 #pass
13971396 else
13981397 foreground = [color_r, color_g, color_b]
@@ -1945,16 +1944,13 @@ module Sakura
19451944 @script_position = 0
19461945 while true
19471946 begin
1948- #@processed_script.extend(@script_parser.parse(script))
1949- @processed_script = @script_parser.parse(script)
1947+ @processed_script.concat(@script_parser.parse(script))
19501948 break
1951- rescue #except ninix.script.ParserError as e:
1952- #logging.error('-' * 50)
1953- #logging.error('{0}'.format(e)) # 'UTF-8'
1954- #done, script = e
1955- #@processed_script.extend(done)
1956- #else
1957- # break
1949+ rescue Script::ParserError => e
1950+ Logging::Logging.error('-' * 50)
1951+ Logging::Logging.error(e.format) # 'UTF-8'
1952+ done, script = e.get_item
1953+ @processed_script.concat(done)
19581954 end
19591955 end
19601956 @script_mode = BROWSE_MODE
@@ -1964,6 +1960,9 @@ module Sakura
19641960 @quick_session = false
19651961 set_synchronized_session(:list => [], :reset => true)
19661962 @balloon.hide_all()
1963+ if @processed_script.empty?
1964+ return
1965+ end
19671966 node = @processed_script[0]
19681967 if node[0] == Script::SCRIPT_TAG and node[1] == '\C'
19691968 @processed_script.shift
@@ -1999,7 +1998,7 @@ module Sakura
19991998 def __yen_p(args)
20001999 begin
20012000 chr_id = args[0].to_i
2002- rescue #except:
2001+ rescue ArgumentError
20032002 return
20042003 end
20052004 if chr_id >= 0
@@ -2089,7 +2088,7 @@ module Sakura
20892088 else
20902089 begin
20912090 balloon_id = (args[0].to_i / 2).to_i
2092- rescue #except ValueError:
2091+ rescue ArgumentError
20932092 balloon_id = 0
20942093 else
20952094 @balloon.set_balloon(@script_side, balloon_id)
@@ -2100,7 +2099,7 @@ module Sakura
21002099 def __yen__b(args)
21012100 begin
21022101 filename, x, y = expand_meta(args[0]).split(',')
2103- rescue #except:
2102+ rescue ArgumentError
21042103 filename, param = expand_meta(args[0]).split(',')
21052104 #assert param == 'inline'
21062105 x, y = 0, 0 ## FIXME
@@ -2132,7 +2131,7 @@ module Sakura
21322131 def __set_weight(value, unit)
21332132 begin
21342133 amount = value.to_i * unit - 0.01
2135- rescue #except ValueError:
2134+ rescue ArgumentError
21362135 amount = 0
21372136 end
21382137 if amount > 0
@@ -2237,7 +2236,7 @@ module Sakura
22372236 def __yen_i(args)
22382237 begin
22392238 actor_id = args[0].to_i
2240- rescue #except ValueError:
2239+ rescue ArgumentError
22412240 #pass
22422241 else
22432242 @surface.invoke(@script_side, actor_id)
@@ -2272,7 +2271,7 @@ module Sakura
22722271 def __yen_and(args)
22732272 begin
22742273 text = CGI.unescape_html("&" + args[0].to_s + ";")
2275- rescue #except:
2274+ rescue ArgumentError
22762275 text = nil
22772276 end
22782277 if text == nil
@@ -2284,7 +2283,7 @@ module Sakura
22842283 def __yen__m(args)
22852284 begin
22862285 num = args[0].to_i(16)
2287- rescue #except ValueError:
2286+ rescue ArgumentError
22882287 num = 0
22892288 end
22902289 if 0x20 <= num and num <= 0x7e
@@ -2569,7 +2568,7 @@ module Sakura
25692568 begin
25702569 x = args[2].to_i
25712570 y = args[3].to_i
2572- rescue #except:
2571+ rescue ArgumentError
25732572 #pass
25742573 else
25752574 @surface.set_balloon_offset(@script_side, [x, y])
@@ -2598,7 +2597,7 @@ module Sakura
25982597 @audio_player.set_state(Gst::State::NULL)
25992598 begin
26002599 track = args[2].to_i
2601- rescue #except:
2600+ rescue ArgumentError
26022601 return
26032602 end
26042603 @audio_player.set_property(
@@ -2920,7 +2919,7 @@ module Sakura
29202919 end
29212920 begin
29222921 @sstp_handle.send([data, '\n'].join(''))
2923- rescue #except socket.error:
2922+ rescue SystemCallError => e
29242923 #pass
29252924 end
29262925 end
@@ -2941,7 +2940,7 @@ module Sakura
29412940 ##logging.debug('close_sstp_handle()')
29422941 begin
29432942 @sstp_handle.close()
2944- rescue #except socket.error
2943+ rescue SystemCallError => e
29452944 #pass
29462945 end
29472946 @sstp_handle = nil
--- a/lib/ninix/script.rb
+++ b/lib/ninix/script.rb
@@ -28,75 +28,72 @@ module Script
2828 TEXT_META = 1
2929 TEXT_STRING = 2
3030
31-# class ParserError < Exception
32-#
33-# def initialize(message, error: 'strict',
34-# script: nil, src: nil, column: nil, length: nil, skip: nil)
35-# if not ['strict', 'loose'].include?(error)
36-# raise ValueError('unknown error scheme: {0}'.format(str(error)))
37-# end
38-# @message = message
39-# @error = error
40-# @script = script or []
41-# @src = src or ''
42-# @column = column
43-# @length = length or 0
44-# @skip = skip or 0
45-# end
46-#
47-# def __getitem__(n)
48-# if n == 0
49-# if @error == 'strict'
50-# return []
51-# else
52-# return @script
53-# end
54-# elsif n == 1
55-# if @error == 'strict' or @column == nil
56-# return ''
57-# else
58-# return @src[@column + @skip, @src.length]
59-# end
60-# else
61-# raise IndexError('tuple index out of range')
62-# end
63-# end
64-#
65-# def __str__
66-# if @column != nil
67-# column = @column
68-# if not @src.empty?
69-# dump = [@src[:column],
70-# '\x1b[7m',
71-# (@src[column, column + @length] or ' '),
72-# '\x1b[m',
73-# @src[column + @length, @src.length]].join('')
74-# else
75-# dump = ''
76-# end
77-# else
78-# column = '??'
79-# dump = @src
80-# end
81-# return 'ParserError: column {0}: {1}\n{2}'.format(column, @message, dump)
82-# end
83-# end
31+ class ParserError < StandardError
32+
33+ def initialize(
34+ error: 'strict',
35+ script: nil, src: nil, column: nil, length: nil, skip: nil)
36+ if not ['strict', 'loose'].include?(error)
37+ raise ValueError('unknown error scheme: {0}'.format(str(error)))
38+ end
39+ @error = error
40+ @script = script or []
41+ @src = src or ''
42+ @column = column
43+ @length = length or 0
44+ @skip = skip or 0
45+ end
46+
47+ def get_item
48+ if @error == 'strict'
49+ done = []
50+ else
51+ done = @script
52+ end
53+ if @error == 'strict' or @column == nil
54+ script = ''
55+ else
56+ script = @src[@column + @skip, @src.length]
57+ end
58+ return done, script
59+ end
60+
61+ def format
62+ if @column != nil
63+ column = @column
64+ if not @src.empty?
65+ dump = [@src[0..@column-1],
66+ '\x1b[7m',
67+ (@src[column, @length] or ' '),
68+ '\x1b[m',
69+ @src[column+@length..@src.length-1]].join('')
70+ else
71+ dump = ''
72+ end
73+ else
74+ column = '??'
75+ dump = @src
76+ end
77+ return 'ParserError: column ' + column.to_s + ': ' + message + "\n" + dump
78+ end
79+ end
8480
8581 class Parser
8682
8783 def initialize(error: 'strict')
8884 if not ['strict', 'loose'].include?(error)
89-# raise ValueError('unknown error scheme: {0}'.format(str(error)))
85+ raise ArgumentError('unknown error scheme: ' + error.to_s)
9086 end
9187 @error = error
9288 end
9389
9490 def perror(msg, position: 'column', skip: nil)
91+ print("PERROR: ", msg, "\n")
9592 if not ['column', 'eol'].include?(position)
96-# raise ValueError('unknown position scheme: ', position.to_s)
93+ raise ArgumentError('unknown position scheme: ', position.to_s)
9794 end
9895 if not ['length', 'rest', nil].include?(skip)
99-# raise ValueError('unknown skip scheme: ', skip.to_s)
96+ raise ArgumentError('unknown skip scheme: ', skip.to_s)
10097 end
10198 if position == 'column'
10299 column = @column
@@ -113,9 +110,14 @@ module Script
113110 length = 0
114111 skip = 0
115112 end
116-# return ParserError(msg, :error => @error,
117-# :script => @script, :src => @src, :column => column, :lenght => length, :skip => skip)
118- return "" # XXX
113+ raise ParserError.new( \
114+ :error => @error, \
115+ :script => @script, \
116+ :src => @src, \
117+ :column => column, \
118+ :length => length, \
119+ :skip => skip \
120+ ), msg
119121 end
120122
121123 def tokenize(s)
@@ -137,11 +139,9 @@ module Script
137139 if match != nil and match.begin(0) == pos
138140 break
139141 end
140-# else
141-# raise RuntimeError('should not reach here')
142142 end
143- if match == nil ## FIXME
144-# raise RuntimeError('should not reach here')
143+ if not match
144+ raise RuntimeError('should not reach here')
145145 end
146146 tokens << [token, match.to_s]
147147 pos += match.to_s.length
@@ -152,8 +152,8 @@ module Script
152152 def next_token
153153 begin
154154 token, lexeme = @tokens.shift
155- rescue # except IndexError:
156-# raise perror('unexpected end of script', :position => 'eol')
155+ rescue IndexError
156+ perror('unexpected end of script', :position => 'eol')
157157 end
158158 if token == nil
159159 return "", ""
@@ -187,12 +187,12 @@ module Script
187187 if not text.empty?
188188 @script << [SCRIPT_TEXT, text, @column]
189189 end
190-# raise perror('unknown tag', :skip => 'length')
190+ perror('unknown tag', :skip => 'length')
191191 elsif token == TOKEN_STRING and lexeme == '%'
192192 string_chunks << lexeme
193193 text << [TEXT_STRING, string_chunks.join('')]
194194 @script << [SCRIPT_TEXT, text, @column]
195-# raise perror('unknown meta string', :skip => 'length')
195+ perror('unknown meta string', :skip => 'length')
196196 return []
197197 end
198198 if [TOKEN_NUMBER, TOKEN_OPENED_SBRA,
@@ -281,11 +281,11 @@ module Script
281281 if not @tokens.empty? and @tokens[0][0] == TOKEN_OPENED_SBRA
282282 args = split_params(read_sbra_text())
283283 if args.length != 2
284-# raise perror('wrong number of arguments', :skip => 'length')
284+ perror('wrong number of arguments', :skip => 'length')
285285 return []
286286 end
287287 if args[1].length != 1 or not args[1][0][1]
288-# raise perror('syntax error (expected an ID)', :skip => 'length')
288+ perror('syntax error (expected an ID)', :skip => 'length')
289289 return []
290290 end
291291 arg1 = args[0]
@@ -322,7 +322,7 @@ module Script
322322 end
323323 @script << [SCRIPT_TAG, lexeme] + args + [@column, ]
324324 else
325-# raise perror('unknown tag ({0})'.format(lexeme), :skip => 'length')
325+ perror('unknown tag (' + lexeme + ')', :skip => 'length')
326326 return []
327327 end
328328 if anchor != nil
@@ -332,6 +332,7 @@ module Script
332332 else
333333 @script << [SCRIPT_TAG, '\_a', @column]
334334 end
335+## FIXME
335336 # anchor.script = @script
336337 # raise anchor
337338 return []
@@ -349,7 +350,7 @@ module Script
349350 def read_number
350351 token, number = next_token()
351352 if token != TOKEN_NUMBER
352-# raise perror('syntax error (expected a number)')
353+ perror('syntax error (expected a number)')
353354 end
354355 return number
355356 end
@@ -357,15 +358,15 @@ module Script
357358 def read_sbra_number
358359 token, lexeme = next_token()
359360 if token != TOKEN_OPENED_SBRA
360-# raise perror('syntax error (expected a square bracket)')
361+ perror('syntax error (expected a square bracket)')
361362 end
362363 token, number = next_token()
363364 if token != TOKEN_NUMBER
364-# raise perror('syntax error (expected a number)', :skip => 'length')
365+ perror('syntax error (expected a number)', :skip => 'length')
365366 end
366367 token, lexeme = next_token()
367368 if token != TOKEN_CLOSED_SBRA
368-# raise perror('syntax error (expected a square bracket)', :skip => 'length')
369+ perror('syntax error (expected a square bracket)', :skip => 'length')
369370 end
370371 return number
371372 end
@@ -373,12 +374,12 @@ module Script
373374 def read_sbra_id
374375 text = read_sbra_text()
375376 if text.length != 1
376- #raise perror('syntax error (expected a single ID)', :skip => 'length')
377+ perror('syntax error (expected a single ID)', :skip => 'length')
377378 return []
378379 end
379380 begin
380381 sbra_id = text[0][1].to_i.to_s
381- rescue # except:
382+ rescue
382383 # pass
383384 else
384385 return sbra_id
@@ -389,7 +390,7 @@ module Script
389390 def read_sbra_text
390391 token, lexeme = next_token()
391392 if token != TOKEN_OPENED_SBRA
392-# raise perror('syntax error (expected a square bracket)')
393+ perror('syntax error (expected a square bracket)')
393394 end
394395 text = []
395396 string_chunks = []
@@ -411,9 +412,10 @@ module Script
411412 elsif token == TOKEN_META
412413 text << [TEXT_META, lexeme]
413414 else
414- #raise perror('syntax error (wrong type of argument)', :skip => 'length')
415+ perror('syntax error (wrong type of argument)', :skip => 'length')
415416 return []
416417 end
418+## FIXME
417419 # else
418420 # raise perror('unexpected end of script', :position => 'eol')
419421 end
--- a/lib/ninix/sstplib.rb
+++ b/lib/ninix/sstplib.rb
@@ -141,7 +141,7 @@ module SSTPLib
141141 begin
142142 sock_domain, remote_port, remote_hostname, remote_ip = @fp.peeraddr
143143 return remote_hostname
144- rescue #except:
144+ rescue
145145 return 'localhost'
146146 end
147147 end
@@ -151,9 +151,8 @@ module SSTPLib
151151 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
152152 t = Time.now.localtime
153153 m = month_names[t.month - 1]
154- ## FIXME ##
155- return t'{0:02d}/{1}/{2:d}:{3:02d}:{4:02d}:{5:02d} {6:+05d}'.format(
156- t[2], m, t[0], t[3], t[4], t[5], (-time.timezone / 36).to_i)
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)
157156 end
158157 end
159158 end