nysol 3.0.0-universal-darwin-13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/blueKiller.rb +17 -0
- data/bin/mdistcopy.rb +89 -0
- data/bin/meach.rb +284 -0
- data/bin/meachc.rb +288 -0
- data/bin/msend.rb +95 -0
- data/bin/mtempclean.rb +33 -0
- data/ext/mcsvin/extconf.rb +15 -0
- data/ext/mcsvout/extconf.rb +14 -0
- data/ext/mmethods/extconf.rb +12 -0
- data/ext/mtable/extconf.rb +12 -0
- data/lib/nysol/margs.rb +402 -0
- data/lib/nysol/mcmd.rb +44 -0
- data/lib/nysol/mcsvin.bundle +0 -0
- data/lib/nysol/mcsvout.bundle +0 -0
- data/lib/nysol/mmethods.bundle +0 -0
- data/lib/nysol/mnettools.rb +220 -0
- data/lib/nysol/mparallel.rb +359 -0
- data/lib/nysol/mparallelmanager.rb +300 -0
- data/lib/nysol/mrubyparse.rb +538 -0
- data/lib/nysol/msysteminfo.rb +216 -0
- data/lib/nysol/mtable.bundle +0 -0
- data/lib/nysol/mtemp.rb +268 -0
- data/lib/nysol/mutils.rb +218 -0
- metadata +131 -0
@@ -0,0 +1,300 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#/* ////////// LICENSE INFO ////////////////////
|
3
|
+
#
|
4
|
+
# * Copyright (C) 2013 by NYSOL CORPORATION
|
5
|
+
# *
|
6
|
+
# * Unless you have received this program directly from NYSOL pursuant
|
7
|
+
# * to the terms of a commercial license agreement with NYSOL, then
|
8
|
+
# * this program is licensed to you under the terms of the GNU Affero General
|
9
|
+
# * Public License (AGPL) as published by the Free Software Foundation,
|
10
|
+
# * either version 3 of the License, or (at your option) any later version.
|
11
|
+
# *
|
12
|
+
# * This program is distributed in the hope that it will be useful, but
|
13
|
+
# * WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF
|
14
|
+
# * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
+
# *
|
16
|
+
# * Please refer to the AGPL (http://www.gnu.org/licenses/agpl-3.0.txt)
|
17
|
+
# * for more details.
|
18
|
+
#
|
19
|
+
# ////////// LICENSE INFO ////////////////////*/
|
20
|
+
require "nysol/msysteminfo"
|
21
|
+
module MCMD
|
22
|
+
|
23
|
+
class MpcManager
|
24
|
+
def initialize(fn="/etc/pclist")
|
25
|
+
@localIP = MCMD::SysInfo.getMyIP
|
26
|
+
@pcIP = []
|
27
|
+
@pcUID = []
|
28
|
+
@pcPWD = []
|
29
|
+
@ip2No = {}
|
30
|
+
File.open(fn){|fp|
|
31
|
+
while lin = fp.gets do
|
32
|
+
next if lin =~ /^#/
|
33
|
+
lins = lin.chomp.split
|
34
|
+
@pcIP << lins[1]
|
35
|
+
@pcUID << lins[0]
|
36
|
+
@pcPWD << lins[2]
|
37
|
+
@ip2No[lins[1]] = @pcIP.size-1
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
41
|
+
def each
|
42
|
+
(0...@pcIP.size).each{|i|
|
43
|
+
yield @pcIP[i],@pcUID[i],@pcPWD[i]
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def pcCount
|
49
|
+
return @pcIP.size
|
50
|
+
end
|
51
|
+
def getIP(no)
|
52
|
+
return @pcIP[no]
|
53
|
+
end
|
54
|
+
def getUID(no)
|
55
|
+
return @pcUID[no]
|
56
|
+
end
|
57
|
+
def getPWD(no)
|
58
|
+
return @pcPWD[no]
|
59
|
+
end
|
60
|
+
def has_IP?(ip)
|
61
|
+
return @ip2No.has_key?(ip)
|
62
|
+
end
|
63
|
+
|
64
|
+
def getUIDbyIP(ip)
|
65
|
+
return nil unless @ip2No.has_key?(ip)
|
66
|
+
return getUID(@ip2No[ip])
|
67
|
+
end
|
68
|
+
def getPWDbyIP(ip)
|
69
|
+
return nil unless @ip2No.has_key?(ip)
|
70
|
+
return getPWD(@ip2No[ip])
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
attr_reader :localIP
|
75
|
+
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
class MparallelManager
|
81
|
+
|
82
|
+
def initialize(mp=4,tim=-1)
|
83
|
+
@mp = mp # パラレルサイズ
|
84
|
+
@thInterval = tim # チェック間隔
|
85
|
+
@runpid = {} # pid => laneNo ## 動いてるPROCESS
|
86
|
+
@slppid = [] # [ [pid ,laneNo child pid] ... ## 休止中PROCESS
|
87
|
+
@mtx = Mutex.new if @thInterval > 0
|
88
|
+
@LaneQue = Array.new(mp){|i| i }
|
89
|
+
end
|
90
|
+
|
91
|
+
def emptyLQ?
|
92
|
+
@LaneQue.empty?
|
93
|
+
end
|
94
|
+
|
95
|
+
# プロセス終了確認
|
96
|
+
def waitLane
|
97
|
+
finLane =[]
|
98
|
+
loop{
|
99
|
+
begin
|
100
|
+
rpid = nil
|
101
|
+
sts = nil
|
102
|
+
loop{
|
103
|
+
@runpid.each{|k,v|
|
104
|
+
rpid ,sts = Process.waitpid2(k,Process::WNOHANG)
|
105
|
+
break unless rpid == nil
|
106
|
+
}
|
107
|
+
break unless rpid == nil
|
108
|
+
}
|
109
|
+
rescue
|
110
|
+
if @mtx then
|
111
|
+
@mtx.synchronize {
|
112
|
+
@runpid.each{|k,v|
|
113
|
+
finLane.push(v)
|
114
|
+
@LaneQue.push(v)
|
115
|
+
}
|
116
|
+
@runpid.clear
|
117
|
+
}
|
118
|
+
else
|
119
|
+
@runpid.each{|k,v|
|
120
|
+
finLane.push(v)
|
121
|
+
@LaneQue.push(v)
|
122
|
+
}
|
123
|
+
@runpid.clear
|
124
|
+
end
|
125
|
+
break
|
126
|
+
end
|
127
|
+
new_pno = nil
|
128
|
+
if @mtx then
|
129
|
+
@mtx.synchronize {
|
130
|
+
new_pno = @runpid.delete(rpid)
|
131
|
+
}
|
132
|
+
else
|
133
|
+
new_pno = @runpid.delete(rpid)
|
134
|
+
end
|
135
|
+
if new_pno != nil then
|
136
|
+
finLane.push(new_pno)
|
137
|
+
@LaneQue.push(new_pno)
|
138
|
+
break
|
139
|
+
end
|
140
|
+
}
|
141
|
+
return finLane
|
142
|
+
end
|
143
|
+
|
144
|
+
# 全プロセス終了確認
|
145
|
+
def waitall
|
146
|
+
rtn = []
|
147
|
+
while !@runpid.empty? or !@slppid.empty? do
|
148
|
+
rtn.concat(waitLane)
|
149
|
+
end
|
150
|
+
return rtn
|
151
|
+
end
|
152
|
+
|
153
|
+
# 空き実行レーン取得
|
154
|
+
def getLane(wait=true)
|
155
|
+
waitLane if wait and @LaneQue.empty?
|
156
|
+
return @LaneQue.shift
|
157
|
+
end
|
158
|
+
|
159
|
+
# 実行PID=>lane登録
|
160
|
+
def addPid(pid,lane)
|
161
|
+
if @mtx then
|
162
|
+
@mtx.synchronize { @runpid[pid]=lane }
|
163
|
+
else
|
164
|
+
@runpid[pid]=lane
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
## メモリ,CPUチェッカー
|
169
|
+
def runStateCheker
|
170
|
+
return unless @mtx
|
171
|
+
Thread.new {
|
172
|
+
begin
|
173
|
+
loop{
|
174
|
+
if MCMD::SysInfo.LimitOver_Mem_Cpu? then
|
175
|
+
@mtx.synchronize {
|
176
|
+
if @runpid.size > 1 then
|
177
|
+
pid = @runpid.keys[0]
|
178
|
+
plist = MCMD::SysInfo.cPIDs(pid)
|
179
|
+
stopL = []
|
180
|
+
plist.reverse_each{|px|
|
181
|
+
begin
|
182
|
+
Process.kill(:STOP, px)
|
183
|
+
stopL << px
|
184
|
+
rescue => msg #STOP できなくてもスルー
|
185
|
+
puts "already finish #{px}"
|
186
|
+
next
|
187
|
+
end
|
188
|
+
}
|
189
|
+
unless stopL.empty? then
|
190
|
+
pno = @runpid.delete(pid)
|
191
|
+
@slppid << [pid,pno,stopL]
|
192
|
+
end
|
193
|
+
else
|
194
|
+
unless @slppid.empty? then
|
195
|
+
pid,pno,plist = @slppid.shift
|
196
|
+
plist.each{|px|
|
197
|
+
begin
|
198
|
+
Process.kill(:CONT, px)
|
199
|
+
rescue => msg
|
200
|
+
puts "already finish #{px}"
|
201
|
+
end
|
202
|
+
}
|
203
|
+
@runpid[pid]=pno
|
204
|
+
end
|
205
|
+
end
|
206
|
+
}
|
207
|
+
else
|
208
|
+
@mtx.synchronize {
|
209
|
+
unless @slppid.empty? then
|
210
|
+
pid,pno,plist = @slppid.shift
|
211
|
+
plist.each{|px|
|
212
|
+
begin
|
213
|
+
Process.kill(:CONT, px)
|
214
|
+
rescue => msg
|
215
|
+
puts "already finish #{px}"
|
216
|
+
end
|
217
|
+
}
|
218
|
+
@runpid[pid]=pno
|
219
|
+
end
|
220
|
+
}
|
221
|
+
end
|
222
|
+
sleep @thInterval
|
223
|
+
}
|
224
|
+
rescue => msg
|
225
|
+
p msg
|
226
|
+
exit
|
227
|
+
end
|
228
|
+
}
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
class MparallelManagerByFile < MparallelManager
|
233
|
+
def initialize(mp=16,wrk="./",tim=-1)
|
234
|
+
super(mp,tim)
|
235
|
+
@wrk =wrk
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
# ファイルでプロセス終了確認
|
240
|
+
def waitLane
|
241
|
+
finLane =[]
|
242
|
+
loop{
|
243
|
+
bFlg = false
|
244
|
+
# @runpid [No->lane]]
|
245
|
+
@runpid.each{|k,v|
|
246
|
+
next unless File.exist?("#{@wrk}/#{v}.log")
|
247
|
+
jmpF =false
|
248
|
+
File.open("#{@wrk}/#{v}.log"){|fp|
|
249
|
+
lin=fp.gets
|
250
|
+
if lin == nil then
|
251
|
+
MCMD::msgLog("UNMATCH FORMAT LOG #{@wrk}/#{v}.log")
|
252
|
+
jmpF = true
|
253
|
+
elsif lin.split[1].to_i != k then
|
254
|
+
MCMD::msgLog("UNMATCH NUMBER #{@wrk}/#{v}.log #{k}")
|
255
|
+
jmpF = true
|
256
|
+
end
|
257
|
+
}
|
258
|
+
next if jmpF
|
259
|
+
finLane.push(v)
|
260
|
+
@LaneQue.push(v)
|
261
|
+
if @runpid.delete(k) == nil then
|
262
|
+
MCMD::msgLog("NIL FIND NIL FIND")
|
263
|
+
end
|
264
|
+
File.unlink("#{@wrk}/#{v}.log")
|
265
|
+
bFlg = true
|
266
|
+
}
|
267
|
+
break if bFlg
|
268
|
+
}
|
269
|
+
return finLane
|
270
|
+
end
|
271
|
+
|
272
|
+
def addNo (no,lane)
|
273
|
+
if @mtx then
|
274
|
+
@mtx.synchronize { @runpid[no]=lane }
|
275
|
+
else
|
276
|
+
@runpid[no]=lane
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
# 空き実行レーン取得
|
282
|
+
def getLane(wait=true)
|
283
|
+
waitLane if wait and @LaneQue.empty?
|
284
|
+
return @LaneQue.shift
|
285
|
+
end
|
286
|
+
|
287
|
+
## メモリ,CPUチェッカー
|
288
|
+
def runStateCheker
|
289
|
+
#何もしない
|
290
|
+
end
|
291
|
+
|
292
|
+
def waitall
|
293
|
+
rtn = []
|
294
|
+
while !@runpid.empty? or !@slppid.empty? do
|
295
|
+
rtn.concat(waitLane)
|
296
|
+
end
|
297
|
+
return rtn
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
@@ -0,0 +1,538 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#/* ////////// LICENSE INFO ////////////////////
|
3
|
+
#
|
4
|
+
# * Copyright (C) 2013 by NYSOL CORPORATION
|
5
|
+
# *
|
6
|
+
# * Unless you have received this program directly from NYSOL pursuant
|
7
|
+
# * to the terms of a commercial license agreement with NYSOL, then
|
8
|
+
# * this program is licensed to you under the terms of the GNU Affero General
|
9
|
+
# * Public License (AGPL) as published by the Free Software Foundation,
|
10
|
+
# * either version 3 of the License, or (at your option) any later version.
|
11
|
+
# *
|
12
|
+
# * This program is distributed in the hope that it will be useful, but
|
13
|
+
# * WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF
|
14
|
+
# * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
+
# *
|
16
|
+
# * Please refer to the AGPL (http://www.gnu.org/licenses/agpl-3.0.txt)
|
17
|
+
# * for more details.
|
18
|
+
#
|
19
|
+
# ////////// LICENSE INFO ////////////////////*/
|
20
|
+
require 'nysol/mcmd'
|
21
|
+
|
22
|
+
module MCMD
|
23
|
+
class MrubyParse
|
24
|
+
@@ST_RESERVE_WORD = ["class","module","if","unless","def"]
|
25
|
+
@@ED_RESERVE_WORD = ["end"]
|
26
|
+
|
27
|
+
@@ST_RESERVE_REG = @@ST_RESERVE_WORD.maddPrefix(["^","\\s+"]).maddSuffix(["$","\\s+"])
|
28
|
+
@@ED_RESERVE_REG = @@ED_RESERVE_WORD.maddPrefix(["^","\\s+"]).maddSuffix(["$","\\s+","\\."])
|
29
|
+
@@RESERVE_REG = @@ST_RESERVE_REG.concat(@@ED_RESERVE_REG)
|
30
|
+
|
31
|
+
|
32
|
+
@@ST_BLOCK_WORD = [["{"],["do"]]
|
33
|
+
@@ED_BLOCK_WORD = [["}"],["end"]]
|
34
|
+
#@@ST_BLOCK_REG = @@ST_BLOCK_WORD.maddPrefix(["^","\\s+"]).maddSuffix(["$","\\s+"])
|
35
|
+
#@@ED_BLOCK_REG = @@ED_BLOCK_WORD.maddPrefix(["^","\\s+"]).maddSuffix(["$","\\s+"])
|
36
|
+
@@ST_BLOCK_PTN = [@@ST_BLOCK_WORD[0].maddPrefix("\\s*").maddSuffix("\\s*"),@@ST_BLOCK_WORD[1].maddPrefix(["^","\\s+"]).maddSuffix(["$","\\s+"])]
|
37
|
+
@@ED_BLOCK_PTN = [@@ED_BLOCK_WORD[0].maddPrefix("\\s*").maddSuffix("\\s*"),@@ED_BLOCK_WORD[1].maddPrefix(["^","\\s+"]).maddSuffix(["$","\\s+"])]
|
38
|
+
|
39
|
+
|
40
|
+
def initialize(infn,lin,kwd,value)
|
41
|
+
@infn = infn
|
42
|
+
@limLin = lin
|
43
|
+
@kwd =kwd
|
44
|
+
@values =value
|
45
|
+
@ldata = ""
|
46
|
+
@blktype = 0
|
47
|
+
@stCnt = 0
|
48
|
+
@edCnt = 0
|
49
|
+
@stBLKCnt = 0
|
50
|
+
@edBLKCnt = 0
|
51
|
+
@recCnt = 0
|
52
|
+
@outFLG = false
|
53
|
+
@argST_FLG = false
|
54
|
+
@argED_FLG = false
|
55
|
+
@reqinfo = false
|
56
|
+
@state = 0
|
57
|
+
@outdata =[]
|
58
|
+
@reqdata =[]
|
59
|
+
@argsV =[]
|
60
|
+
@outline =""
|
61
|
+
@blkPtn = 0
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def skip_space(pos)
|
66
|
+
return nil if pos==nil
|
67
|
+
rpos = @ldata.index(/\S/,pos)
|
68
|
+
if rpos == nil then
|
69
|
+
if @ldata.size == 0 then
|
70
|
+
rpos = pos
|
71
|
+
else
|
72
|
+
rpos = @ldata.size-1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
return rpos
|
76
|
+
end
|
77
|
+
|
78
|
+
def match_Reserve(ldata,pos)
|
79
|
+
return nil if pos ==nil
|
80
|
+
lldata = ldata[pos..-1]
|
81
|
+
|
82
|
+
@@ST_RESERVE_WORD.each{|reserv|
|
83
|
+
return reserv if lldata.index(/^#{reserv}/)
|
84
|
+
}
|
85
|
+
@@ED_RESERVE_WORD.each{|reserv|
|
86
|
+
return reserv if lldata.index(/^#{reserv}/)
|
87
|
+
}
|
88
|
+
return nil
|
89
|
+
end
|
90
|
+
|
91
|
+
def match_BlkReserve(ldata,pos)
|
92
|
+
return nil if pos ==nil
|
93
|
+
lldata = ldata[pos..-1]
|
94
|
+
@@ST_BLOCK_WORD[@blktype].each{|reserv|
|
95
|
+
return reserv if lldata.index(/^#{reserv}/)
|
96
|
+
}
|
97
|
+
@@ED_BLOCK_WORD[@blktype].each{|reserv|
|
98
|
+
return reserv if lldata.index(/^#{reserv}/)
|
99
|
+
}
|
100
|
+
return nil
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def analyze_blk_sub
|
105
|
+
if @ldata =~ /^\s*#/ then
|
106
|
+
@ldata =""
|
107
|
+
return
|
108
|
+
end
|
109
|
+
if @edCnt == @stCnt and @ldata =~ /^\s*require\s/ then
|
110
|
+
@outdata << @ldata
|
111
|
+
@ldata =""
|
112
|
+
return
|
113
|
+
end
|
114
|
+
pos = 0
|
115
|
+
pos = @ldata.index(/#{@@RESERVE_REG.join('|')}/,pos)
|
116
|
+
pos = skip_space(pos)
|
117
|
+
kwd = match_Reserve(@ldata,pos)
|
118
|
+
if pos == nil then
|
119
|
+
@outline << @ldata if @outFLG
|
120
|
+
pos = @ldata.size
|
121
|
+
elsif kwd == "end" then
|
122
|
+
@edCnt +=1
|
123
|
+
pos += kwd.size
|
124
|
+
@outline << @ldata[0...pos] if @outFLG
|
125
|
+
@outFLG =false if @edCnt == @stCnt
|
126
|
+
elsif kwd == "if" || kwd == "unless" then
|
127
|
+
@stCnt +=1 if @ldata[0...pos].index(/\S/) == nil
|
128
|
+
pos += kwd.size
|
129
|
+
@outline << @ldata[0...pos] if @outFLG
|
130
|
+
else
|
131
|
+
@stCnt +=1
|
132
|
+
pos += kwd.size
|
133
|
+
@outFLG =true
|
134
|
+
@outline << @ldata[0...pos] if @outFLG
|
135
|
+
end
|
136
|
+
@ldata = @ldata[pos..-1]
|
137
|
+
# 行終了
|
138
|
+
if @ldata.size==0 then
|
139
|
+
if @outline.size != 0 then
|
140
|
+
@outdata << @outline
|
141
|
+
@recCnt += 1
|
142
|
+
end
|
143
|
+
@recCnt = 0 if @edCnt == @stCnt
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# skip,add_stcnt,add_edcnt,chgoutF
|
148
|
+
def analyze_blk_start
|
149
|
+
sp = @ldata.match(/(.*)#{@kwd}(#{@@ST_BLOCK_PTN[0].join('|')}|#{@@ST_BLOCK_PTN[1].join('|')})(.*)/)
|
150
|
+
sp = @ldata.match(/(.*)#{@kwd}\s*\(.*\)\s*(#{@@ST_BLOCK_PTN[0].join('|')}|#{@@ST_BLOCK_PTN[1].join('|')})(.*)/) if sp == nil
|
151
|
+
@blkPtn = 1 if sp[2].include?("do")
|
152
|
+
@ldata = sp[3]
|
153
|
+
end
|
154
|
+
|
155
|
+
def analyze_args
|
156
|
+
@ldata.lstrip!
|
157
|
+
return if @ldata.size==0
|
158
|
+
unless @argST_FLG then
|
159
|
+
raise "format ERROR" if @ldata[0]!="|"
|
160
|
+
@ldata=@ldata[1..-1]
|
161
|
+
@argST_FLG = true
|
162
|
+
end
|
163
|
+
out=""
|
164
|
+
unless @argED_FLG then
|
165
|
+
pos=0
|
166
|
+
while pos < @ldata.size do
|
167
|
+
case @ldata[pos]
|
168
|
+
when ","
|
169
|
+
@argsV << out
|
170
|
+
out =""
|
171
|
+
when "|"
|
172
|
+
@argsV << out
|
173
|
+
out =""
|
174
|
+
@argED_FLG = true
|
175
|
+
else
|
176
|
+
out << @ldata[pos]
|
177
|
+
end
|
178
|
+
pos += 1
|
179
|
+
break if @argED_FLG
|
180
|
+
end
|
181
|
+
@ldata = @ldata[pos..-1]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def analyze_blk
|
186
|
+
pos = 0
|
187
|
+
loop{
|
188
|
+
pos = @ldata.index(/(#{@@ST_BLOCK_PTN[@blkPtn].join('|')}|#{@@ED_BLOCK_PTN[@blkPtn].join('|')})(.*)/)
|
189
|
+
pos = skip_space(pos)
|
190
|
+
kwd = match_BlkReserve(@ldata,pos)
|
191
|
+
if pos == nil then
|
192
|
+
@outline << @ldata
|
193
|
+
pos = @ldata.size
|
194
|
+
else
|
195
|
+
case kwd
|
196
|
+
when "do","{"
|
197
|
+
@stBLKCnt+=1
|
198
|
+
when "end","}"
|
199
|
+
@edBLKCnt+=1
|
200
|
+
end
|
201
|
+
if @stBLKCnt == @edBLKCnt then
|
202
|
+
@outline << @ldata[0...pos]
|
203
|
+
pos = pos+kwd.size
|
204
|
+
else
|
205
|
+
pos = pos+kwd.size
|
206
|
+
@outline << @ldata[0...pos]
|
207
|
+
end
|
208
|
+
end
|
209
|
+
@ldata = @ldata[pos..-1]
|
210
|
+
break if @ldata.size == 0
|
211
|
+
break if @stBLKCnt == @edBLKCnt
|
212
|
+
}
|
213
|
+
end
|
214
|
+
|
215
|
+
def output(outfn)
|
216
|
+
File.open(outfn,"w"){|ofp|
|
217
|
+
ofp.puts("#!/usr/bin/env ruby")
|
218
|
+
ofp.puts("# -*- coding: utf-8 -*- ")
|
219
|
+
File.open(@infn,"r"){|ifp|
|
220
|
+
ifp.each_line do | ldata |
|
221
|
+
@outline = ""
|
222
|
+
@ldata = ldata.chomp
|
223
|
+
loop{
|
224
|
+
break if @ldata.size==0
|
225
|
+
case @state
|
226
|
+
when 0 # kwd(m2each) block前
|
227
|
+
if ifp.lineno == @limLin then
|
228
|
+
@state = 1 ; next ;
|
229
|
+
end
|
230
|
+
analyze_blk_sub()
|
231
|
+
when 1 # kwd(m2each) 行
|
232
|
+
analyze_blk_start()
|
233
|
+
@outFLG = false
|
234
|
+
@stBLKCnt += 1
|
235
|
+
@state = 2
|
236
|
+
outrqCHK =[]
|
237
|
+
@recCnt.times{ #requireは出力する
|
238
|
+
chkword = @outdata.pop
|
239
|
+
outrqCHK << chkword if @ldata =~ /^\s*require\s/
|
240
|
+
}
|
241
|
+
@outdata.each{|ld| ofp.puts(ld) }
|
242
|
+
outrqCHK.each{|ld| ofp.puts(ld) }
|
243
|
+
@values.each {|ld| ofp.puts(ld) }
|
244
|
+
@outdata=[]
|
245
|
+
when 2 # kwd(m2each) 引数
|
246
|
+
analyze_args()
|
247
|
+
if @argED_FLG then
|
248
|
+
@argsV.each_with_index{|v,i|
|
249
|
+
if i==0 then
|
250
|
+
ofp.puts("#{v} = ARGV[#{i}].split(',')")
|
251
|
+
ofp.puts("#{v} = #{v}[0] if #{v}.size==1")
|
252
|
+
else
|
253
|
+
ofp.puts("#{v} = ARGV[#{i}].to_i")
|
254
|
+
end
|
255
|
+
}
|
256
|
+
@state = 3
|
257
|
+
end
|
258
|
+
when 3 # kwd(m2each) ブロック
|
259
|
+
analyze_blk()
|
260
|
+
if @stBLKCnt == @edBLKCnt || @ldata.size == 0 then
|
261
|
+
ofp.puts(@outline)
|
262
|
+
@state = 4 if @stBLKCnt == @edBLKCnt
|
263
|
+
end
|
264
|
+
when 4 # end check
|
265
|
+
analyze_blk_sub()
|
266
|
+
if @edCnt == @stCnt then
|
267
|
+
@outdata=[]
|
268
|
+
@state = 5
|
269
|
+
end
|
270
|
+
when 5 # end check
|
271
|
+
analyze_blk_sub()
|
272
|
+
end
|
273
|
+
break if @ldata.size==0
|
274
|
+
}
|
275
|
+
end
|
276
|
+
@outdata.each{|ld| ofp.puts(ld) }
|
277
|
+
}
|
278
|
+
}
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
# inf:ソースファイル , lin:読み込み開始業 out:出力ファイル名 kwd:m2each,出力するローカル変数
|
283
|
+
def MCMD::outputblk(inf,lin,outf,kwd,values=[])
|
284
|
+
|
285
|
+
|
286
|
+
s_char_ex = ["\\s+class\\s+|^class\\s+|\\s+class$|^class$",
|
287
|
+
"\\s+module\\s+|^module\\s+|\\s+module$|^module$",
|
288
|
+
"\\s+if\\s+|^if\\s+|\\s+if$|^if$",
|
289
|
+
"\\s+def\\s+|^def\\s+|\\s+def$|^def$" ]
|
290
|
+
e_char_ex = ["\\s+end\\s+|^end\\s+|\\s+end\.|^end\.|\\s+end$|^end$"]
|
291
|
+
|
292
|
+
|
293
|
+
s_char = ["\\s*{\\s*","\\s+do\\s+|^do\\s+|\\s+do$|^do$" ]
|
294
|
+
e_char = ["\\s*}\\s*","\\s+end\\s+|^end\\s+|\\s+end\.|^end\.|\\s+end$|^end$"]
|
295
|
+
regpos = 0
|
296
|
+
nowL=0
|
297
|
+
start = false
|
298
|
+
arg = false
|
299
|
+
arg_s = false
|
300
|
+
blk_e = false
|
301
|
+
s_ch_cnt= 0
|
302
|
+
e_ch_cnt= 0
|
303
|
+
oscript = ""
|
304
|
+
args=[]
|
305
|
+
reqiureinfo=[]
|
306
|
+
afterinfo=[]
|
307
|
+
stcnt_ex =0
|
308
|
+
edcnt_ex =0
|
309
|
+
outF=false
|
310
|
+
reccnt=0
|
311
|
+
#開始行kwdの位置を決定してその後ブロックを抜き出す
|
312
|
+
File.open(outf,"w"){|ofp|
|
313
|
+
File.open(inf,"r"){|ifp|
|
314
|
+
while ldata = ifp.gets do
|
315
|
+
nowL+=1
|
316
|
+
if nowL < lin then
|
317
|
+
if ldata =~ /^\s*require\s|^\s*#/
|
318
|
+
reqiureinfo << ldata
|
319
|
+
reccnt +=1
|
320
|
+
next
|
321
|
+
end
|
322
|
+
ofset_e=0
|
323
|
+
out_e=""
|
324
|
+
loop {
|
325
|
+
pos_e = ldata.index(/(#{s_char_ex.join('|')}|#{e_char_ex[0]})/,ofset_e)
|
326
|
+
if pos_e != nil then
|
327
|
+
while pos_e < ldata.length do
|
328
|
+
break unless ldata[pos_e].match(/\s/)
|
329
|
+
pos_e+=1
|
330
|
+
end
|
331
|
+
case ldata[pos_e]
|
332
|
+
when "c" then
|
333
|
+
pos_e+=5
|
334
|
+
stcnt_ex+=1
|
335
|
+
outF = true
|
336
|
+
out_e << ldata[0...pos_e] if outF
|
337
|
+
when "m" then
|
338
|
+
pos_e+=6
|
339
|
+
stcnt_ex+=1
|
340
|
+
outF = true
|
341
|
+
out_e << ldata[0...pos_e] if outF
|
342
|
+
when "d" then
|
343
|
+
pos_e+=3
|
344
|
+
stcnt_ex+=1
|
345
|
+
outF = true
|
346
|
+
out_e << ldata[0...pos_e] if outF
|
347
|
+
when "i" then
|
348
|
+
## 後ろif(空白以外あり)
|
349
|
+
if ldata[0...pos_e].index(/\S/) != nil then
|
350
|
+
pos_e+=2
|
351
|
+
out_e << ldata[0...pos_e] if outF
|
352
|
+
else
|
353
|
+
pos_e+=2
|
354
|
+
out_e << ldata[0...pos_e] if outF
|
355
|
+
stcnt_ex+=1
|
356
|
+
end
|
357
|
+
|
358
|
+
when "e" then
|
359
|
+
pos_e+=3
|
360
|
+
edcnt_ex+=1
|
361
|
+
out_e << ldata[0...pos_e] if outF
|
362
|
+
outF = false if stcnt_ex == edcnt_ex
|
363
|
+
|
364
|
+
end
|
365
|
+
else
|
366
|
+
out_e << ldata if outF
|
367
|
+
reqiureinfo << out_e
|
368
|
+
reccnt +=1
|
369
|
+
reccnt =0 if stcnt_ex == edcnt_ex
|
370
|
+
break
|
371
|
+
end
|
372
|
+
ldata=ldata[pos_e..-1]
|
373
|
+
}
|
374
|
+
next
|
375
|
+
end
|
376
|
+
# 開始チェック
|
377
|
+
unless start then
|
378
|
+
# start 位置 "v1".m2each"v2" "v3"
|
379
|
+
sp = ldata.match(/(.*)#{kwd}(#{s_char[0]}|#{s_char[1]})(.*)/)
|
380
|
+
sp = ldata.match(/(.*)#{kwd}\s*\(.*\)\s*(#{s_char[0]}|#{s_char[1]})(.*)/) if sp == nil
|
381
|
+
regpos = 1 if sp[2].include?("do")
|
382
|
+
ldata = sp[3]
|
383
|
+
start = true
|
384
|
+
outF =false
|
385
|
+
s_ch_cnt+=1
|
386
|
+
reccnt.times{ reqiureinfo.pop }
|
387
|
+
reqiureinfo.each{|ld| ofp.puts(ld) }
|
388
|
+
values.each{|ld| ofp.puts(ld) }
|
389
|
+
end
|
390
|
+
# argsチェック
|
391
|
+
unless arg then
|
392
|
+
ldata.lstrip!
|
393
|
+
next if ldata.length == 0
|
394
|
+
unless arg_s then
|
395
|
+
raise "format error" if ldata[0]!="|"
|
396
|
+
ldata = ldata[1..-1]
|
397
|
+
arg_s =true
|
398
|
+
end
|
399
|
+
pos=0
|
400
|
+
out =""
|
401
|
+
while pos < ldata.length do
|
402
|
+
case ldata[pos]
|
403
|
+
when ","
|
404
|
+
args << out
|
405
|
+
out =""
|
406
|
+
when "|"
|
407
|
+
args << out
|
408
|
+
out =""
|
409
|
+
arg = true
|
410
|
+
pos += 1
|
411
|
+
break
|
412
|
+
else
|
413
|
+
out << ldata[pos]
|
414
|
+
end
|
415
|
+
pos += 1
|
416
|
+
end
|
417
|
+
next unless arg
|
418
|
+
ldata =ldata[pos..-1]
|
419
|
+
args.each_with_index{|d,i|
|
420
|
+
if i==0 then
|
421
|
+
ofp.puts("#{d} = ARGV[#{i}].split(',')")
|
422
|
+
ofp.puts("#{d} = #{d}[0] if #{d}.size==1")
|
423
|
+
|
424
|
+
else
|
425
|
+
ofp.puts("#{d} = ARGV[#{i}].to_i")
|
426
|
+
end
|
427
|
+
}
|
428
|
+
end
|
429
|
+
unless blk_e then
|
430
|
+
offset=0
|
431
|
+
out =""
|
432
|
+
loop {
|
433
|
+
pos = ldata.index(/#{s_char[regpos]}|#{e_char[regpos]}/,offset)
|
434
|
+
if pos == nil then
|
435
|
+
out = ldata
|
436
|
+
break
|
437
|
+
end
|
438
|
+
while pos < ldata.length do
|
439
|
+
break unless ldata[pos].match(/\s/)
|
440
|
+
pos+=1
|
441
|
+
end
|
442
|
+
case ldata[pos]
|
443
|
+
when "d" then
|
444
|
+
s_ch_cnt+= 1
|
445
|
+
offset = pos+2
|
446
|
+
when "e" then
|
447
|
+
e_ch_cnt+= 1
|
448
|
+
offset = pos+3
|
449
|
+
when "{" then
|
450
|
+
s_ch_cnt+= 1
|
451
|
+
offset = pos+1
|
452
|
+
when "}" then
|
453
|
+
e_ch_cnt+= 1
|
454
|
+
offset = pos+1
|
455
|
+
end
|
456
|
+
if s_ch_cnt == e_ch_cnt then
|
457
|
+
out = ldata[0...pos]
|
458
|
+
ldata =ldata[pos..-1]
|
459
|
+
break
|
460
|
+
end
|
461
|
+
}
|
462
|
+
ofp.puts out
|
463
|
+
blk_e = true if s_ch_cnt == e_ch_cnt
|
464
|
+
next unless blk_e
|
465
|
+
end
|
466
|
+
# block以降
|
467
|
+
if ldata =~ /^\s*require\s|^\s*#/
|
468
|
+
afterinfo << ldata
|
469
|
+
reccnt +=1
|
470
|
+
next
|
471
|
+
end
|
472
|
+
ofset_e=0
|
473
|
+
out_e=""
|
474
|
+
loop {
|
475
|
+
pos_e = ldata.index(/(#{s_char_ex.join('|')}|#{e_char_ex[0]})/,ofset_e)
|
476
|
+
if pos_e != nil then
|
477
|
+
while pos_e < ldata.length do
|
478
|
+
break unless ldata[pos_e].match(/\s/)
|
479
|
+
pos_e+=1
|
480
|
+
end
|
481
|
+
case ldata[pos_e]
|
482
|
+
when "c" then
|
483
|
+
pos_e+=5
|
484
|
+
stcnt_ex+=1
|
485
|
+
out_e << ldata[0...pos_e] if outF
|
486
|
+
when "m" then
|
487
|
+
pos_e+=6
|
488
|
+
stcnt_ex+=1
|
489
|
+
out_e << ldata[0...pos_e] if outF
|
490
|
+
when "d" then
|
491
|
+
pos_e+=3
|
492
|
+
stcnt_ex+=1
|
493
|
+
out_e << ldata[0...pos_e] if outF
|
494
|
+
when "i" then
|
495
|
+
## 後ろif(空白以外あり)
|
496
|
+
if ldata[0...pos_e].index(/\S/) != nil then
|
497
|
+
pos_e+=2
|
498
|
+
out_e << ldata[0...pos_e] if outF
|
499
|
+
else
|
500
|
+
pos_e+=2
|
501
|
+
out_e << ldata[0...pos_e] if outF
|
502
|
+
stcnt_ex+=1
|
503
|
+
end
|
504
|
+
|
505
|
+
when "e" then
|
506
|
+
pos_e+=3
|
507
|
+
edcnt_ex+=1
|
508
|
+
out_e << ldata[0...pos_e] if outF
|
509
|
+
outF = false if stcnt_ex == edcnt_ex
|
510
|
+
|
511
|
+
end
|
512
|
+
else
|
513
|
+
out_e << ldata if stcnt_ex != edcnt_ex && outF
|
514
|
+
afterinfo << out_e
|
515
|
+
reccnt +=1
|
516
|
+
reccnt =0 if stcnt_ex == edcnt_ex
|
517
|
+
break
|
518
|
+
end
|
519
|
+
ldata=ldata[pos_e..-1]
|
520
|
+
}
|
521
|
+
end
|
522
|
+
afterinfo.each{|ld| ofp.puts(ld) }
|
523
|
+
}
|
524
|
+
}
|
525
|
+
|
526
|
+
end
|
527
|
+
|
528
|
+
|
529
|
+
end
|
530
|
+
|
531
|
+
if __FILE__ == $0 then
|
532
|
+
infn= ARGV[0]
|
533
|
+
lin= ARGV[1].to_i
|
534
|
+
tag= ARGV[2]
|
535
|
+
|
536
|
+
MCMD::MrubyParse.new(infn,lin,tag,[]).output("xxxx_#{tag}_#{lin}")
|
537
|
+
|
538
|
+
end
|