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