YkLib 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +34 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +44 -0
  10. data/Rakefile +6 -0
  11. data/YkLib.gemspec +29 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/lib/YkLib/Yk/__advance__.rb +151 -0
  15. data/lib/YkLib/Yk/__defun__.rb +44 -0
  16. data/lib/YkLib/Yk/__hook__.rb +244 -0
  17. data/lib/YkLib/Yk/__minmax__.rb +123 -0
  18. data/lib/YkLib/Yk/__stdlog.rb +329 -0
  19. data/lib/YkLib/Yk/adhocLiterals/email.rb +119 -0
  20. data/lib/YkLib/Yk/adhocLiterals/path.rb +402 -0
  21. data/lib/YkLib/Yk/adhocLiterals/tag.rb +19 -0
  22. data/lib/YkLib/Yk/adhocLiterals/url.rb +36 -0
  23. data/lib/YkLib/Yk/adhocLiterals.rb +199 -0
  24. data/lib/YkLib/Yk/auto_escseq.rb +5 -0
  25. data/lib/YkLib/Yk/auto_pstore.rb +179 -0
  26. data/lib/YkLib/Yk/bsearch.rb +120 -0
  27. data/lib/YkLib/Yk/clambda.rb +309 -0
  28. data/lib/YkLib/Yk/confLine.rb +423 -0
  29. data/lib/YkLib/Yk/create_tty_width_available.rb +24 -0
  30. data/lib/YkLib/Yk/crypt.rb +26 -0
  31. data/lib/YkLib/Yk/debug2 +1 -0
  32. data/lib/YkLib/Yk/debug2.rb +473 -0
  33. data/lib/YkLib/Yk/debugout.rb +139 -0
  34. data/lib/YkLib/Yk/email_tz.rb +533 -0
  35. data/lib/YkLib/Yk/enum_expect.rb +170 -0
  36. data/lib/YkLib/Yk/errlog.rb +5 -0
  37. data/lib/YkLib/Yk/escseq.rb +59 -0
  38. data/lib/YkLib/Yk/eval_alt.rb +281 -0
  39. data/lib/YkLib/Yk/expector.rb +93 -0
  40. data/lib/YkLib/Yk/fetch.rb +556 -0
  41. data/lib/YkLib/Yk/fetch_old.rb +290 -0
  42. data/lib/YkLib/Yk/fib.rb +158 -0
  43. data/lib/YkLib/Yk/file_aux.rb +843 -0
  44. data/lib/YkLib/Yk/file_aux2.rb +919 -0
  45. data/lib/YkLib/Yk/file_aux_old.rb +160 -0
  46. data/lib/YkLib/Yk/filemod.rb +19 -0
  47. data/lib/YkLib/Yk/force_escseq.rb +3 -0
  48. data/lib/YkLib/Yk/generator__.rb +144 -0
  49. data/lib/YkLib/Yk/generator__.rb.org +139 -0
  50. data/lib/YkLib/Yk/indenter/argless_case.rb +46 -0
  51. data/lib/YkLib/Yk/indenter/each_token.rb +671 -0
  52. data/lib/YkLib/Yk/indenter/free_case.rb +313 -0
  53. data/lib/YkLib/Yk/indenter/if_less.rb +53 -0
  54. data/lib/YkLib/Yk/indenter/independent_ensure.rb +23 -0
  55. data/lib/YkLib/Yk/indenter/independent_rescue.rb +23 -0
  56. data/lib/YkLib/Yk/indenter/operand_circumflex.rb +0 -0
  57. data/lib/YkLib/Yk/indenter/operand_period.rb +16 -0
  58. data/lib/YkLib/Yk/indenter/parenless_and.rb +37 -0
  59. data/lib/YkLib/Yk/indenter/post_test.rb +48 -0
  60. data/lib/YkLib/Yk/indenter/token.rb +1525 -0
  61. data/lib/YkLib/Yk/indenter.rb +1382 -0
  62. data/lib/YkLib/Yk/inot.rb +265 -0
  63. data/lib/YkLib/Yk/intf.rb +815 -0
  64. data/lib/YkLib/Yk/io_aux.rb +1332 -0
  65. data/lib/YkLib/Yk/ioctl.rb +60 -0
  66. data/lib/YkLib/Yk/ipcc.rb +87 -0
  67. data/lib/YkLib/Yk/ipcountry.rb +207 -0
  68. data/lib/YkLib/Yk/ipv4adr.rb +318 -0
  69. data/lib/YkLib/Yk/localmail.rb +276 -0
  70. data/lib/YkLib/Yk/method_chain.rb +359 -0
  71. data/lib/YkLib/Yk/misc_tz.rb +1716 -0
  72. data/lib/YkLib/Yk/missing_method.rb +50 -0
  73. data/lib/YkLib/Yk/mojiConv.rb +257 -0
  74. data/lib/YkLib/Yk/nostdlog.rb +4 -0
  75. data/lib/YkLib/Yk/on_marshal.rb +20 -0
  76. data/lib/YkLib/Yk/overrider.rb +47 -0
  77. data/lib/YkLib/Yk/path.rb +293 -0
  78. data/lib/YkLib/Yk/path_aux.rb +883 -0
  79. data/lib/YkLib/Yk/path_aux_alt.rb +0 -0
  80. data/lib/YkLib/Yk/path_rep.rb +1267 -0
  81. data/lib/YkLib/Yk/pg_setup.rb +917 -0
  82. data/lib/YkLib/Yk/procinfo.rb +314 -0
  83. data/lib/YkLib/Yk/proclist.rb +492 -0
  84. data/lib/YkLib/Yk/property.rb +863 -0
  85. data/lib/YkLib/Yk/ranger.rb +606 -0
  86. data/lib/YkLib/Yk/resolv_tz.rb +88 -0
  87. data/lib/YkLib/Yk/rlprompt.rb +73 -0
  88. data/lib/YkLib/Yk/rootexec.rb +48 -0
  89. data/lib/YkLib/Yk/rpm-packageproxy.rb +784 -0
  90. data/lib/YkLib/Yk/rpm-packageproxy2.rb +1430 -0
  91. data/lib/YkLib/Yk/rwhen.rb +21 -0
  92. data/lib/YkLib/Yk/selector.rb +124 -0
  93. data/lib/YkLib/Yk/set.rb +170 -0
  94. data/lib/YkLib/Yk/shellquote.rb +300 -0
  95. data/lib/YkLib/Yk/sio.rb +1001 -0
  96. data/lib/YkLib/Yk/sio0.rb +835 -0
  97. data/lib/YkLib/Yk/sio_aux.rb +1524 -0
  98. data/lib/YkLib/Yk/sio_inot.rb +86 -0
  99. data/lib/YkLib/Yk/sock_aux.rb +42 -0
  100. data/lib/YkLib/Yk/spipe.rb +843 -0
  101. data/lib/YkLib/Yk/sql_table.rb +565 -0
  102. data/lib/YkLib/Yk/stdlog.rb +4 -0
  103. data/lib/YkLib/Yk/syscommand.rb +173 -0
  104. data/lib/YkLib/Yk/sysinit.rb +75 -0
  105. data/lib/YkLib/Yk/ttyFontWidth.rb +46113 -0
  106. data/lib/YkLib/Yk/tty_char.dump +0 -0
  107. data/lib/YkLib/Yk/tty_char.rb +47 -0
  108. data/lib/YkLib/Yk/tty_char_create.rb +437031 -0
  109. data/lib/YkLib/Yk/tty_char_static.rb +437016 -0
  110. data/lib/YkLib/Yk/tty_rewrite.rb +142 -0
  111. data/lib/YkLib/Yk/tty_str.rb +461 -0
  112. data/lib/YkLib/Yk/tty_width.dat.rb +114 -0
  113. data/lib/YkLib/Yk/tty_width.rb +180 -0
  114. data/lib/YkLib/Yk/tty_width_available +569 -0
  115. data/lib/YkLib/Yk/tty_width_list +0 -0
  116. data/lib/YkLib/Yk/tty_width_list.linux +280 -0
  117. data/lib/YkLib/Yk/tty_width_list.windows +324 -0
  118. data/lib/YkLib/Yk/tz_tty +0 -0
  119. data/lib/YkLib/Yk/tz_tty.rb +0 -0
  120. data/lib/YkLib/Yk/uprepos.rb +94 -0
  121. data/lib/YkLib/Yk/userinfo.rb +91 -0
  122. data/lib/YkLib/Yk/with.rb +109 -0
  123. data/lib/YkLib/version.rb +3 -0
  124. data/lib/YkLib.rb +6 -0
  125. metadata +170 -0
