mathgl 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,192 @@
1
+ # This document is converted from other_en.texi.
2
+ class MglColor
3
+
4
+ # Sets color from values of Red, Green, Blue and Alpha channels. These values should be in interval [0,1].
5
+ # @overload set(r,g,b,a=1)
6
+ # @param [Float] r
7
+ # @param [Float] g
8
+ # @param [Float] b
9
+ # @param [Float] a default=1
10
+ # @return [nil]
11
+ def set
12
+ end
13
+
14
+
15
+ # Sets color as ``lighted'' version of color c.
16
+ # @overload set(c,bright=1)
17
+ # @param [MglColor] c
18
+ # @param [Float] bright default=1
19
+ # @return [nil]
20
+ def set
21
+ end
22
+
23
+
24
+ # Sets color from symbolic id.
25
+ # @overload set(p,bright=1)
26
+ # @param [String] p
27
+ # @param [Float] bright default=1
28
+ # @return [nil]
29
+ def set
30
+ end
31
+
32
+
33
+ # Checks correctness of the color.
34
+ # @overload valid()
35
+ # @return [bool]
36
+ def valid
37
+ end
38
+
39
+
40
+ # Gets maximal of spectral component.
41
+ # @overload norm()
42
+ # @return [Float]
43
+ def norm
44
+ end
45
+
46
+
47
+ # Adds colors by its RGB values.
48
+ # @overload +(b)
49
+ # @param [MglColor] b
50
+ # @return [MglColor]
51
+ def +
52
+ end
53
+
54
+
55
+ # Subtracts colors by its RGB values.
56
+ # @overload -(b)
57
+ # @param [MglColor] b
58
+ # @return [MglColor]
59
+ def -
60
+ end
61
+
62
+
63
+ # Multiplies color by number.
64
+ # @overload *(b)
65
+ # @param [Float] b
66
+ # @return [MglColor]
67
+ def *
68
+ end
69
+
70
+
71
+ # Divide color by number.
72
+ # @overload /(b)
73
+ # @param [Float] b
74
+ # @return [MglColor]
75
+ def /
76
+ end
77
+
78
+
79
+ end # MglColor
80
+
81
+ class MglPoint
82
+
83
+ # Returns true if point contain NAN values.
84
+ # @overload is_nan()
85
+ # @return [bool]
86
+ def is_nan
87
+ end
88
+
89
+
90
+ # Returns the norm } of vector.
91
+ # @overload norm()
92
+ # @return [Float]
93
+ def norm
94
+ end
95
+
96
+
97
+ # Normalizes vector to be unit vector.
98
+ # @overload normalize()
99
+ # @return [nil]
100
+ def normalize
101
+ end
102
+
103
+
104
+ # Returns point component: x for i=0, y for i=1, z for i=2, c for i=3.
105
+ # @overload val(i)
106
+ # @param [Integer] i
107
+ # @return [Float]
108
+ def val
109
+ end
110
+
111
+
112
+ # Point of summation (summation of vectors).
113
+ # @overload +(b)
114
+ # @param [MglPoint] b
115
+ # @return [MglPoint]
116
+ def +
117
+ end
118
+
119
+
120
+ # Point of difference (difference of vectors).
121
+ # @overload -(b)
122
+ # @param [MglPoint] b
123
+ # @return [MglPoint]
124
+ def -
125
+ end
126
+
127
+
128
+ # Multiplies (scale) points by number.
129
+ # @overload *(b)
130
+ # @param [Float] b
131
+ # @return [MglPoint]
132
+ def *
133
+ end
134
+
135
+
136
+ # Multiplies (scale) points by number 1/b.
137
+ # @overload /(b)
138
+ # @param [Float] b
139
+ # @return [MglPoint]
140
+ def /
141
+ end
142
+
143
+
144
+ # Scalar product of vectors.
145
+ # @overload *(b)
146
+ # @param [MglPoint] b
147
+ # @return [MglPoint]
148
+ def *
149
+ end
150
+
151
+
152
+ # Return vector of element-by-element product.
153
+ # @overload /(b)
154
+ # @param [MglPoint] b
155
+ # @return [MglPoint]
156
+ def /
157
+ end
158
+
159
+
160
+ # Cross-product of vectors.
161
+ # @overload ^(b)
162
+ # @param [MglPoint] b
163
+ # @return [MglPoint]
164
+ def ^
165
+ end
166
+
167
+
168
+ # The part of a which is perpendicular to vector b.
169
+ # @overload &(b)
170
+ # @param [MglPoint] b
171
+ # @return [MglPoint]
172
+ def &
173
+ end
174
+
175
+
176
+ # The part of a which is parallel to vector b.
177
+ # @overload |(b)
178
+ # @param [MglPoint] b
179
+ # @return [MglPoint]
180
+ def |
181
+ end
182
+
183
+
184
+ # Return the norm sqrt(|a|^2) of vector a.
185
+ # @overload mgl_norm()
186
+ # @return [MglPoint]
187
+ def mgl_norm
188
+ end
189
+
190
+
191
+ end # MglPoint
192
+
@@ -0,0 +1,151 @@
1
+ # This document is converted from parse_en.texi.
2
+ class MglParse
3
+
4
+ # Main function in the class. Function parse and execute line-by-line MGL script in array text. Lines are separated by newline symbol as usual.
5
+ # @overload execute(gr,text)
6
+ # @param [MglGraph] gr
7
+ # @param [String] text
8
+ # @return [nil]
9
+ def execute
10
+ end
11
+
12
+
13
+ # The same as previous but read script from the file fp. If print=true then all warnings and information will be printed in stdout.
14
+ # @overload execute(gr,fp,print=false)
15
+ # @param [MglGraph] gr
16
+ # @param [FILE] fp
17
+ # @param [bool] print default=false
18
+ # @return [nil]
19
+ def execute
20
+ end
21
+
22
+
23
+ # Function parses the string str and executes it by using gr as a graphics plotter. Returns the value depending on an error presence in the string str: 0 -- no error, 1 -- wrong command argument(s), 2 -- unknown command, 3 -- string is too long. Optional argument pos allows to save the string position in the document (or file) for using for|next command.
24
+ # @overload parse(gr,str,pos=0)
25
+ # @param [MglGraph] gr
26
+ # @param [String] str
27
+ # @param [long] pos default=0
28
+ # @return [Integer]
29
+ def parse
30
+ end
31
+
32
+
33
+ # Function parses the string formula and return resulting data array. In difference to AddVar() or FindVar(), it is usual data array which should be deleted after usage.
34
+ # @overload calc(formula)
35
+ # @param [String] formula
36
+ # @return [MglData]
37
+ def calc
38
+ end
39
+
40
+
41
+ # Function set the value of n-th parameter as string str (n=0, 1 ... 'z'-'a'+10). String str shouldn't contain symbol.
42
+ # @overload add_param(n,str)
43
+ # @param [Integer] n
44
+ # @param [String] str
45
+ # @return [nil]
46
+ def add_param
47
+ end
48
+
49
+
50
+ # Function returns the pointer to variable with name name or zero if variable is absent. Use this function to put external data array to the script or get the data from the script. You must obtained data arrays!
51
+ # @overload find_var(name)
52
+ # @param [String] name
53
+ # @return [MglVar]
54
+ def find_var
55
+ end
56
+
57
+
58
+ # Function returns the pointer to variable with name name. If variable is absent then new variable is created with name name. Use this function to put external data array to the script or get the data from the script. You must obtained data arrays!
59
+ # @overload add_var(name)
60
+ # @param [String] name
61
+ # @return [MglVar]
62
+ def add_var
63
+ end
64
+
65
+
66
+ # Function delete the variable specified by its name or by its pointer.
67
+ # @overload delete_var(name)
68
+ # @param [String] name
69
+ # @return [nil]
70
+ def delete_var
71
+ end
72
+
73
+
74
+ # Function delete all variables in this parser.
75
+ # @overload delete_all()
76
+ # @return [nil]
77
+ def delete_all
78
+ end
79
+
80
+
81
+ # Restore Once flag.
82
+ # @overload restore_once()
83
+ # @return [nil]
84
+ def restore_once
85
+ end
86
+
87
+
88
+ # Allow to parse 'setsize' command or not.
89
+ # @overload allow_set_size(a)
90
+ # @param [bool] a
91
+ # @return [nil]
92
+ def allow_set_size
93
+ end
94
+
95
+
96
+ # Allow reading/saving files or not.
97
+ # @overload allow_file_io(a)
98
+ # @param [bool] a
99
+ # @return [nil]
100
+ def allow_file_io
101
+ end
102
+
103
+
104
+ # Sends stop signal which terminate execution at next command.
105
+ # @overload stop()
106
+ # @return [nil]
107
+ def stop
108
+ end
109
+
110
+
111
+ # Return the number of registered MGL commands.
112
+ # @overload get_cmd_num()
113
+ # @return [long]
114
+ def get_cmd_num
115
+ end
116
+
117
+
118
+ # Return the name of command with given id.
119
+ # @overload get_cmd_name(id)
120
+ # @param [long] id
121
+ # @return [String]
122
+ def get_cmd_name
123
+ end
124
+
125
+
126
+ # Return the type of MGL command name. Type of commands are: 0 -- not the command, 1 - data plot, 2 - other plot, 3 - setup, 4 - data handle, 5 - data create, 6 - subplot, 7 - program, 8 - 1d plot, 9 - 2d plot, 10 - 3d plot, 11 - dd plot, 12 - vector plot, 13 - axis, 14 - primitives, 15 - axis setup, 16 - text/legend, 17 - data transform.
127
+ # @overload cmd_type(name)
128
+ # @param [String] name
129
+ # @return [Integer]
130
+ def cmd_type
131
+ end
132
+
133
+
134
+ # Return the format of arguments for MGL command name.
135
+ # @overload cmd_format(name)
136
+ # @param [String] name
137
+ # @return [String]
138
+ def cmd_format
139
+ end
140
+
141
+
142
+ # Return the description of MGL command name.
143
+ # @overload cmd_desc(name)
144
+ # @param [String] name
145
+ # @return [String]
146
+ def cmd_desc
147
+ end
148
+
149
+
150
+ end # MglParse
151
+
@@ -1,3 +1,3 @@
1
1
  module Mathgl
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/misc/conv_texi.rb ADDED
@@ -0,0 +1,426 @@
1
+ class MethodType
2
+
3
+ class Args
4
+ attr_accessor :type, :name, :default
5
+
6
+ def initialize(type,name,default=nil)
7
+ @type = Args.conv_type(type)
8
+ @name = name.downcase
9
+ @default = default
10
+ end
11
+
12
+ def default_s
13
+ if default and !default.empty?
14
+ "default=#{default}"
15
+ else
16
+ ""
17
+ end
18
+ end
19
+
20
+ def var
21
+ if default and !default.empty?
22
+ "#{name}=#{default}"
23
+ else
24
+ "#{name}"
25
+ end
26
+ end
27
+
28
+ def self.conv_type(s)
29
+ s = s.gsub(/\b(const|inline)\b/,"")
30
+ s = s.gsub(/(\*|&)/,"")
31
+ s.strip!
32
+ case s
33
+ when /mglData.\b/
34
+ "MglData"
35
+ when /mgl(\w+)\b/
36
+ "Mgl"+$1
37
+ when "int"
38
+ "Integer"
39
+ when "void"
40
+ "nil"
41
+ when "double","mreal"
42
+ "Float"
43
+ when "char"
44
+ "String"
45
+ else
46
+ s
47
+ end
48
+ end
49
+
50
+ def conv_type_bak(s)
51
+ s = conv_type2(s)
52
+ case s
53
+ when "MglPoint"
54
+ "MglPoint,Array"
55
+ else
56
+ s
57
+ end
58
+ end
59
+ end
60
+
61
+ def initialize(clss,line)
62
+ @args = []
63
+ @docs = []
64
+ @clss = fix_class_name(clss) if clss
65
+ parse(line)
66
+ if @clss.nil?
67
+ a = @args.shift
68
+ @clss = @return_type = a.type
69
+ end
70
+ end
71
+
72
+ attr_accessor :name, :return_type, :doc, :clss
73
+
74
+ def add_doc(s)
75
+ @docs << s
76
+ end
77
+
78
+ def args(n)
79
+ a = @args[n]
80
+ if a.nil?
81
+ @args[n] = a = Args.new
82
+ end
83
+ a
84
+ end
85
+
86
+ def vars
87
+ @args.map{|a| a.var}
88
+ end
89
+
90
+ def mkdoc
91
+ d = []
92
+ @docs.each do |s|
93
+ d << s
94
+ end
95
+ d << "# @overload #{name}(#{vars.join(',')})"
96
+ @args.each do |a|
97
+ d << "# @param [#{a.type}] #{a.name} #{a.default_s}"
98
+ end
99
+ d << "# @return [#{return_type}]"
100
+ d.join("\n")+"\n"
101
+ end
102
+
103
+ def fix_return_type(s)
104
+ Args.conv_type(s.gsub(/\{([^{}]+)\}/,'\1'))
105
+ end
106
+
107
+
108
+ def parse(line)
109
+ #p line
110
+ #if line.nil?
111
+ if /(.*)\((.*)\)/ =~ line.strip
112
+ m,parms = $1,$2
113
+ if /(\S.*[\s*&])(\w+\S+)/ =~ m
114
+ ret, meth = $1,$2
115
+ else
116
+ ret = m
117
+ meth = "unknown_method"
118
+ end
119
+ if ret.strip == "{}"
120
+ @name = "initialize"
121
+ @return_type = fix_return_type(@clss)
122
+ else
123
+ @name = fix_method_name(meth)
124
+ @return_type = fix_return_type(ret)
125
+ end
126
+ decomp_parms(parms)
127
+ else
128
+ "# parse_param_error: "+line
129
+ end
130
+ end
131
+
132
+ def decomp_parms(parms)
133
+ parms.split(/,/).each_with_index do |x,i|
134
+ if /(\S.*[\s*&])(\w+)(=([^=]+))?/ =~ x
135
+ @args[i] = Args.new($1,$2,$4)
136
+ else
137
+ @args[i] = Args.new("unknown","error")
138
+ end
139
+ end
140
+ end
141
+
142
+ def fix_method_name(x)
143
+ x = x.sub(/^operator(\S+)/,'\1')
144
+ x = x.gsub(/(?<=[a-z])(?=[A-Z])/,"_").downcase
145
+ x.gsub!(/(?<=[a-z])(?=[0-9]+[a-z])/i,"_")
146
+ x
147
+ end
148
+
149
+ def fix_class_name(x)
150
+ x = $1 if /(\w+)/=~x
151
+ x[0] = x[0].upcase
152
+ x
153
+ end
154
+
155
+ def valid
156
+ @name !~ /=$/ and
157
+ @name != "!" and
158
+ @name != "unknown_method" and
159
+ @clss =~ /^mgl/i and
160
+ @return_type !~ /\b(HMGL|HCDT|HMPR)\b/ and
161
+ @args.all? do |a|
162
+ /\b(HMGL|HCDT|HMPR)\b/ !~ a.type
163
+ end
164
+ end
165
+
166
+ def ruby_def
167
+ "def #{name}\nend\n"
168
+ end
169
+ end
170
+
171
+ class TexiParse
172
+
173
+ def initialize
174
+ end
175
+
176
+ def parse(src_str)
177
+ @re_ignore_param = /\b(HMGL|HCDT|HMPR)\b/
178
+ @tags = {}
179
+ @defs = []
180
+ @docs = {}
181
+ @block_nest = []
182
+ @s = src_str
183
+ @a = @s.scan(/^.*$/).map{|x| x}
184
+ tags = {}
185
+ @a.each{|x| tags[$1]=true if /^@end (\w+)/=~x}
186
+
187
+ tags = tags.keys
188
+ @re_tag = /^@(#{tags.join('|')})\b\s*(.*)/
189
+
190
+ block_loop()
191
+ end
192
+
193
+ def empty?
194
+ @docs.empty?
195
+ end
196
+
197
+ def write(io)
198
+ @docs.each do |clss,docs|
199
+ if clss
200
+ io.print "class #{clss}\n\n"
201
+ docs.each do |x|
202
+ io.print x+"\n\n"
203
+ end
204
+ io.print "end # #{clss}\n\n"
205
+ end
206
+ end
207
+ end
208
+
209
+ def c(a)
210
+ ""
211
+ end
212
+
213
+ def block_loop(tag="_top_",arg=nil)
214
+ b = []
215
+ @block_nest.push([])
216
+ while !@a.empty?
217
+ a0 = @a.shift
218
+ #puts a0
219
+ case a0
220
+ when @re_tag
221
+ tag2,arg2 = $1,$2
222
+ if respond_to?(tag2)
223
+ send(tag2,arg2)
224
+ else
225
+ block_loop(tag2,arg2)
226
+ end
227
+ when /^@end #{tag}\b/
228
+ break
229
+ else
230
+ parse_line(a0)
231
+ b.push(a0)
232
+ end
233
+ end
234
+ @block_nest.pop
235
+ end
236
+
237
+ def default_tag(tag,arg)
238
+ tag = "section" if tag == "subsection"
239
+ @tags[tag] = arg
240
+ "#{tag}:#{arg}"
241
+ nil
242
+ end
243
+
244
+ def parse_tag(tag,arg)
245
+ if respond_to?(tag)
246
+ send(tag,arg)
247
+ else
248
+ default_tag(tag,arg)
249
+ end
250
+ end
251
+
252
+ def parse_inline(a)
253
+ a = a.gsub(/@(\w+)\{([^}]*)\}/){|x| parse_tag($1,$2)}
254
+ a.gsub!(/@\{/,"(")
255
+ a.gsub!(/@\}/,")")
256
+ a
257
+ end
258
+
259
+ def parse_line(a)
260
+ case a
261
+ when /^@(\w+)(.*)/
262
+ tag,arg = $1,$2
263
+ line = parse_tag(tag,parse_inline(arg))
264
+ else
265
+ line = parse_inline(a)
266
+ end
267
+ if line
268
+ @block_nest.last.push(line)
269
+ end
270
+ end
271
+
272
+ def ifclear(arg)
273
+ if !@defs.include?(arg)
274
+ block_loop("ifclear",arg)
275
+ end
276
+ end
277
+
278
+ def ifset(arg)
279
+ if @defs.include?(arg)
280
+ block_loop("ifclear",arg)
281
+ end
282
+ end
283
+
284
+ def deftypemethod(arg)
285
+ deftype(:deftypemethod,arg)
286
+ end
287
+
288
+ def deftypefn(arg)
289
+ deftype(:deftypefn,arg)
290
+ end
291
+
292
+ def deftype(tag,arg)
293
+ #p arg
294
+ @method = []
295
+ deftypefnx(parse_inline(arg))
296
+ lines = block_loop(tag,arg)
297
+ s = ""
298
+ section = @tags['section'].strip
299
+ if /^mgl.*class$/ !~ section
300
+ s << "# #{section}.\n"
301
+ end
302
+ lines.each do |x|
303
+ s << "# #{x}\n"
304
+ end
305
+ mm = nil
306
+ @method.each do |m|
307
+ if m and m.valid
308
+ s << m.mkdoc
309
+ mm = m
310
+ end
311
+ end
312
+ if mm and mm.valid
313
+ s << mm.ruby_def
314
+ #puts s
315
+ clss = mm.clss
316
+ b = @docs[clss]
317
+ @docs[clss] = b = [] unless b
318
+ b.push s
319
+ elsif mm
320
+ puts "undoc: "+mm.name
321
+ end
322
+ nil
323
+ end
324
+
325
+ def deftypefnx(a)
326
+ return if /wchar_t/ =~ a
327
+ a = parse_inline(a)
328
+ a = a.strip
329
+ #puts "- deftypefnx #{a}"
330
+ if /\{(\w+) on ([^}]+)\}(.*)/ =~ a
331
+ type,clss,args = $1,$2,$3
332
+ case type
333
+ when "Method"
334
+ @method << MethodType.new(clss,args)
335
+ #a = [type,clss,*parse_param(args)]
336
+ #a[4].unshift "# @overload #{a[2]}(#{a[3].join(',')})"
337
+ #if a[4].all?{|x| @re_ignore_param !~ x}
338
+ # @method << a
339
+ #end
340
+ when "Constructor"
341
+ @method << MethodType.new(clss,args)
342
+ #a = [type,clss,*parse_param(args)]
343
+ #a[4].unshift "# @overload initialize(#{a[3].join(',')})"
344
+ #if a[4].all?{|x| @re_ignore_param !~ x}
345
+ # @method << a
346
+ #end
347
+ when "Destructor"
348
+ when "Slot"
349
+ when "Signal"
350
+ else
351
+ raise "unknown method type : #{type}"
352
+ end
353
+ elsif /\{Library Function\}(.*)/ =~ a
354
+ clss,args = nil,$1
355
+ @method << MethodType.new(clss,args)
356
+ #a = library_function($1)
357
+ #if a and a[4].all?{|x| @re_ignore_param !~ x}
358
+ # @method << a
359
+ #end
360
+ elsif /^(mgl\w+) (.*)/ =~ a
361
+ clss,args = $1,$2
362
+ #p [clss,args]
363
+ m = MethodType.new(clss,args)
364
+ #p m
365
+ #p m.mkdoc
366
+ @method << m
367
+ #a = ["Method",clss,*library_method(args)]
368
+ #if a and a[4].all?{|x| @re_ignore_param !~ x}
369
+ # @method << a
370
+ #end
371
+ elsif /\{MGL command\}/ =~ a
372
+ elsif /\{C function\}/ =~ a
373
+ elsif /\{Global function\}/ =~ a
374
+ elsif /\{MGL suffix\}/ =~ a
375
+ elsif /QMathGL/ =~ a
376
+ elsif /Fl_MathGL/ =~ a
377
+ else
378
+ puts "undoc: "+a
379
+ end
380
+ nil
381
+ end
382
+
383
+
384
+ def code(s)
385
+ s
386
+ end
387
+
388
+ def var(s)
389
+ s
390
+ end
391
+
392
+ def emph(x)
393
+ "*"+x+"*"
394
+ end
395
+
396
+ def code(x)
397
+ #"+"+x+"+"
398
+ x
399
+ end
400
+
401
+ def ref(x)
402
+ #"{"+x+"}"
403
+ x
404
+ end
405
+ end
406
+
407
+ srcdir = ENV["HOME"]+"/2013/src/mathgl-2.1.3.1/texinfo/"
408
+ dstdir = ENV["HOME"]+"/2013/git/ruby-mathgl/lib/mathgl/"
409
+
410
+ Dir.glob(srcdir+"*_en.texi") do |rf|
411
+ #[ENV["HOME"]+"/2013/src/mathgl-2.1.3.1/texinfo/core_en.texi"].each do |rf|
412
+ src = nil
413
+ open(rf,"r"){|io| src = io.read}
414
+ if /deftypefn/=~src
415
+ wf = dstdir+"libdoc_"+File.basename(rf,".texi")+".rb"
416
+ puts "#{rf} -> #{wf}"
417
+ tp = TexiParse.new
418
+ tp.parse(src)
419
+ if !tp.empty?
420
+ open(wf,"w"){|io|
421
+ io.puts "# This document is converted from #{File.basename(rf)}."
422
+ tp.write(io)
423
+ }
424
+ end
425
+ end
426
+ end