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