@@ -0,0 +1,309 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'Yk/misc_tz'
5
+
6
+
7
+ module TZLambda
8
+
9
+ class Base
10
+ instance_methods.each { |m|
11
+ if m.to_s !~ /^__/ && m.to_s != "object_id"
12
+ undef_method m
13
+ end
14
+ }
15
+ def __l_to_lambda__
16
+ self
17
+ end
18
+ def method_missing (name, *args, &bl)
19
+ MethodElem.new nil, self, name, *args, &bl
20
+ end
21
+ def hasTheme?
22
+ false
23
+ end
24
+ def call *cargs
25
+ if !hasTeme?
26
+ __call nil, *cargs
27
+ else
28
+ __call *cargs
29
+ end
30
+ end
31
+ end
32
+
33
+ class PlaceHolder < Base
34
+ def initialize pos
35
+ @pos = pos
36
+ end
37
+ def __call *cargs
38
+ cargs[@pos]
39
+ end
40
+ def coerce a
41
+ [self, a]
42
+ end
43
+ def hasTheme?
44
+ @pos == 0
45
+ end
46
+ end
47
+
48
+
49
+ class MethodElem < Base
50
+ def initialize bnd, target, name, *args, &bl
51
+ @binding = bnd
52
+ @target = target.__l_to_lambda__
53
+ @args = []
54
+ args.each do |a|
55
+ @args.push a.__l_to_lambda__
56
+ end
57
+ @block = bl
58
+ @name = name
59
+ end
60
+ def __call *cargs
61
+ args = @args.map{ |e| e.__call(*cargs)}
62
+ if !@binding
63
+ t = @target.__call(*cargs)
64
+ m = t.__send__(@name, *args, &bl)
65
+ else
66
+ args = args.map{|e| "ObjectSpace._id2ref(#{e.__id__})"}
67
+ if @block
68
+ args.push "&ObjectSpace._id2ref(#{@block.__id__})"
69
+ end
70
+ @binding.eval("#{@name} #{args.join(', ')}")
71
+ end
72
+ end
73
+ def hasTheme?
74
+ return true if @target.hasTheme?
75
+ @args.each do |a|
76
+ return true if a.hasTheme?
77
+ end
78
+ end
79
+ def to_proc
80
+ Proc.new do |*args|
81
+ __call nil, *args
82
+ end
83
+ end
84
+ end
85
+
86
+
87
+ class FixedElem < Base
88
+ def initialize obj
89
+ @obj = obj
90
+ end
91
+ def __call *cargs
92
+ return @obj
93
+ end
94
+ end
95
+
96
+
97
+ class NullElem
98
+ instance_methods.each { |m|
99
+ if m.to_s !~ /^__/ && m.to_s != "object_id"
100
+ undef_method m
101
+ end
102
+ }
103
+ def initialize bnd
104
+ @binding = bnd
105
+ end
106
+ def method_missing (name, *args, &bl)
107
+ MethodElem.new @binding, nil, name, *args, &bl
108
+ end
109
+ end
110
+
111
+ PlaceHolder0 = PlaceHolder.new 0
112
+ PlaceHolder1 = PlaceHolder.new 1
113
+ PlaceHolder2 = PlaceHolder.new 2
114
+ PlaceHolder3 = PlaceHolder.new 3
115
+ PlaceHolder4 = PlaceHolder.new 4
116
+ PlaceHolder5 = PlaceHolder.new 5
117
+ PlaceHolder6 = PlaceHolder.new 6
118
+ PlaceHolder7 = PlaceHolder.new 7
119
+ PlaceHolder8 = PlaceHolder.new 8
120
+ PlaceHolder9 = PlaceHolder.new 9
121
+ PlaceHolder10 = PlaceHolder.new 10
122
+ PlaceHolder11 = PlaceHolder.new 11
123
+ PlaceHolder12 = PlaceHolder.new 12
124
+ PlaceHolder13 = PlaceHolder.new 13
125
+ PlaceHolder14 = PlaceHolder.new 14
126
+ PlaceHolder15 = PlaceHolder.new 15
127
+ PlaceHolder16 = PlaceHolder.new 16
128
+ PlaceHolder17 = PlaceHolder.new 17
129
+ PlaceHolder18 = PlaceHolder.new 18
130
+ PlaceHolder19 = PlaceHolder.new 19
131
+ PlaceHolder20 = PlaceHolder.new 20
132
+
133
+ class MethodCall
134
+ instance_methods.each { |m|
135
+ if m.to_s !~ /^__/ && m.to_s != "object_id"
136
+ undef_method m
137
+ end
138
+ }
139
+ def initialize bnd, obj, mode
140
+ @binding = bnd
141
+ @mode = mode
142
+ @obj = obj
143
+ end
144
+ def method_missing name, *args, &bl
145
+ name = @mode + name.to_s
146
+ @binding.eval(name).__send__(:__call, @obj, *args, &bl)
147
+ end
148
+ end
149
+
150
+ class CallBlock
151
+ instance_methods.each { |m|
152
+ if m.to_s !~ /^__/ && m.to_s != "object_id"
153
+ undef_method m
154
+ end
155
+ }
156
+ def initialize bnd, obj, rflag = false
157
+ @binding = bnd
158
+ @obj = obj
159
+ @rflag = rflag
160
+ end
161
+ def method_missing name, *args
162
+ bl = args.pop
163
+ if @obj
164
+ res = @obj.__send__(name, *args, &bl)
165
+ if @rflag
166
+ @obj.replace res
167
+ else
168
+ res
169
+ end
170
+ else
171
+ args._!.map{|e| "ObjectSpace._id2ref(#{e.__id__})"}
172
+ args.push "&ObjectSpace._id2ref(#{bl.to_proc.__id__})"
173
+ res = @binding.eval("#{name} #{args.join(', ')}")
174
+ if @rflag
175
+ @binding.eval("replace ObjectSpace._id2ref(#{res.__id__})")
176
+ else
177
+ res
178
+ end
179
+ end
180
+ end
181
+ end
182
+ class SetTheme
183
+ def initialize obj, *lexprs
184
+ @lexprs = lexprs
185
+ @obj = obj
186
+ end
187
+ def call *cargs
188
+ ret = @lexprs.map{|e| e.__call @obj, *cargs}
189
+ if ret.size == 1
190
+ ret[0]
191
+ else
192
+ ret
193
+ end
194
+ end
195
+ end
196
+
197
+ end
198
+
199
+
200
+ def __ *args
201
+ case args.size
202
+ when 0
203
+ return unless bnd = caller_binding
204
+ TZLambda::NullElem.new bnd
205
+ when 1
206
+ args[0].__l_to_lambda__
207
+ else
208
+ args = args.map do |a|
209
+ a.__l_to_lambda__
210
+ end
211
+ args.__l_to_lambda__
212
+ end
213
+ end
214
+
215
+
216
+
217
+ class Object
218
+ def __l_to_lambda__
219
+ TZLambda::FixedElem.new self
220
+ end
221
+ def _I *lexprs
222
+ return unless bnd = caller_binding
223
+ obj = bnd.eval("self") == self ? nil : self
224
+ if lexprs.size == 0
225
+ TZLambda::MethodCall.new bnd, obj, ""
226
+ else
227
+ TZLambda::SetTheme.new obj, *lexprs
228
+ end
229
+ end
230
+ [[:a, ?@], [:d, ?$]].each do |s, m|
231
+ class_eval %{
232
+ def _I#{s.to_s}
233
+ return unless bnd = caller_binding
234
+ obj = bnd.eval("self") == self ? nil : self
235
+ TZLambda::MethodCall.new bnd, obj, #{m.inspect}.chr
236
+ end
237
+ }
238
+ end
239
+ [["!", ", :replace"], ["", ""]].each do |s, f|
240
+ class_eval %{
241
+ def _L#{s}
242
+ return unless bnd = caller_binding
243
+ obj = bnd.eval("self") == self ? nil : self
244
+ TZLambda::CallBlock.new bnd, obj#{f}
245
+ end
246
+ }
247
+ end
248
+ end
249
+
250
+
251
+ 0.upto 20 do |i|
252
+ eval %{
253
+ def _#{i}
254
+ return TZLambda::PlaceHolder#{i}
255
+ end
256
+ }
257
+ end
258
+
259
+
260
+ class String
261
+ alias :__plus__ :+
262
+ def + (other)
263
+ return __(self) + other if other.is_a?(TZLambda::Base)
264
+ __plus__ other
265
+ end
266
+ end
267
+
268
+
269
+ if $0 == __FILE__
270
+ def fold &m
271
+ [100, 200, 300].inject{|a, e| m.call(a, e) }
272
+ end
273
+ def test a, b
274
+ [a + 1, b + 1]
275
+ end
276
+ require 'Yk/path_aux'
277
+ require 'Yk/debug2'
278
+ p 3
279
+ p
280
+ a = "#{ENV['HOME']}/.console_files"
281
+ p
282
+ b = __1 * __1 * __2
283
+ p
284
+ p __I.b 2, 3
285
+ p "Q"._?._e?.inspect
286
+ p "asdf"._e?
287
+ clause __.a + __0 + __1._?._e?.__it.to_s do |c|
288
+ p "test"._I(c, c).call "asdf"
289
+ end
290
+ e = __FILE__
291
+ clause _0.expand_path.write_la _1.ln do |c|
292
+ p c
293
+ "~/.command_arg_files.test"._I.c e
294
+ if e._d? || e._!.dirname._d?
295
+ "~/.command_arg_dirs.test"._I.c e
296
+ end
297
+ end
298
+ a = [1, 2, 3]
299
+ p a
300
+ a._L!.map(100 + _1)
301
+ p a
302
+ p _L.fold(:+)
303
+ a = __.test __1, __2
304
+ p _I.a 5, 6
305
+ p _I(a, a).call 7, 8
306
+ p [?a, ?b, ?c]._L!.map("Z" + _1)
307
+ end
308
+
309
+
@@ -0,0 +1,423 @@
1
+
2
+ class ConfLine < String
3
+ class Error < Exception
4
+ end
5
+ @@definitions = Hash.new { |h, k| h[k] = Hash.new }
6
+ def resolvIt (arg, parent)
7
+ ret = []
8
+ mode = true
9
+ wd = ""
10
+ addByte = Proc.new do |c|
11
+ wd += c.chr
12
+ end
13
+ checkWord = Proc.new do
14
+ if mode
15
+ while wd =~ (/\$(\{|)([A-Za-z_]\w*)(\1)/)
16
+ pre = $`
17
+ if pre && pre != ""
18
+ ret += pre.split_chunk(/[\,\s]+/)
19
+ end
20
+ post = $'
21
+ val = $2
22
+ if tmp = resolvDef(val)
23
+ if tmp =~ /\%\d+/
24
+ args = getArguments(post)
25
+ if args
26
+ tmp = tmp.setArgs(args)
27
+ end
28
+ end
29
+ end
30
+ ret.push tmp
31
+ wd = post
32
+ end
33
+ end
34
+ ret += wd.split_chunk(/[\,\s]+/)
35
+ wd = ""
36
+ end
37
+ catch :brkr do
38
+ curPos = 0
39
+ g = Object.new
40
+ g.__defun__ :+@ do
41
+ arg[curPos]
42
+ end
43
+ g.__defun__ :inc do
44
+ curPos += 1
45
+ if curPos == arg.size
46
+ throw :brkr
47
+ end
48
+ end
49
+ g.__defun__ :next do
50
+ arg[curPos + 1]
51
+ end
52
+ def g.loop (&bl)
53
+ while true
54
+ yield
55
+ inc
56
+ end
57
+ end
58
+ g.loop do
59
+ case +g
60
+ when ?\"
61
+ mode = true
62
+ g.inc
63
+ begin
64
+ if +g == ?\\
65
+ g.inc
66
+ case +g
67
+ when ?\\
68
+ addByte.call ?\\
69
+ when ?n
70
+ addByte.call ?\n
71
+ when ?t
72
+ addByte.call ?\t
73
+ else
74
+ addByte.call +g
75
+ end
76
+ next
77
+ end
78
+ addByte.call +g
79
+ g.inc
80
+ end while +g != ?\"
81
+ checkWord.call
82
+ when ?\'
83
+ mode = false
84
+ g.inc
85
+ begin
86
+ if +g == ?\\
87
+ g.inc
88
+ case +g
89
+ when ?'
90
+ addByte.call "'"
91
+ else
92
+ addByte.call ?\\
93
+ addByte.call +g
94
+ end
95
+ next
96
+ end
97
+ addByte.call +g
98
+ g.inc
99
+ end while +g != ?\'
100
+ checkWord.call
101
+ else
102
+ mode = true
103
+ begin
104
+ addByte.call +g
105
+ g.inc
106
+ end while g.next != ?\" && g.next != ?\'
107
+ checkWord.call
108
+ end
109
+ end
110
+ end
111
+ checkWord.call
112
+ ConfLine.new(ret, parent)
113
+ end
114
+ def getArguments (str, parent)
115
+ ret = []
116
+ i = 0
117
+ cnt1 = 0
118
+ cnt2 = 0
119
+ cnt3 = 0
120
+ pth = nil
121
+ if str[0] != ?(
122
+ return nil
123
+ end
124
+ while i < str.size
125
+ case pth
126
+ when nil
127
+ case str[i]
128
+ when ?(
129
+ cnt1 += 1
130
+ if cnt1 == 1
131
+ start = i + 1
132
+ end
133
+ when ?)
134
+ cnt1 -= 1
135
+ if cnt1 == 0
136
+ ret.push resolvIt(str[start .. i - 1].strip, parent)
137
+ start = nil
138
+ str[0 .. i] = ""
139
+ break
140
+ end
141
+ when ?{
142
+ cnt2 += 1
143
+ when ?}
144
+ cnt2 -= 1
145
+ when ?[
146
+ cnt3 += 1
147
+ when ?]
148
+ cnt3 -= 1
149
+ when ?"
150
+ pth = ?\"
151
+ when ?'
152
+ pth = ?\'
153
+ when ?,
154
+ if cnt1 == 1 && cnt2 == 0 && cnt3 == 0
155
+ ret.push resolvIt(str[start .. i - 1].strip, parent)
156
+ start = i + 1
157
+ end
158
+ start = i + 1
159
+ end
160
+ when "\\\'"
161
+ pth = ?\'
162
+ when "\\\""
163
+ pth = ?\"
164
+ when ?\'
165
+ case str[i]
166
+ when ?\'
167
+ pth = nil
168
+ when ?\\
169
+ pth = "\\\'"
170
+ end
171
+ when ?\"
172
+ case str[i]
173
+ when ?\"
174
+ pth = nil
175
+ when ?\\
176
+ pth = "\\\""
177
+ end
178
+ end
179
+ i += 1
180
+ end
181
+ return ret
182
+ end
183
+ def getChunk (i)
184
+ self[@chunks[i]]
185
+ end
186
+ def chunks (arg = nil)
187
+ if arg.is_a? Range
188
+ res = ""
189
+ (tmp = @chunks[arg]).each_index do |i|
190
+ e = tmp[i]
191
+ if i != 0 && res.respond_to?(:prefix)
192
+ res += e.prefix
193
+ end
194
+ res += e
195
+ if i != tmp.size - 1 && res.respond_to?(:postfix)
196
+ res += e.postfix
197
+ end
198
+ end
199
+ res
200
+ elsif arg != nil
201
+ @chunks[arg]
202
+ else
203
+ @chunks
204
+ end
205
+ end
206
+ def resolvDef (arg)
207
+ @definitionFiles.each do |f|
208
+ if @@definitions.key?(f)
209
+ if tmp = @@definitions[f][arg]
210
+ return tmp
211
+ end
212
+ end
213
+ end
214
+ nil
215
+ end
216
+ def registerDefFile (defFile)
217
+ if defFile && defFile.readable_file? && !@@definitions.key?(defFile)
218
+ defFile.read_each_line do |ln2|
219
+ ConfLine.new(ln2, defFile, nil)
220
+ end
221
+ if @@definitions.key? defFile
222
+ @definitionFiles.push defFile
223
+ end
224
+ end
225
+ end
226
+ attr :definitionFiles
227
+ attr :scope
228
+ def setArgs (args, parent)
229
+ arr = []
230
+ chunks.each do |e|
231
+ if e =~ /\%\d+/
232
+ # if e.respond_to? :chunks
233
+ # arr.push e.setArgs(args, parent)
234
+ # else
235
+ while e =~ /\%(\d+)/
236
+ pre, hit, id, post = $`, $&, $1.to_i - 1, $'
237
+ if pre && pre != ""
238
+ arr += pre.split_chunk(/[\,\s]+/)
239
+ end
240
+ if tmp = args[id]
241
+ arr.push tmp
242
+ else
243
+ arr.push hit
244
+ end
245
+ e = post
246
+ end
247
+ if e && e != ""
248
+ arr.push e
249
+ end
250
+ # end
251
+ else
252
+ arr.push e
253
+ end
254
+ end
255
+ ConfLine.new(arr.join.split_chunk(/[\,\s]+/), parent)
256
+ end
257
+ def initialize (ln, sc, incFiles = nil, noDef = false)
258
+ super()
259
+ if !ln.is_a? Array
260
+ @scope = sc
261
+ @definitionFiles = [@scope]
262
+ if incFiles.is_a? Array
263
+ incFiles.each do |e|
264
+ registerDefFile e
265
+ end
266
+ else
267
+ registerDefFile e
268
+ end
269
+ @definitionFiles.push nil
270
+ tmp = ""
271
+ ln.each_line do |l|
272
+ l.sub!(/\#.*$/, "")
273
+ l.strip!
274
+ tmp += l.ln!
275
+ end
276
+ if !noDef && ln =~ /([A-Za-z_]\w*)\s*\=\s*(.*)/m
277
+ m1, m2 = $1, $2.strip
278
+ @@definitions[@scope][m1] = ConfLine.new(m2, @scope, incFiles, true)
279
+ replace("")
280
+ else
281
+ res = ln
282
+ arr = []
283
+ while res =~ (/\$(\{|)([A-Za-z_]\w*)(\1)/)
284
+ pre = $`
285
+ post = $'
286
+ val = $2
287
+ if pre && pre != ""
288
+ arr.push *pre.split_chunk(/[\,\s]+/)
289
+ end
290
+ if tmp = resolvDef(val)
291
+ if tmp =~ /\%\d+/
292
+ args = getArguments(post, self)
293
+ tmp = tmp.setArgs(args, self)
294
+ end
295
+ arr.push tmp
296
+ else
297
+ arr.push "$" + val
298
+ end
299
+ res = post
300
+ end
301
+ arr.push *res.split_chunk(/[\,\s]+/)
302
+ @chunks = arr
303
+ replace(arr.join)
304
+ end
305
+ if block_given? && self != ""
306
+ yield self
307
+ end
308
+ else
309
+ arr, parent = ln, sc
310
+ @chunks = arr
311
+ @scope = parent.scope
312
+ @definitionFiles = parent.definitionFiles
313
+ replace(arr.join)
314
+ end
315
+ end
316
+ end
317
+
318
+
319
+ module ConfFile
320
+ module_function
321
+ def getSection_l (f, sec, scope = nil, preLoad = [], preParser = nil, &bl)
322
+ getSection_(true, f, sec, scope, preLoad, preParser, &bl)
323
+ end
324
+ def getSection (f, sec, scope = nil, preLoad = [], preParser = nil, &bl)
325
+ getSection_(nil, f, sec, scope, preLoad, preParser, &bl)
326
+ end
327
+ def getSection_ (lck, f, sec, scope = nil, preLoad = [], preParser = nil)
328
+ # if !scope
329
+ # scope = f
330
+ # end
331
+ @cList ||= Hash.new
332
+ @cList[f] ||= splitSection_(lck, f)
333
+ res = nil
334
+ notFound = Proc.new do
335
+ if ((tmp = @cList[f].keys).size == 1 && tmp[0] == nil)
336
+ @cList[f][nil]
337
+ elsif tmp.size == 0
338
+ ""
339
+ else
340
+ nil
341
+ end
342
+ end
343
+ if sec.is_a? Regexp
344
+ ret = nil
345
+ @cList[f].keys.select{ |e| e =~ sec}.each do |k|
346
+ if !ret
347
+ ret = ""
348
+ end
349
+ ret += @cList[f][k]
350
+ end
351
+ if !ret
352
+ notFound.call
353
+ else
354
+ res = ret
355
+ end
356
+ else
357
+ if !@cList[f].key?(sec)
358
+ notFound.call
359
+ else
360
+ res = @cList[f][sec]
361
+ end
362
+ end
363
+ i = 0
364
+ if res
365
+ res = res.lines
366
+ pobj = preParser.new if preParser
367
+ while i < res.size
368
+ ln = res[i]
369
+ while ln[-2] == ?\\
370
+ ln = ln.chomp.chop.ln
371
+ if i == res.size - 1
372
+ break
373
+ end
374
+ i += 1
375
+ ln += res[i]
376
+ end
377
+ if pobj
378
+ pobj.call ln do |ln2|
379
+ cl = ConfLine.new(ln2, scope, preLoad)
380
+ if ln2.respond_to? :extra_properties
381
+ ln2.extra_properties.each do |l|
382
+ cl.__defun__ l, ln2.method(l).call
383
+ end
384
+ end
385
+ yield cl
386
+ end
387
+ else
388
+ yield ConfLine.new(ln, scope, preLoad)
389
+ end
390
+ i += 1
391
+ end
392
+ end
393
+ end
394
+ def splitSection_ (lck, f)
395
+ secs = Hash.new { |h, k| h[k] = "".clone }
396
+ sec = nil
397
+ if lck
398
+ f.read_each_line_l do |ln|
399
+ if ln =~ /^\s*\[([^\]\#]+)\]/
400
+ sec = $1.strip
401
+ ln = $'
402
+ end
403
+ secs[sec] += ln
404
+ end
405
+ else
406
+ f.read_each_line do |ln|
407
+ if ln =~ /^\s*\[([^\]\#]+)\]/
408
+ sec = $1.strip
409
+ ln = $'
410
+ end
411
+ secs[sec] += ln
412
+ end
413
+ end
414
+ secs
415
+ end
416
+ def splitSection (f)
417
+ splitSection_(nil, f)
418
+ end
419
+ def splitSection_l (f)
420
+ splitSection_(true, f)
421
+ end
422
+ end
423
+