json, an output representation, first pass
[software/sisu] / lib / sisu / hub_options.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** hub, command line options parsing
8
9 *** hub
10
11 ** Author: Ralph Amissah
12 [ralph@amissah.com]
13 [ralph.amissah@gmail.com]
14
15 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
16 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Ralph Amissah,
17 All Rights Reserved.
18
19 ** License: GPL 3 or later:
20
21 SiSU, a framework for document structuring, publishing and search
22
23 Copyright (C) Ralph Amissah
24
25 This program is free software: you can redistribute it and/or modify it
26 under the terms of the GNU General Public License as published by the Free
27 Software Foundation, either version 3 of the License, or (at your option)
28 any later version.
29
30 This program is distributed in the hope that it will be useful, but WITHOUT
31 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
33 more details.
34
35 You should have received a copy of the GNU General Public License along with
36 this program. If not, see [http://www.gnu.org/licenses/].
37
38 If you have Internet connection, the latest version of the GPL should be
39 available at these locations:
40 [http://www.fsf.org/licensing/licenses/gpl.html]
41 [http://www.gnu.org/licenses/gpl.html]
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 [http://www.jus.uio.no/sisu]
50 [http://www.sisudoc.org]
51
52 ** Git
53 [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary]
54 [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/hub_options.rb;hb=HEAD]
55
56 =end
57 module SiSU_Commandline
58 begin
59 require 'pathname'
60 rescue LoadError
61 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
62 error('pathname NOT FOUND (LoadError)')
63 end
64 require_relative 'se' # se.rb
65 require_relative 'dp_make' # dp_make.rb
66 class HeaderCommon
67 def sisu_document_make_instructions(make_instruct_array=:nil)
68 @pagenew=
69 @pagebreak=
70 @pageline=
71 @toc=
72 @lv1=@lv2=@lv3=@lv4=@lv5=@lv6=
73 @num_top=
74 @i18n=
75 @man_section=
76 @emphasis_set_to=
77 @bold_match_list=
78 @italics_match_list=
79 @substitution_match_list=
80 @footer_links=
81 @home_button_links=
82 @links=
83 nil
84 make_instruct_array=make_instruct_array==:nil \
85 ? SiSU_Env::GetInit.new.sisu_document_make.makefile_read
86 : make_instruct_array
87 @makeset=false
88 if make_instruct_array
89 make_instruct_array.each do |para| #% scan document
90 if para =~/^(?:@make:|@links:)[+-]?\s/
91 case para
92 when /^@make:(.+)/m #% header processing - make
93 @env=SiSU_Env::InfoEnv.new
94 @make=SiSU_Param_Make::MdMake.new($1.strip,@opt,@env).make
95 makes=SiSU_Param_Make::MakeHead.new(@make).make_instruct
96 @makeset=true
97 @pagenew=makes[:pagenew]
98 @pagebreak=makes[:pagenew]
99 @pageline=makes[:pageline]
100 @toc=makes[:toc]
101 @lv1=makes[:lv1]
102 @lv2=makes[:lv2]
103 @lv3=makes[:lv3]
104 @lv4=makes[:lv4]
105 @lv5=makes[:lv5]
106 @lv6=makes[:lv6]
107 @num_top=makes[:num_top]
108 @i18n=makes[:i18n]
109 @man_section=makes[:man_section]
110 @emphasis_set_to=makes[:emphasis_set_to]
111 @bold_match_list=makes[:bold_match_list]
112 @italics_match_list=makes[:italics_match_list]
113 @substitution_match_list=makes[:substitution_match_list]
114 @footer_links=makes[:footer_links]
115 @home_button_links=makes[:home_button_links]
116 @home_button_image=makes[:home_button_image]
117 @cover_image=makes[:cover_image]
118 when /^@links:(.+)/m #% header processing - make
119 make_links=SiSU_Param::Parameters::MdMake.new($1.strip,@opt,@env).make_links
120 @links,@links_append=make_links.links,make_links.append?
121 end
122 end
123 end #% here endeth the common header loop
124 end
125 { makeset: @makeset,
126 pagenew: @pagenew,
127 pagebreak: @pagebreak,
128 pageline: @pageline,
129 toc: @toc,
130 lv1: @lv1,
131 lv2: @lv2,
132 lv3: @lv3,
133 lv4: @lv4,
134 lv5: @lv5,
135 lv6: @lv6,
136 num_top: @num_top,
137 i18n: @i18n,
138 man_section: @man_section,
139 emphasis_set_to: @emphasis_set_to,
140 bold_match_list: @bold_match_list,
141 italics_match_list: @italics_match_list,
142 substitution_match_list: @substitution_match_list,
143 footer_links: @footer_links,
144 home_button_links: @home_button_links,
145 home_button_image: @home_button_image,
146 cover_image: @cover_image,
147 links: @links,
148 links_append: @links_append
149 }
150 end
151 end
152 class Options
153 attr_accessor :selections,:opt_ch,:act,:dir_structure_by,:lingual,:f_pths,:files,:files_mod,:call_path,:base_path,:base_stub,:sub_location,:image_src_path,:paths,:lngs,:f_pth,:pth,:fno,:fns,:fnb,:fnc,:fng,:fncb,:lng,:lng_base,:what,:make_instructions,:make_instructions_pod,:sisu_run_path,:sisu_install_type
154 @@act=nil
155 def initialize(a,sisu_runtime)
156 @opt_ch=@f_pth=@pth=@fno=@fns=@fnb=@fnc=@fng=@fncb=@what=@lng=@lng_base=@call_path=@base_path=@base_stub=@image_src_path=@sub_location=''
157 @f_pths,@files,@files_mod,@paths,@select_arr,@act=Array.new(5){[]}
158 @select_str=nil
159 @env=SiSU_Env::InfoEnv.new
160 @lng_base=@env.language_default_set
161 @dir_structure_by=SiSU_Env::EnvCall.new.output_dir_structure.by?
162 @lingual=SiSU_Env::EnvCall.new.mono_multi_lingual?
163 @sisu_run_from=sisu_runtime[:runtime_path]
164 @sisu_install_type=sisu_runtime[:runtime_type]
165 @call_path=sisu_runtime[:call_path]
166 pth=SiSU_Utils::Path.new(call_path)
167 @base_path=pth.base_markup
168 @base_stub=pth.base_markup_stub
169 @image_src_path=pth.image_src
170 @a=sisu_glob_rules(a)
171 @a.freeze
172 @make_instructions=HeaderCommon.new.sisu_document_make_instructions
173 @make_instructions_pod=nil
174 init
175 end
176 def sisu_called_from?
177 @call_path
178 end
179 def sisu_bin_filepath?
180 @sisu_run_from
181 end
182 def sisu_install_type?
183 @sisu_install_type
184 end
185 def sisu_lib_dir?
186 File.dirname(__FILE__)
187 end
188 def sisu_data_dir?
189 env=RbConfig::CONFIG
190 if sisu_install_type? ==:full_path_to_sisu_bin_in_sisu_dir_tree
191 sisu_bin_filepath?.gsub(/\/bin\/sisu\S*/,'/data/sisu')
192 #sisu_lib_dir?.gsub(/\/lib\/sisu\/(?:current|develop)\S*/,'/data/sisu')
193 elsif sisu_install_type? ==:gem_install
194 #sisu_run_from?.gsub(/\/bin\/.+/,'/data/sisu')
195 env['datadir']
196 elsif sisu_install_type? ==:system_install
197 #SiSU_Info_Env::InfoEnv.new.path.share
198 env['datadir']
199 else
200 env['datadir']
201 end
202 end
203 def find_all(find_flag,opt)
204 if find_flag
205 x=Dir.glob('*.ss[tm]')
206 Px[:lng_lst].each do |d|
207 if FileTest.directory?(d)
208 x << Dir.glob("#{d}/*.ss[tm]")
209 end
210 end
211 x=x.flatten
212 opt + x
213 end
214 end
215 def find_select(find_flag,opt)
216 if find_flag
217 x=[]
218 if opt.inspect =~/"[a-zA-Z][a-zA-Z0-9._-]+?"/
219 opt.each do |g|
220 x <<=if g =~/.ss[tm]/
221 Dir.glob("*#{g}")
222 else
223 Dir.glob("*#{g}*.ss[tm]")
224 end
225 Px[:lng_lst].each do |d|
226 if FileTest.directory?(d)
227 x <<=if g =~/.ss[tm]/
228 Dir.glob("#{d}/*#{g}")
229 else
230 Dir.glob("#{d}/*#{g}*.ss[tm]")
231 end
232 end
233 end
234 end
235 end
236 x.flatten
237 end
238 end
239 def sisu_glob_rules(a)
240 a=if a.inspect =~/"-[A-Za-z0-9]*[fG]/ \
241 or a.inspect =~/"--find"|"--glob"/
242 b,f=[],[]
243 find_flag=false
244 a.each do |y|
245 if y =~ /^-/
246 if y =~/^-/ \
247 && y =~/[fG]|--find|--glob/
248 find_flag=true
249 end
250 b << y
251 end
252 if find_flag \
253 && y !~ /^-/ \
254 && y =~ /\S+/
255 if y !~/\//
256 f << y
257 else
258 find_flag=false
259 puts %{sub-directories "#{y}" cannot be provided for --find or --glob at this time}
260 end
261 end
262 end
263 r=Px[:lng_lst_rgx].gsub(/\|#{lng_base}\|/,'|')
264 @lang_regx=%r{(?:#{r})}
265 if find_flag
266 (f.length > 0) \
267 ? (b + find_select(find_flag,f))
268 : find_all(find_flag,b)
269 elsif a.inspect =~/"(?:-\S+?|--\S+?)"/ \
270 && a.inspect =~/"#{@lang_regx}\/?"/ \
271 && a.inspect =~/"#{lng_base}\/\S+?\.ss[tm]"/
272 init_selected_lang_dirs(a)
273 else b
274 end
275 else a
276 end
277 end
278 def init_selected_lang_dirs(a)
279 @z=a.each.map do |y|
280 if y =~/^#{lng_base}\/(\S+?\.ss[tm])$/
281 @fn=$1
282 y
283 elsif y =~/^#{@lang_regx}\/?$/
284 "#{y}/#{@fn}"
285 else y
286 end
287 end
288 end
289 def init
290 a=@a
291 s=expand_numeric_shortcuts(a)
292 q=set_files_and_paths_and_general_extract(s)
293 files=(q[:files].length > 0) ? :true : :false
294 @select_arr=opt_cmd_and_mod_adjust(q[:opt_ch],q[:selections],files)
295 if a.length > 0
296 @what=q[:what] unless q[:what].empty?
297 @paths = q[:paths]
298 @files = q[:files]
299 @f_pths = q[:f_pths]
300 @lngs = q[:lngs]
301 if @files.length > 0 \
302 and @opt_ch.empty? \
303 and @select_arr.length==0 #% if no other action called on filename given, default is sisu --v5 -0 [filename(s)] configured as flag default
304 shortcut=SiSU_Env::InfoProcessingFlag.new
305 @select_arr=['--v5']
306 @select_arr << shortcut.act_0.arr #+ ' --dal'
307 end
308 if @select_arr.inspect =~/--verbose/ \
309 && @opt_ch !~/-[ku]*v[ku]*$/
310 SiSU_Screen::Ansi.new(
311 @opt_ch,
312 "\tsisu " + @opt_ch + ' ' + @select_arr.join(' ') + ' ' + @files.join(' ') + "\n"
313 ).print_brown
314 end
315 end
316 @@act ? @act=@@act : @@act=@act=opt_act
317 self
318 end
319 def sisu_document_make_pod
320 def makefile_name
321 SiSU_Env::GetInit.new.sisu_document_make.makefile_name
322 end
323 def makefile(pod_make_path)
324 "#{pod_make_path}/#{makefile_name}"
325 end
326 def makefile_read(pod_make_path)
327 if FileTest.file?(makefile(pod_make_path))
328 sisu_doc_makefile=IO.read(makefile(pod_make_path), mode: 'r:utf-8')
329 sisu_doc_makefile.split(/\s*\n\s*\n/m)
330 else nil
331 end
332 end
333 self
334 end
335 def set_files_and_paths_and_general_extract(s)
336 c,w='',''
337 m,f,pth,lng,lngs=[],[],[],[],[]
338 lng_is=''
339 a=(s.nil?) \
340 ? ['-v']
341 : s.split(/\s+/)
342 r_l=Px[:lng_lst].join('|')
343 a.uniq.each do |x|
344 if x =~/^-[a-z0-5]+/i \
345 or x =~/^--\S+/
346 if x =~/^-([a-z0-5]+)/i
347 c << $1
348 end
349 if x =~/^--\S+/
350 m << x
351 end
352 elsif x =~ /(?:\.(?:(?:-|ssm\.)?sst(?:\.xml)?|ssm|ssi|sx[sdn]\.xml|s[1-3]|kdi|ssp)|\S+?\.ss[mt]\.(?:txz|zip)|sisupod\.(?:txz|zip))$/
353 if x =~/\S+?\.ss[mt]\.(?:txz|zip)|sisupod\.(?:txz|zip)/
354 if x =~/^(?:https?|file):\/\/\S+/ #\
355 end
356 pwd=Dir.pwd
357 fn_pod=x.gsub(/([^\/]+)\.txz$/,'\1')
358 fullname=@env.processing_path.processing + '/sisupod/' + fn_pod
359 pt=Pathname.new(fullname)
360 FileUtils::mkdir_p(pt.to_s)
361 pod_make_path=fullname + '/sisupod/doc/_sisu'
362 make_instruct_array=sisu_document_make_pod.makefile_read(pod_make_path)
363 @make_instructions_pod=
364 HeaderCommon.new.sisu_document_make_instructions(make_instruct_array)
365 Dir.chdir(pt.realpath)
366 system("
367 chdir #{fullname}
368 tar xaf #{pwd}/#{x}
369 chdir #{pwd}
370 ")
371 Dir.chdir(pt.realpath.to_s + '/sisupod/doc')
372 r=Px[:lng_lst_rgx]
373 Dir.entries("#{fullname}/sisupod/doc").each do |d_lng|
374 if d_lng =~/^(?:#{r})$/
375 Dir.chdir(pt.realpath.to_s + "/sisupod/doc/#{d_lng}")
376 filenames=Dir.glob("*.ss[mt]")
377 filenames.each do |fn|
378 f_pths << {
379 pth: "#{fullname}/sisupod/doc/#{d_lng}",
380 f: "#{fn}",
381 pth_stub: 'doc',
382 lng: d_lng,
383 lng_is: d_lng,
384 url_base: '',
385 url: ''
386 }
387 Dir.chdir(pwd)
388 f << fn
389 end
390 end
391 end
392 elsif x =~/^(?:https?|file):\/\/\S+/ \
393 and x =~/\S+?\.ss[mt]$/
394 r_url=/(http:\/\/\S+?\/\S+?\/src(?:\/(?:#{r_l}))?)\//
395 url_base = (x[r_url,1])
396 url = x
397 y=x.gsub(/http:\/\/\S+?\/\S+?\/src\//,'')
398 t=/(#{r_l})\/[^\/]+?\.ss[tm]$/
399 l_p = (y[t,1]) \
400 ? y[t,1]
401 : nil
402 lng << l_p
403 lngs << if l_p
404 l_p
405 elsif x =~/~(#{r_l})\.ss[tm]/
406 $1
407 else lng_base
408 end
409 r_f=/(?:#{r_l})\/([^\/]+?\.ss[tm])$/
410 fn = (y[r_f,1]) \
411 ? y[r_f,1]
412 : y
413 fn=fn.gsub(/\.((?:ssm\.)?sst)/,'.-\1')
414 fullname=Dir.pwd + '/' + fn
415 pt=Pathname.new(fullname)
416 pth << Dir.pwd
417 r_u=/.+?\/([^\/]+)(?:\/(?:#{r_l})$|$)/
418 lng_is =if l_p
419 l_p
420 elsif x =~/~(#{r_l})\.ss[tm]/
421 $1
422 else lng_base
423 end
424 f_pths << {
425 pth: pt.split[0].realpath.to_s,
426 f: pt.split[1].to_s,
427 pth_stub: pt.split[0].realpath.to_s[r_u,1],
428 lng: (pt.split[0].realpath.to_s[t,1]) \
429 ? pt.split[0].realpath.to_s[t,1]
430 : nil,
431 lng_is: lng_is,
432 url_base: url_base,
433 url: url
434 }
435 f << fn
436 elsif FileTest.file?(x)
437 pt=Pathname.new(x)
438 pth << pt.split[0].realpath.to_s #remove?
439 f << pt.split[1].to_s #remove?
440 r_u=/.+?\/([^\/]+)(?:\/(?:#{r_l})$|$)/
441 t=/.+\/(#{r_l})$/
442 l_p = (pt.split[0].realpath.to_s[t,1]) \
443 ? pt.split[0].realpath.to_s[t,1]
444 : nil
445 lngs << lng_is = if l_p
446 l_p
447 elsif x =~/~(#{r_l})\.ss[tm]/
448 $1
449 else lng_base
450 end
451 f_pths << {
452 pth: pt.split[0].realpath.to_s,
453 f: pt.split[1].to_s,
454 pth_stub: pt.split[0].realpath.to_s[r_u,1],
455 lng: lng_is,
456 lng_is: lng_is,
457 url_base: nil,
458 url: nil,
459 }
460 else puts "file not found: #{x}"
461 end
462 elsif x =~ /\.termsheet\.rb$/
463 (FileTest.file?(x)) \
464 ? (f << x)
465 : (puts "file not found: #{x}")
466 else w=x
467 puts "#{x} in #{a.join(' ')}?"
468 end
469 end
470 {
471 opt_ch: c,
472 selections: m,
473 what: w,
474 paths: pth,
475 files: f,
476 f_pths: f_pths,
477 lng: lng_is,
478 lngs: lngs,
479 }
480 end
481 def expand_numeric_shortcuts(a)
482 s=''
483 a.each do |x|
484 y=case x
485 when /0/
486 (x=~/^-0\S+/) \
487 ? x.gsub(/^-0(\S+)/,'--act0' + ' -\1')
488 : x.gsub(/^-0/,'--act0' + ' ')
489 when /1/
490 (x=~/^-1\S+/) \
491 ? x.gsub(/^-1(\S+)/,'--act1' + ' -\1')
492 : x.gsub(/^-1/,'--act1' + ' ')
493 when /2/
494 (x=~/^-2\S+/) \
495 ? x.gsub(/^-2(\S+)/,'--act2' + ' -\1')
496 : x.gsub(/^-2/,'--act2' + ' ')
497 when /3/
498 (x=~/^-3\S+/) \
499 ? x.gsub(/^-3(\S+)/,'--act3' + ' -\1')
500 : x.gsub(/^-3/,'--act3' + ' ')
501 when /4/
502 (x=~/^-4\S+/) \
503 ? x.gsub(/^-4(\S+)/,'--act4' + ' -\1')
504 : x.gsub(/^-4/,'--act4' + ' ')
505 when /5/
506 (x=~/^-5\S+/) \
507 ? x.gsub(/^-5(\S+)/,'--act5' + ' -\1')
508 : x.gsub(/^-5/,'--act5' + ' ')
509 when /6/
510 (x=~/^-6\S+/) \
511 ? x.gsub(/^-6(\S+)/,'--act6' + ' -\1')
512 : x.gsub(/^-6/,'--act6' + ' ')
513 when /7/
514 (x=~/^-7\S+/) \
515 ? x.gsub(/^-7(\S+)/,'--act7' + ' -\1')
516 : x.gsub(/^-7/,'--act7' + ' ')
517 when /8/
518 (x=~/^-8\S+/) \
519 ? x.gsub(/^-8(\S+)/,'--act8' + ' -\1')
520 : x.gsub(/^-8/,'--act8' + ' ')
521 when /9/
522 (x=~/^-9\S+/) \
523 ? x.gsub(/^-9(\S+)/,'--act9' + ' -\1')
524 : x.gsub(/^-9/,'--act9' + ' ')
525 else x
526 end
527 s << " #{y}" unless y.empty?
528 end
529 s.strip!
530 end
531 def opt_cmd_and_mod_adjust(ch,select_arr,files)
532 select_arr=select_arr.flatten
533 sel_init=select_arr.flatten
534 shortcut=SiSU_Env::InfoProcessingFlag.new
535 if files ==:true
536 if not sel_init.empty? \
537 and sel_init.inspect =~/"--act[s0-9]?/
538 sel_init.each do |s|
539 select_arr <<=case s
540 when /--act0/ then shortcut.act_0.arr
541 when /--act1/ then shortcut.act_1.arr
542 when /--act2/ then shortcut.act_2.arr
543 when /--act3/ then shortcut.act_3.arr
544 when /--act4/ then shortcut.act_4.arr
545 when /--act5/ then shortcut.act_5.arr
546 when /--act6/ then shortcut.act_6.arr
547 when /--act7/ then shortcut.act_7.arr
548 when /--act8/ then shortcut.act_8.arr
549 when /--act9/ then shortcut.act_9.arr
550 when /--act/ then shortcut.act_info
551 end
552 end
553 end
554 if not sel_init.empty? \
555 and sel_init.inspect =~/"--pdf-/
556 select_arr << '--pdf'
557 sel_init.each do |s|
558 if s =~ /^--pdf-(?:(?:l|landscape)(?:-(?:a4|letter|a5|b5|legal))?|(?:a4|letter|a5|b5|legal)-(?:l|landscape))$/
559 select_arr << '--landscape'
560 end
561 if s =~ /^--pdf-(?:(?:p|portrait)(?:-(?:a4|letter|a5|b5|legal))?|(?:a4|letter|a5|b5|legal)-(?:p|portrait))$/
562 select_arr << '--portrait'
563 end
564 if s =~ /^--pdf(?:-(?:a4|letter|a5|b5|legal)(?:-(?:[lp]|landscape|portrait))?|(?:-(?:[lp]|landscape|portrait))(?:-(?:a4|letter|a5|b5|legal)))$/
565 if s =~ /^--pdf(?:-a4(?:-(?:[lp]|landscape|portrait))?|(?:-(?:[lp]|landscape|portrait))-a4)$/
566 select_arr << '--papersize-a4'
567 end
568 if s =~ /^--pdf(?:-a5(?:-(?:[lp]|landscape|portrait))?|(?:-(?:[lp]|landscape|portrait))-a5)$/
569 select_arr << '--papersize-a5'
570 end
571 if s =~ /^--pdf(?:-b5(?:-(?:[lp]|landscape|portrait))?|(?:-(?:[lp]|landscape|portrait))-b5)$/
572 select_arr << '--papersize-b5'
573 end
574 if s =~ /^--pdf(?:-letter(?:-(?:[lp]|landscape|portrait))?|(?:-(?:[lp]|landscape|portrait))-letter)$/
575 select_arr << '--papersize-letter'
576 end
577 if s =~ /^--pdf(?:-legal(?:-(?:[lp]|landscape|portrait))?|(?:-(?:[lp]|landscape|portrait))-legal)$/
578 select_arr << '--papersize-legal'
579 end
580 end
581 end
582 select_arr=select_arr.uniq
583 end
584 if ch.empty? \
585 and sel_init.length == 0
586 select_arr << shortcut.act_0.arr ################ & --flag empty
587 elsif not ch.empty?
588 if ch =~/c/ then select_arr << '--color-toggle'
589 ch=ch.gsub(/[c]/,'')
590 end
591 if ch =~/k/ then select_arr << '--color-off'
592 ch=ch.gsub(/[k]/,'')
593 end
594 if ch =~/C/ then select_arr << '--config'
595 ch=ch.gsub(/[C]+/,'')
596 end
597 if ch =~/m/ then select_arr << '--dal'
598 ch=ch.gsub(/[m]/,'')
599 end
600 if ch =~/t/ then select_arr << '--txt'
601 ch=ch.gsub(/[t]/,'')
602 end
603 if ch =~/h/ then select_arr << '--html'
604 ch=ch.gsub(/[h]/,'')
605 end
606 if ch =~/e/ then select_arr << '--epub'
607 ch=ch.gsub(/[e]/,'')
608 end
609 if ch =~/o/ then select_arr << '--odt'
610 ch=ch.gsub(/[o]/,'')
611 end
612 if ch =~/d/ then select_arr << '--docbook'
613 ch=ch.gsub(/[d]/,'')
614 end
615 if ch =~/p/ then select_arr << '--pdf'
616 ch=ch.gsub(/[p]/,'')
617 end
618 if ch =~/w/ then select_arr << '--concordance'
619 ch=ch.gsub(/[w]/,'')
620 end
621 if ch =~/i/ then select_arr << '--manpage'
622 ch=ch.gsub(/[i]/,'')
623 end
624 if ch =~/I/ then select_arr << '--texinfo'
625 ch=ch.gsub(/[I]/,'')
626 end
627 if ch =~/b/ then select_arr << '--xhtml'
628 ch=ch.gsub(/[b]/,'')
629 end
630 if ch =~/x/ then select_arr << '--xml-sax'
631 ch=ch.gsub(/[x]/,'')
632 end
633 if ch =~/X/ then select_arr << '--xml-dom'
634 ch=ch.gsub(/[X]/,'')
635 end
636 if ch =~/j/ then select_arr << '--images'
637 ch=ch.gsub(/[j]/,'')
638 end
639 if ch =~/J/ then select_arr << '--json'
640 ch=ch.gsub(/[J]/,'')
641 end
642 if ch =~/N/ then select_arr << '--digests'
643 ch=ch.gsub(/[N]/,'')
644 end
645 if ch =~/P/ then select_arr << '--po4a-sst'
646 ch=ch.gsub(/[P]/,'')
647 end
648 if ch =~/d/ then select_arr << '--sqlite'
649 ch=ch.gsub(/[d]/,'')
650 end
651 if ch =~/D/ then select_arr << '--pg'
652 ch=ch.gsub(/[D]/,'')
653 end
654 if ch =~/Q/ then select_arr << '--qrcode'
655 ch=ch.gsub(/[Q]/,'')
656 end
657 if ch =~/s/ then select_arr << '--source'
658 ch=ch.gsub(/[s]/,'')
659 end
660 if ch =~/S/ then select_arr << '--sisupod'
661 ch=ch.gsub(/[S]/,'')
662 end
663 if ch =~/m/ then select_arr << '--manifest'
664 ch=ch.gsub(/[m]/,'')
665 end
666 if ch =~/R/ then select_arr << '--rsync'
667 ch=ch.gsub(/[R]/,'')
668 end
669 if ch =~/r/ then select_arr << '--scp'
670 ch=ch.gsub(/[r]/,'')
671 end
672 if ch =~/g/ then select_arr << '--git'
673 ch=ch.gsub(/[g]/,'')
674 end
675 if ch =~/U/ then select_arr << '--urls'
676 ch=ch.gsub(/[u]/,'')
677 end
678 if ch =~/Z/ then select_arr << '--zap'
679 ch=ch.gsub(/[Z]/,'')
680 end
681 if ch =~/F/ then select_arr << '--sample-search-form'
682 ch=ch.gsub(/[F]/,'')
683 end
684 if ch =~/W/ then select_arr << '--webrick'
685 ch=ch.gsub(/[w]/,'')
686 end
687 if ch =~/M/ then select_arr << '--maintenance'
688 ch=ch.gsub(/[M]/,'')
689 end
690 if ch =~/V/ then select_arr << '--very-verbose'
691 ch=ch.gsub(/[V]/,'')
692 end
693 if ch =~/v/ then select_arr << '--verbose'
694 ch=ch.gsub(/[v]/,'')
695 end
696 if ch =~/q/ then select_arr << '--quiet'
697 ch=ch.gsub(/[q]/,'')
698 end
699 if select_arr.inspect !~/--urls/ \
700 and select_arr.inspect \
701 !~/"--harvest/
702 select_arr << '--urls'
703 end
704 if select_arr.inspect !~/--dal/ \
705 and select_arr.inspect =~/txt|text|html|odt|epub|docbook|xml|pdf|manpage|texinfo|concordance|qrcode|source|sisupod|pg|sqlite|zap/
706 select_arr << '--dal'
707 end
708 if select_arr.inspect !~/--manifest/ \
709 and select_arr.inspect =~/txt|text|html|odt|epub|docbook|xml|pdf|manpage|texinfo|concordance|qrcode|source|sisupod|pg|sqlite|zap/
710 select_arr << '--manifest'
711 end
712 if select_arr.inspect !~/--images/ \
713 and select_arr.inspect =~/html|odt|docbook|xml|qrcode/
714 select_arr << '--images'
715 end
716 end
717 else
718 if not sel_init.empty? \
719 and sel_init.inspect =~/"--acts?/
720 shortcut.act_info
721 exit
722 end
723 if ch =~/c/ then select_arr << '--color-toggle'
724 ch=ch.gsub(/[c]/,'')
725 end
726 if ch =~/k/ then select_arr << '--color-off'
727 ch=ch.gsub(/[k]/,'')
728 end
729 if ch =~/C/ then select_arr << '--config'
730 ch=ch.gsub(/[C]+/,'')
731 end
732 if sel_init.inspect =~/"--createdb"|"--create(?:all)?"|"--dropall"|"--recreate(?:all)?"/
733 if ch =~/d/ then select_arr << '--sqlite'
734 ch=ch.gsub(/[d]/,'')
735 end
736 if ch =~/D/ then select_arr << '--pg'
737 ch=ch.gsub(/[D]/,'')
738 end
739 end
740 if ch =~/W/ then select_arr << '--webrick'
741 ch=ch.gsub(/[w]/,'')
742 end
743 if ch =~/v/ then select_arr << '--version'
744 ch=ch.gsub(/[v]/,'')
745 end
746 if ch =~/M/ then select_arr << '--maintenance'
747 ch=ch.gsub(/[M]/,'')
748 end
749 if ch =~/V/ then select_arr << '--very-verbose'
750 ch=ch.gsub(/[V]/,'')
751 end
752 if ch =~/q/ then select_arr << '--quiet'
753 ch=ch.gsub(/[q]/,'')
754 end
755 end
756 select_arr=select_arr.flatten.compact.uniq.sort
757 end
758 def opt_act
759 select_arr=@select_arr
760 @@act=if @@act
761 @act=@@act
762 else
763 act={}
764 act[:no_stop]=if select_arr.inspect \
765 =~/"--no-stop"|"--errors-as-warnings"/
766 { bool: true, set: :on }
767 else
768 { bool: false, set: :na }
769 end
770 act[:license]=(select_arr.inspect \
771 =~/"--license/) \
772 ? { bool: true, set: :on }
773 : { bool: false, set: :na }
774 act[:site_init]=(select_arr.inspect \
775 =~/"--init"|"--initialize"|"--init-site"|"--conf"|"--config"|"--configure"/) \
776 ? { bool: true, set: :on }
777 : { bool: false, set: :na }
778 act[:rc]=if select_arr.inspect \
779 =~/"--rc=/
780 x=Dir.pwd + '/' + select_arr.join.gsub(/--rc=/,'')
781 { bool: true, set: :on, inst: x }
782 else
783 { bool: false, set: :na, inst: '' }
784 end
785 act[:processing_path]=if select_arr.inspect \
786 =~/"--processing-path=/
787 base_pth=select_arr.join(';').gsub(/^.*--processing-path=['"]?(.+?)(?:['"]?;.+)?$/,'\1')
788 { bool: true, set: :on, inst: base_pth }
789 elsif select_arr.inspect \
790 =~/"--processing-path/
791 { bool: true, set: :on, inst: @base_path }
792 else
793 { bool: false, set: :na, inst: nil }
794 end
795 act[:dump]=if select_arr.inspect \
796 =~/"--dump=/
797 base_pth=select_arr.join(';').
798 gsub(/^.*--dump=['"]?(.+?)(?:['"]?;.+)?$/,'\1')
799 { bool: true, set: :on, inst: base_pth }
800 elsif select_arr.inspect =~/"--dump/
801 { bool: true, set: :on, inst: @base_path }
802 else
803 { bool: false, set: :na, inst: nil }
804 end
805 act[:redirect]=if select_arr.inspect \
806 =~/"--redirect=/
807 base_pth=select_arr.join(';').
808 gsub(/^.*--redirect=['"]?(.+?)(?:['"]?;.+)?$/,'\1')
809 { bool: true, set: :on, inst: base_pth }
810 elsif select_arr.inspect \
811 =~/"--redirect/
812 { bool: true, set: :on, inst: @base_path }
813 else
814 { bool: false, set: :na, inst: nil }
815 end
816 act[:switch]=if select_arr.inspect \
817 =~/"--switch-off=/
818 off_list=select_arr.join(';').
819 gsub(/^.*--switch-off=['"]?(.+?)(?:['"];.+)?$/,'\1')
820 off_list=off_list.scan(/[^,;\s]+/)
821 { bool: false, set: :off, off: off_list}
822 else { bool: true, set: :na, off: [] }
823 end
824 act[:default_language]=if select_arr.inspect \
825 =~/"--(?:default-)?language[-=](\S{2})"/
826 { set: :on, code: $1 }
827 elsif lng_base
828 { set: :on, code: lng_base }
829 else { set: :na, code: 'en' }
830 end
831 act[:i18n]=if select_arr.inspect \
832 =~/"(?:--monolingual|--i18n-mono(?:lingual)?)"/ #if monolingual possible outputs output_by :filename & :filetype only, without language code in default language name; give warning of conflict settings if monolingual & :language selected
833 @lingual=:mono
834 { set: :mono }
835 elsif select_arr.inspect \
836 =~/"(?:--multilingual|--i18n-multi(?:lingual)?)"/
837 @lingual=:multi
838 { set: :multi }
839 else { set: :na }
840 end
841 act[:output_by]=if select_arr.inspect \
842 =~/"--(?:output-)?by-language"/
843 @dir_structure_by=:language
844 { set: :language }
845 elsif select_arr.inspect \
846 =~/"--(?:output-)?by-filename"/
847 @dir_structure_by=:filename
848 { set: :filename }
849 elsif select_arr.inspect \
850 =~/"--(?:output-)?by-filetype"/
851 @dir_structure_by=:filetype
852 { set: :filetype }
853 else { set: :na }
854 end
855 act[:ocn]=if select_arr.inspect \
856 =~/"--ocn"|"--inc-ocn"|"--numbering"|"--inc-numbering"/
857 { bool: true, set: :on }
858 elsif select_arr.inspect \
859 =~/"--no-ocn"|"--exc-ocn"|"--no-numbering"|"--exc-numbering"/ \
860 || act[:switch][:off].inspect =~/"ocn"|"--numbering"/
861 { bool: false, set: :off }
862 else { bool: true, set: :na }
863 end
864 act[:toc]=if select_arr.inspect \
865 =~/"--inc-toc"/
866 { bool: true, set: :on }
867 elsif select_arr.inspect \
868 =~/"--(?:exc|no)-toc"/ \
869 || act[:switch][:off].inspect =~/"toc"/
870 { bool: false, set: :off }
871 else { bool: true, set: :na }
872 end
873 act[:minitoc]=if select_arr.inspect \
874 =~/"--inc-minitoc"/
875 { bool: true, set: :on }
876 elsif select_arr.inspect \
877 =~/"--(?:exc|no)-minitoc"/ \
878 || act[:switch][:off].inspect =~/"minitoc"/
879 { bool: false, set: :off }
880 else { bool: true, set: :na }
881 end
882 act[:links_to_manifest]=if select_arr.inspect \
883 =~/"--inc-links-to-manifest"|"--inc-manifest-links"/
884 { bool: true, set: :on }
885 elsif select_arr.inspect \
886 =~/"--(?:exc|no)-manifest"/ \
887 || act[:switch][:off].inspect =~/"manifest"/ #place lower
888 { bool: false, set: :off }
889 elsif select_arr.inspect \
890 =~/"--(?:exc|no)-links-to-manifest"|"--(?:exc|no)-manifest-links"/ \
891 || act[:switch][:off].inspect \
892 =~/"links_to_manifest"|"manifest_links"|"--(?:exc|no)-manifest"/ \
893 || select_arr.inspect \
894 =~/"--(?:redirect|dump)/
895 { bool: false, set: :off }
896 else { bool: true, set: :na }
897 end
898 act[:manifest_minitoc]=if select_arr.inspect \
899 =~/"--inc-manifest-minitoc"|"--inc-minitoc"/
900 { bool: true, set: :on }
901 elsif select_arr.inspect \
902 =~/"--(?:exc|no)-manifest-minitoc"|"--(?:exc|no)-minitoc"/ \
903 || act[:switch][:off].inspect =~/"manifest_minitoc"|"minitoc"/
904 { bool: false, set: :off }
905 else { bool: true, set: :na }
906 end
907 act[:metadata]=if select_arr.inspect \
908 =~/"--inc-metadata"/
909 { bool: true, set: :on }
910 elsif select_arr.inspect \
911 =~/"--(?:exc|no)-metadata"/ \
912 || act[:switch][:off].inspect =~/"metadata"/
913 { bool: false, set: :off }
914 else { bool: true, set: :na }
915 end
916 act[:html_minitoc]=if select_arr.inspect \
917 =~/"--inc-html-minitoc"|"--inc-minitoc"/
918 { bool: true, set: :on }
919 elsif select_arr.inspect \
920 =~/"--(?:exc|no)-html-minitoc"|"--(?:exc|no)-minitoc"/ \
921 || act[:switch][:off].inspect =~/"html_minitoc"|"minitoc"/
922 { bool: false, set: :off }
923 else { bool: true, set: :na }
924 end
925 act[:html_navigation]=if select_arr.inspect \
926 =~/"--inc-html-navigation"|"--inc-navigation"/
927 { bool: true, set: :on }
928 elsif select_arr.inspect \
929 =~/"--(?:exc|no)-html-navigation"|"--(?:exc|no)-navigation"/ \
930 || act[:switch][:off].inspect =~/"html_navigation"|"nav"/
931 { bool: false, set: :off }
932 else { bool: true, set: :na }
933 end
934 act[:html_navigation_bar]=if select_arr.inspect \
935 =~/"--inc-html-navigation-bar"|"--inc-navigation-bar"/
936 { bool: true, set: :on }
937 elsif select_arr.inspect \
938 =~/"--(?:exc|no)-html-navigation-bar"|"--(?:exc|no)-navigation-bar"/ \
939 || act[:switch][:off].inspect =~/"html_navigation_bar"|"navbar"/
940 { bool: false, set: :off }
941 else { bool: false, set: :na }
942 end
943 act[:segsubtoc]=if select_arr.inspect \
944 =~/"--inc-segsubtoc"/
945 { bool: true, set: :on }
946 elsif select_arr.inspect \
947 =~/"--(?:exc|no)-segsubtoc"/ \
948 || act[:switch][:off].inspect =~/"segsubtoc"/
949 { bool: false, set: :off }
950 else { bool: true, set: :na }
951 end
952 act[:search_form]=if select_arr.inspect \
953 =~/"--inc-search-form"/
954 { bool: true, set: :on }
955 elsif select_arr.inspect \
956 =~/"--(?:exc|no)-search-form"/ \
957 || act[:switch][:off].inspect =~/"search_form"|"search"/
958 { bool: false, set: :off }
959 else { bool: true, set: :na }
960 end
961 act[:html_search_form]=if select_arr.inspect \
962 =~/"--inc-html-search-form"|"--inc-search-form"/
963 { bool: true, set: :on }
964 elsif select_arr.inspect \
965 =~/"--(?:exc|no)-html-search-form"|"--(?:exc|no)-search-form"/ \
966 || act[:switch][:off].inspect \
967 =~/"html_search_form"|"search_form"|"search"/
968 { bool: false, set: :off }
969 else { bool: true, set: :na }
970 end
971 act[:html_right_pane]=if select_arr.inspect \
972 =~/"--inc-html-right-pane"|"--inc-right-pane"|"--inc-html-right-column"|"--inc-right-column"/
973 { bool: true, set: :on }
974 elsif select_arr.inspect \
975 =~/"--(?:exc|no)-html-right-pane"|"--(?:exc|no)-right-pane"|"--(?:exc|no)-html-right-column"|"--(?:exc|no)-right-column"/ \
976 || act[:switch][:off].inspect =~/"html_right_pane"|"html_right_column"|"promo"/
977 { bool: false, set: :off }
978 else { bool: true, set: :na }
979 end
980 act[:html_top_band]=if select_arr.inspect \
981 =~/"--inc-html-top-band"|"--inc-top-band"/
982 { bool: true, set: :on }
983 elsif select_arr.inspect \
984 =~/"--(?:exc|no)-html-top-band"|"--(?:exc|no)-top-band"/ \
985 || act[:switch][:off].inspect =~/"html-top-band"|"top-band"/
986 { bool: false, set: :off }
987 else { bool: true, set: :na }
988 end
989 act[:html]=if select_arr.inspect \
990 =~/"--html-strict"/ \
991 or ((select_arr.inspect \
992 =~/"--html"/) \
993 && select_arr.inspect \
994 =~/"--strict"/)
995 act[:html_strict]={ bool: true, set: :on }
996 act[:html_scroll]={ bool: true, set: :on }
997 act[:html_seg]={ bool: true, set: :on }
998 { bool: true, set: :on }
999 elsif (select_arr.inspect \
1000 =~/"--html"/)
1001 act[:html_strict]={ bool: false, set: :off }
1002 act[:html_scroll]={ bool: true, set: :on }
1003 act[:html_seg]={ bool: true, set: :on }
1004 { bool: true, set: :on }
1005 else
1006 act[:html_strict]=(select_arr.inspect \
1007 =~/"--strict"/) \
1008 ? { bool: true, set: :on }
1009 : { bool: false, set: :na }
1010 act[:html_scroll]=(select_arr.inspect \
1011 =~/"--html-scroll"/) \
1012 ? { bool: true, set: :on }
1013 : { bool: false, set: :na }
1014 act[:html_seg]=(select_arr.inspect \
1015 =~/"--html-seg"/) \
1016 ? { bool: true, set: :on }
1017 : { bool: false, set: :na }
1018 { bool: false, set: :na }
1019 end
1020 act[:concordance]=(select_arr.inspect \
1021 =~/"--concordance"/) \
1022 ? { bool: true, set: :on }
1023 : { bool: false, set: :na }
1024 act[:images]=(select_arr.inspect \
1025 =~/"--images"/) \
1026 ? { bool: true, set: :on }
1027 : { bool: false, set: :na }
1028 act[:json]=(select_arr.inspect \
1029 =~/"--json"/) \
1030 ? { bool: true, set: :on }
1031 : { bool: false, set: :na }
1032 if select_arr.inspect \
1033 =~/"--pdf"/
1034 if select_arr.inspect \
1035 =~/"--portrait"/
1036 act[:pdf]= { bool: false, set: :na }
1037 act[:pdf_l]={ bool: false, set: :na }
1038 act[:pdf_p]={ bool: true, set: :on }
1039 elsif select_arr.inspect \
1040 =~/"--landscape"/
1041 act[:pdf]= { bool: false, set: :na }
1042 act[:pdf_l]={ bool: true, set: :on }
1043 act[:pdf_p]={ bool: false, set: :na }
1044 else
1045 act[:pdf]= { bool: true, set: :on }
1046 act[:pdf_l]={ bool: true, set: :on }
1047 act[:pdf_p]={ bool: true, set: :on }
1048 end
1049 else
1050 act[:pdf]= { bool: false, set: :na }
1051 act[:pdf_p]= { bool: false, set: :na }
1052 act[:pdf_l]= { bool: false, set: :na }
1053 act[:pdf_a4]= { bool: false, set: :na }
1054 act[:pdf_a5]= { bool: false, set: :na }
1055 act[:pdf_b5]= { bool: false, set: :na }
1056 act[:pdf_letter]={ bool: false, set: :na }
1057 act[:pdf_legal]= { bool: false, set: :na }
1058 end
1059 if act[:pdf][:set]==:on \
1060 or act[:pdf_p][:set]==:on \
1061 or act[:pdf_l][:set]==:on
1062 act[:pdf_a4]=if select_arr.inspect \
1063 =~/"--a4"|--papersize-a4"/ \
1064 or select_arr.inspect \
1065 =~/"--papersize=\S*a4\b\S*"/ #--papersize=a4,a5
1066 { bool: true, set: :on }
1067 else
1068 { bool: false, set: :na }
1069 end
1070 act[:pdf_a5]=if select_arr.inspect \
1071 =~/"--a5"|"--papersize-a5"/ \
1072 or select_arr.inspect \
1073 =~/"--papersize=\S*a5\b\S*"/ #--papersize=a4,a5
1074 { bool: true, set: :on }
1075 else
1076 { bool: false, set: :na }
1077 end
1078 act[:pdf_b5]=if select_arr.inspect \
1079 =~/"--b5"|"--papersize-b5"/ \
1080 or select_arr.inspect \
1081 =~/"--papersize=\S*b5\b\S*"/
1082 { bool: true, set: :on }
1083 else
1084 { bool: false, set: :na }
1085 end
1086 act[:pdf_letter]=if select_arr.inspect \
1087 =~/"--letter"|"--papersize-letter"/ \
1088 or select_arr.inspect \
1089 =~/"--papersize=\S*letter\b\S*"/
1090 { bool: true, set: :on }
1091 else
1092 { bool: false, set: :na }
1093 end
1094 act[:pdf_legal]=if select_arr.inspect \
1095 =~/"--legal"|"--papersize-legal"/ \
1096 or select_arr.inspect \
1097 =~/"--papersize=\S*legal\b\S*"/
1098 { bool: true, set: :on }
1099 else
1100 { bool: false, set: :na }
1101 end
1102 end
1103 act[:epub]=(select_arr.inspect \
1104 =~/"--epub"/) \
1105 ? { bool: true, set: :on }
1106 : { bool: false, set: :na }
1107 act[:odt]=if select_arr.inspect \
1108 =~/"--odt"|"--odf"|"--odt-(?:ocn|numbering)"|"--odf-(?:ocn|numbering)"/
1109 act[:odt_ocn]=if (select_arr.inspect \
1110 =~/"--odt-(?:ocn|numbering)"|"--odf-(?:ocn|numbering)"/ \
1111 or select_arr.inspect \
1112 =~/"--ocn"|"--inc-ocn"|"--numbering"|"--inc-numbering"/)
1113 { bool: true, set: :on }
1114 elsif select_arr.inspect \
1115 =~/"--no-ocn"|"--exc-ocn"|"--no-numbering"|"--exc-numbering"/
1116 { bool: false, set: :off }
1117 else
1118 { bool: false, set: :na }
1119 end
1120 { bool: true, set: :on }
1121 else
1122 { bool: false, set: :na }
1123 end
1124 act[:xml_sax]=(select_arr.inspect \
1125 =~/"--xml-sax"|"--sax"/) \
1126 ? { bool: true, set: :on }
1127 : { bool: false, set: :na }
1128 act[:xml_dom]=(select_arr.inspect \
1129 =~/"--xml-dom"|"--dom"/) \
1130 ? { bool: true, set: :on }
1131 : { bool: false, set: :na }
1132 act[:xml_docbook_book]=(select_arr.inspect \
1133 =~/"--docbook"|"--docbook-book"|"--xml-docbook"|"--xml-docbook_book"/) \
1134 ? { bool: true, set: :on }
1135 : { bool: false, set: :na }
1136 act[:xml_fictionbook]=(select_arr.inspect \
1137 =~/"--fictionbook"|"--xml-fictionbook"/) \
1138 ? { bool: true, set: :on }
1139 : { bool: false, set: :na }
1140 act[:xml_scaffold_structure_sisu]=select_arr.inspect \
1141 =~/"--xml-scaffold"|"--xml-scaffold-sisu"/ \
1142 ? { bool: true, set: :on }
1143 : { bool: false, set: :na }
1144 act[:xml_scaffold_structure_collapse]=select_arr.inspect \
1145 =~/"--xml-scaffold-collapse"/ \
1146 ? { bool: true, set: :on }
1147 : { bool: false, set: :na }
1148 act[:xhtml]=(select_arr.inspect \
1149 =~/"--xhtml"/) \
1150 ? { bool: true, set: :on }
1151 : { bool: false, set: :na }
1152 act[:txt]=if select_arr.inspect \
1153 =~/"--txt"|"--text"|"--plaintext"|"--txt-(?:ocn|numbering)"|"--text-(?:ocn|numbering)"|"--plaintext-(?:ocn|numbering)"/
1154 act[:txt_ocn]=if (select_arr.inspect \
1155 =~/"--txt-(?:ocn|numbering)"|"--text-(?:ocn|numbering)"|"--plaintext-(?:ocn|numbering)"/ \
1156 or select_arr.inspect \
1157 =~/"--ocn"|"--inc-ocn"|"--numbering"|"--inc-numbering"/)
1158 { bool: true, set: :on }
1159 elsif select_arr.inspect \
1160 =~/"--no-ocn"|"--exc-ocn"|"--no-numbering"|"--exc-numbering"/
1161 { bool: false, set: :off }
1162 else
1163 { bool: false, set: :na }
1164 end
1165 { bool: true, set: :on }
1166 else
1167 { bool: false, set: :na }
1168 end
1169 act[:txt_textile]=(select_arr.inspect \
1170 =~/"--textile"/) \
1171 ? { bool: true, set: :on }
1172 : { bool: false, set: :na }
1173 act[:txt_asciidoc]=(select_arr.inspect \
1174 =~/"--asciidoc"/) \
1175 ? { bool: true, set: :on }
1176 : { bool: false, set: :na }
1177 act[:txt_markdown]=(select_arr.inspect \
1178 =~/"--markdown"/) \
1179 ? { bool: true, set: :on }
1180 : { bool: false, set: :na }
1181 act[:txt_rst]=(select_arr.inspect \
1182 =~/"--rst"|"--rest"|"--restructuredtext"/) \
1183 ? { bool: true, set: :on }
1184 : { bool: false, set: :na }
1185 act[:txt_orgmode]=(select_arr.inspect \
1186 =~/"--org"|"--orgmode"/) \
1187 ? { bool: true, set: :on }
1188 : { bool: false, set: :na }
1189 act[:manpage]=(select_arr.inspect \
1190 =~/"--manpage"|"--man"/) \
1191 ? { bool: true, set: :on }
1192 : { bool: false, set: :na }
1193 act[:texinfo]=(select_arr.inspect \
1194 =~/"--texinfo"/) \
1195 ? { bool: true, set: :on }
1196 : { bool: false, set: :na }
1197 act[:psql]=if select_arr.inspect \
1198 =~/"--pg-\S+"/ \
1199 or ((select_arr.inspect =~/"--pg"/) \
1200 && (select_arr.inspect \
1201 =~/"--createdb"|"--create(?:all)?"|"--dropall"|"--recreate(?:all)?"|"--import"|"--update"|"--remove"/))
1202 act[:psql_createdb]=if select_arr.inspect \
1203 =~/"--pg-createdb"|"--createdb"/
1204 { bool: true, set: :on }
1205 else
1206 { bool: false, set: :na }
1207 end
1208 if select_arr.inspect \
1209 =~/"--pg-recreate(?:all)?"|"--recreate(?:all)?"/
1210 act[:psql_drop]={ bool: true, set: :on }
1211 act[:psql_create]={ bool: true, set: :on }
1212 else
1213 act[:psql_drop]=if select_arr.inspect \
1214 =~/"--pg-dropall"|"--dropall"/
1215 { bool: true, set: :on }
1216 else
1217 { bool: false, set: :na }
1218 end
1219 act[:psql_create]=if select_arr.inspect \
1220 =~/"--pg-create(?:all)?"|"--create(?:all)?"/
1221 { bool: true, set: :on }
1222 else
1223 { bool: false, set: :na }
1224 end
1225 end
1226 act[:psql_import]=if select_arr.inspect \
1227 =~/"--pg-import"|"--import"/
1228 { bool: true, set: :on }
1229 else
1230 { bool: false, set: :na }
1231 end
1232 act[:psql_update]=if select_arr.inspect \
1233 =~/"--pg-update"|"--update"/
1234 act[:psql_remove]={ bool: true, set: :on }
1235 { bool: true, set: :on }
1236 else
1237 act[:psql_remove]=if select_arr.inspect \
1238 =~/"--pg-remove"|"--remove"/
1239 { bool: true, set: :on }
1240 else
1241 { bool: false, set: :na }
1242 end
1243 { bool: false, set: :na }
1244 end
1245 { bool: true, set: :on }
1246 else
1247 act[:psql_createdb]=
1248 { bool: false, set: :na }
1249 act[:psql_drop]=
1250 { bool: false, set: :na }
1251 act[:psql_create]=
1252 { bool: false, set: :na }
1253 act[:psql_import]=
1254 { bool: false, set: :na }
1255 act[:psql_update]=
1256 { bool: false, set: :na }
1257 act[:psql_remove]=
1258 { bool: false, set: :na }
1259 { bool: false, set: :na }
1260 end
1261 act[:sqlite]=if select_arr.inspect \
1262 =~/"--sqlite-\S+"/ \
1263 or (select_arr.inspect \
1264 =~/"--sqlite"/ \
1265 && select_arr.inspect \
1266 =~/"--createdb"|"--create(?:all)?"|"--dropall"|"--recreate(?:all)?"|"--import"|"--update"|"--remove"/)
1267 act[:sqlite_createdb]=if select_arr.inspect \
1268 =~/"--sqlite-createdb"|"--createdb"/
1269 { bool: true, set: :on }
1270 else
1271 { bool: false, set: :na }
1272 end
1273 if select_arr.inspect \
1274 =~/"--sqlite-recreate(?:all)?"|"--recreate(?:all)?"/
1275 act[:sqlite_drop]={ bool: true, set: :on }
1276 act[:sqlite_create]={ bool: true, set: :on }
1277 else
1278 act[:sqlite_create]=if select_arr.inspect \
1279 =~/"--sqlite-create(?:all)?"|"--create(?:all)?"/
1280 { bool: true, set: :on }
1281 else
1282 { bool: false, set: :na }
1283 end
1284 act[:sqlite_drop]=if select_arr.inspect \
1285 =~/"--sqlite-dropall"|"--dropall"/
1286 { bool: true, set: :on }
1287 else
1288 { bool: false, set: :na }
1289 end
1290 end
1291 act[:sqlite_import]=if select_arr.inspect \
1292 =~/"--sqlite-import"|"--import"/
1293 { bool: true, set: :on }
1294 else
1295 { bool: false, set: :na }
1296 end
1297 act[:sqlite_update]=if select_arr.inspect \
1298 =~/"--sqlite-update"|"--update"/
1299 act[:sqlite_remove]={ bool: true, set: :on }
1300 { bool: true, set: :on }
1301 else
1302 act[:sqlite_remove]=if select_arr.inspect \
1303 =~/"--sqlite-remove"|"--sqlite-remove"/
1304 { bool: true, set: :on }
1305 else
1306 { bool: false, set: :na }
1307 end
1308 { bool: false, set: :na }
1309 end
1310 { bool: true, set: :on }
1311 else
1312 act[:sqlite_createdb]=
1313 { bool: false, set: :na }
1314 act[:sqlite_drop]=
1315 { bool: false, set: :na }
1316 act[:sqlite_create]=
1317 { bool: false, set: :na }
1318 act[:sqlite_import]=
1319 { bool: false, set: :na }
1320 act[:sqlite_update]=
1321 { bool: false, set: :na }
1322 act[:sqlite_remove]=
1323 { bool: false, set: :na }
1324 { bool: false, set: :na }
1325 end
1326 act[:sqlite_discrete]=select_arr.inspect \
1327 =~/"--sql"|"--sqlite"/ \
1328 && (select_arr.inspect \
1329 !~/"--createdb"|"--create(?:all)?"|"--dropall"|"--recreate(?:all)?"|"--import"|"--update"|"--remove"/) \
1330 ? { bool: true, set: :on }
1331 : { bool: false, set: :na }
1332 act[:harvest]=(select_arr.inspect \
1333 =~/"--harvest"/) \
1334 ? { bool: true, set: :on }
1335 : { bool: false, set: :na }
1336 act[:po4a_sstm]=(select_arr.inspect \
1337 =~/"--po4a-ss[tm]"/) \
1338 ? { bool: true, set: :on }
1339 : { bool: false, set: :na }
1340 act[:po4a_sst_ao_sst]=(select_arr.inspect \
1341 =~/"--po4a-ao(?:-ss[tm])?"/) \
1342 ? { bool: true, set: :on }
1343 : { bool: false, set: :na }
1344 act[:po4a_shelf]=(select_arr.inspect \
1345 =~/"--po4a-shelf"|"--pot?-shelf"/) \
1346 ? { bool: true, set: :on }
1347 : { bool: false, set: :na }
1348 if act[:po4a_shelf][:set]==:on \
1349 or act[:po4a_sst_ao_sst][:set]==:on \
1350 or act[:po4a_sstm][:set]==:on
1351 act[:po4a_lang]=if select_arr.inspect \
1352 =~/"--(?:trans|init)-([a-z]{2}):((?:(?:[a-z]{2}\b),?)+)/
1353 lng_src,lng_trn=$1,$2.split(',')
1354 { bool: true, set: :on, src: lng_src, trn: lng_trn }
1355 elsif select_arr.inspect \
1356 =~/"--trans"/
1357 { bool: true, set: :on }
1358 { bool: true, set: :on, src: 'en', trn: [] }
1359 else
1360 { bool: false, set: :na }
1361 end
1362 act[:po4a_lang_trans]=if select_arr.inspect \
1363 =~/"--trans-([a-z]{2}):((?:(?:[a-z]{2}\b),?)+)/
1364 lng_src,lng_trn=$1,$2.split(',')
1365 { bool: true, set: :on, src: lng_src, trn: lng_trn }
1366 elsif select_arr.inspect \
1367 =~/"--trans"/
1368 { bool: true, set: :on }
1369 { bool: true, set: :on, src: 'en', trn: [] }
1370 else
1371 { bool: false, set: :na }
1372 end
1373 act[:po4a_lang_init]=if select_arr.inspect \
1374 =~/"--init-([a-z]{2}):((?:(?:[a-z]{2}\b),?)+)/
1375 lng_src,lng_trn=$1,$2.split(',')
1376 { bool: true, set: :on, src: lng_src, trn: lng_trn }
1377 else
1378 { bool: false, set: :na }
1379 end
1380 else
1381 act[:po4a_lang_trans]= \
1382 { bool: false, set: :na }
1383 act[:po4a_lang_init]= \
1384 { bool: false, set: :na }
1385 end
1386 act[:git]=(select_arr.inspect \
1387 =~/"--git"/) \
1388 ? { bool: true, set: :on }
1389 : { bool: false, set: :na }
1390 act[:hash_digests]=(select_arr.inspect \
1391 =~/"--digests?"|"--hash-digests"/) \
1392 ? { bool: true, set: :on }
1393 : { bool: false, set: :na }
1394 act[:pdf_font_size]=if select_arr.inspect \
1395 =~/"--(?:pdf-)?font-?size[=-](\d{1,2})(?:pt)?"/
1396 $1
1397 else :na
1398 end
1399 act[:pdf_hyperlink_colors]=if select_arr.inspect \
1400 =~/"--pdf-hyperlinks-(?:mono(?:chrome)?|no-color)"/
1401 :mono
1402 elsif select_arr.inspect \
1403 =~/"--pdf-hyperlinks-color"/
1404 :color
1405 else :na
1406 end
1407 act[:hash_digest_algo]=if select_arr.inspect \
1408 =~/"--hash-(?:sha)?512"/
1409 :sha512
1410 elsif select_arr.inspect \
1411 =~/"--hash-(?:sha)?256"/
1412 :sha256
1413 elsif select_arr.inspect \
1414 =~/"--hash-md5"/
1415 :md5
1416 else :na
1417 end
1418 act[:sample_search_form]=if select_arr.inspect \
1419 =~/"--sample-search-form"/
1420 if select_arr.inspect \
1421 =~/"--db[-=]pg"/
1422 { bool: true, set: :on, db: :pg }
1423 elsif select_arr.inspect \
1424 =~/"--db[-=]sqlite"/
1425 { bool: true, set: :on, db: :sqlite }
1426 else
1427 { bool: true, set: :on, db: :na }
1428 end
1429 else
1430 { bool: false, set: :na, db: :na }
1431 end
1432 act[:webrick]=select_arr.inspect \
1433 =~/"--webrick"/ \
1434 ? { bool: true, set: :on }
1435 : { bool: false, set: :na }
1436 act[:share_source]=select_arr.inspect \
1437 =~/"--source"/ \
1438 ? { bool: true, set: :on }
1439 : { bool: false, set: :na }
1440 act[:sisupod]=select_arr.inspect \
1441 =~/"--sisupod"/ \
1442 ? { bool: true, set: :on }
1443 : { bool: false, set: :na }
1444 act[:scp]=select_arr.inspect \
1445 =~/"--scp"/ \
1446 ? { bool: true, set: :on }
1447 : { bool: false, set: :na }
1448 act[:rsync]=select_arr.inspect \
1449 =~/"--rsync"|"--remote"/ \
1450 ? { bool: true, set: :on }
1451 : { bool: false, set: :na }
1452 act[:zap]=select_arr.inspect \
1453 =~/"--zap"|"--delete"/ \
1454 ? { bool: true, set: :on }
1455 : { bool: false, set: :na }
1456 act[:urls_all]=select_arr.inspect \
1457 =~/"--urls-all"/ \
1458 ? { bool: true, set: :on }
1459 : { bool: false, set: :na }
1460 act[:urls_selected]=if select_arr.inspect \
1461 =~/"--urls"/
1462 { bool: true, set: :on }
1463 elsif select_arr.inspect \
1464 =~/"--harvest/
1465 { bool: false, set: :off }
1466 elsif select_arr.inspect \
1467 =~/"--verbose"|"--maintenance"/
1468 { bool: true, set: :on }
1469 else
1470 { bool: false, set: :na }
1471 end
1472 act[:sitemap]=select_arr.inspect \
1473 =~/"--sitemap"/ \
1474 ? { bool: true, set: :on }
1475 : { bool: false, set: :na }
1476 act[:qrcode]=select_arr.inspect \
1477 =~/"--qrcode"/ \
1478 ? { bool: true, set: :on }
1479 : { bool: false, set: :na }
1480 act[:help]=select_arr.inspect \
1481 =~/"--help/ \
1482 ? { bool: true, set: :on }
1483 : { bool: false, set: :na }
1484 act[:ao]=if select_arr.inspect \
1485 =~/"--ao"|"--dal"/
1486 { bool: true, set: :on }
1487 elsif (act[:txt][:set]==:on \
1488 || act[:txt_textile][:set]==:on \
1489 || act[:txt_asciidoc][:set]==:on \
1490 || act[:txt_markdown][:set]==:on \
1491 || act[:txt_rst][:set]==:on \
1492 || act[:txt_orgmode][:set]==:on \
1493 || act[:xhtml][:set]==:on \
1494 || act[:epub][:set]==:on \
1495 || act[:html][:set]==:on \
1496 || act[:html_seg][:set]==:on \
1497 || act[:html_scroll][:set]==:on \
1498 || act[:json][:set]==:on \
1499 || act[:texinfo][:set]==:on \
1500 || act[:manpage][:set]==:on \
1501 || act[:hash_digests][:set]==:on \
1502 || act[:odt][:set]==:on \
1503 || act[:pdf][:set]==:on \
1504 || act[:pdf_p][:set]==:on \
1505 || act[:pdf_l][:set]==:on \
1506 || act[:qrcode][:set]==:on \
1507 || act[:sisupod][:set]==:on \
1508 || act[:share_source][:set]==:on \
1509 || act[:po4a_sstm][:set]==:on \
1510 || act[:concordance][:set]==:on \
1511 || act[:sqlite_discrete][:set]==:on \
1512 || act[:sqlite_import][:set]==:on \
1513 || act[:sqlite_update][:set]==:on \
1514 || act[:sqlite_remove][:set]==:on \
1515 || act[:psql_import][:set]==:on \
1516 || act[:psql_update][:set]==:on \
1517 || act[:psql_remove][:set]==:on \
1518 || act[:xml_dom][:set]==:on \
1519 || act[:xml_sax][:set]==:on \
1520 || act[:xml_docbook_book][:set]==:on \
1521 || act[:xml_fictionbook][:set]==:on \
1522 || act[:xml_scaffold_structure_sisu][:set]==:on \
1523 || act[:xml_scaffold_structure_collapse][:set]==:on )
1524 { bool: true, set: :on }
1525 else
1526 { bool: false, set: :na }
1527 end
1528 act[:manifest]=if select_arr.inspect \
1529 =~/"--inc-manifest"/
1530 { bool: true, set: :on }
1531 elsif select_arr.inspect \
1532 =~/"--(?:exc|no)-manifest"/ \
1533 || act[:switch][:off].inspect =~/"manifest"/
1534 { bool: false, set: :off }
1535 elsif select_arr.inspect \
1536 =~/"--manifest"/
1537 { bool: true, set: :on }
1538 elsif (act[:txt][:set]==:on \
1539 || act[:txt_textile][:set]==:on \
1540 || act[:txt_asciidoc][:set]==:on \
1541 || act[:txt_markdown][:set]==:on \
1542 || act[:txt_rst][:set]==:on \
1543 || act[:txt_orgmode][:set]==:on \
1544 || act[:xhtml][:set]==:on \
1545 || act[:epub][:set]==:on \
1546 || act[:html][:set]==:on \
1547 || act[:html_seg][:set]==:on \
1548 || act[:html_scroll][:set]==:on \
1549 || act[:json][:set]==:on \
1550 || act[:texinfo][:set]==:on \
1551 || act[:manpage][:set]==:on \
1552 || act[:hash_digests][:set]==:on \
1553 || act[:odt][:set]==:on \
1554 || act[:pdf][:set]==:on \
1555 || act[:pdf_p][:set]==:on \
1556 || act[:pdf_l][:set]==:on \
1557 || act[:qrcode][:set]==:on \
1558 || act[:sisupod][:set]==:on \
1559 || act[:share_source][:set]==:on \
1560 || act[:po4a_sstm][:set]==:on \
1561 || act[:concordance][:set]==:on \
1562 || act[:xml_dom][:set]==:on \
1563 || act[:xml_sax][:set]==:on \
1564 || act[:xml_docbook_book][:set]==:on \
1565 || act[:xml_fictionbook][:set]==:on \
1566 || act[:xml_scaffold_structure_sisu][:set]==:on \
1567 || act[:xml_scaffold_structure_collapse][:set]==:on )
1568 { bool: true, set: :on }
1569 else { bool: true, set: :na }
1570 end
1571 act[:console_messages] = ''
1572 act[:verbose]=if select_arr.inspect \
1573 =~/"--verbose"/
1574 act[:console_messages] << ' --verbose '
1575 { bool: true, set: :on }
1576 else
1577 { bool: false, set: :na }
1578 end
1579 act[:verbose_plus]=if select_arr.inspect \
1580 =~/"--very-verbose"|"--verbose-very"/
1581 act[:console_messages] << ' --very-verbose '
1582 { bool: true, set: :on }
1583 else
1584 { bool: false, set: :na }
1585 end
1586 act[:version_info]=if select_arr.inspect \
1587 =~/"--version"|"--verbose"|"--maintenance"/
1588 act[:console_messages] << ' --maintenance '
1589 { bool: true, set: :on }
1590 else
1591 { bool: false, set: :na }
1592 end
1593 act[:quiet]=if (select_arr.inspect =~/"--quiet"/)
1594 act[:console_messages] << ' --quiet '
1595 { bool: true, set: :on }
1596 else
1597 { bool: false, set: :na }
1598 end
1599 act[:color_state]=if select_arr.inspect =~/"--color-on"|"--color"/
1600 act[:console_messages] << ' --color-on '
1601 { bool: true, set: :on }
1602 elsif (select_arr.inspect =~/"--color-off"/)
1603 act[:console_messages] << ' --color-off '
1604 { bool: false, set: :off }
1605 else { bool: true, set: :na } #fix default color
1606 end
1607 # act[:color_toggle]=if select_arr.inspect =~/"--color-toggle"/
1608 # true
1609 # else false
1610 # end
1611 act[:maintenance]=if (select_arr.inspect =~/"--maintenance|--keep-processing-files"/)
1612 act[:console_messages] << ' --maintenance '
1613 { bool: true, set: :on }
1614 else
1615 { bool: false, set: :na }
1616 end
1617 act[:profile]=if (select_arr.inspect =~/"--profile"/)
1618 act[:console_messages] << ' --color-off '
1619 { bool: true, set: :on }
1620 else
1621 { bool: false, set: :na }
1622 end
1623 @act=act
1624 end
1625 end
1626 def opt_ch
1627 @opt_ch
1628 end
1629 def selections
1630 def arr
1631 @select_arr.sort
1632 end
1633 def str
1634 @select_str ||= arr.join(' ')
1635 end
1636 self
1637 end
1638 def act
1639 @@act
1640 end
1641 def files_mod
1642 files_mod=files
1643 @files_mod=files_mod
1644 end
1645 def files
1646 @files
1647 end
1648 def f_pth
1649 @f_pth
1650 end
1651 def pth
1652 @pth
1653 end
1654 def sub_location
1655 pth.gsub(/#{base_path}/,'')
1656 end
1657 def lng
1658 @lng
1659 end
1660 def lng_base
1661 @lng_base
1662 end
1663 def fno
1664 @fno=(fns.nil? || fns.empty?) \
1665 ? '' \
1666 : (fns[/(.+?(?:sst|ssm))(?:\.sst)?/,1])
1667 end
1668 def fng
1669 @fng=(fno.nil? || fno.empty?) \
1670 ? '' \
1671 : (fno.gsub(/(?:~(?:#{Px[:lng_lst_rgx]}))?(\.ss[tm])$/,'\1'))
1672 end
1673 def fns
1674 @fns
1675 end
1676 def fnl
1677 @fns.gsub(/(\S+?)((?:\.ssm)?\.sst)/,"\\1.#{lng}\\2")
1678 end
1679 def what
1680 @what
1681 end
1682 def fnb
1683 (fns.nil? || fns.empty?) \
1684 ? '' \
1685 : (fns[/(.+?)\.(?:(?:-|ssm\.)?sst|ssm)$/,1])
1686 end
1687 def fnc
1688 @fnc=(@fns =~/\.(?:ssm\.sst|ssm)$/) \
1689 ? fnb + '.ssm.sst'
1690 : @fns
1691 end
1692 def fncb
1693 @fncb=(@fns =~/(?:\~\S{2,3})?\.(?:ssm\.sst|ssm)$/) \
1694 ? fnb + '.ssm.sst'
1695 : @fns.gsub(/(?:\~\S{2,3})?(\.sst)$/,'\1')
1696 end
1697 end
1698 end
1699 __END__
1700 note usually named @opt is carried in dp document parameters (usually as @md.opt), @opt is a
1701 subset of @md where @md is passed, contents of @opt are available as @md.opt
1702 passing @opt as well is duplication check for fns & fnb