68f8c6106c68f371b40071f47ca55e90c4442417
[software/sisu] / lib / sisu / develop / dp.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** document parameters extracted from input files for program use
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/dp.rb;hb=HEAD>
55
56 =end
57 module SiSU_Param
58 begin
59 require 'uri'
60 require 'pstore'
61 rescue LoadError
62 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
63 error('uri or pstore NOT FOUND (LoadError)')
64 end
65 require_relative 'se' # se.rb
66 include SiSU_Env
67 require_relative 'dp_make' # dp_make.rb
68 require_relative 'dp_identify_markup' # dp_identify_markup.rb
69 @@date=SiSU_Env::InfoDate.new
70 @@proc=
71 @@filename_txt=
72 @@filename_texinfo=
73 @@filename_lout_portrait=
74 @@filename_lout_landscape=
75 @@filename_html_scroll=
76 @@filename_html_index=
77 @@filename_html_segtoc=
78 @@filename_semantic=
79 @@filename_rss=
80 @@newfile=
81 @@drr=
82 nil
83 @doc={
84 initialise: nil,
85 markup: '',
86 lnks: '',
87 stmp: '',
88 req: {},
89 }
90 @@yaml=@@yamladdr=nil
91 @@trigger=nil
92 @@lv,@@flag={},{}
93 @@tex_backslash="\\\\"
94 class Parameters
95 @@publisher='SiSU scribe'
96 @@md=@@fns=@@pth=nil
97 def initialize(opt)
98 @opt=opt
99 @cX||=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set])
100 @fns=if @opt.act[:psql][:set] == [:on] #revisit CHECK
101 opt.fns
102 else opt.fns.gsub(/\.ssm$/,'.ssm.sst')
103 end
104 SiSU_Param::Instantiate.new.param_instantiate
105 @env=SiSU_Env::InfoEnv.new(@fns)
106 @pstorefile="#{@env.processing_path.ao}/#{@fns}.pstore"
107 end
108 def get
109 if @opt.f_pth \
110 and @opt.f_pth[:pth] != Dir.pwd #BUG check
111 # you may need to change Dir.pwd to @opt.f_pth[:pth] where the latter
112 # has a path value that is different, however, f_pth is not always set!
113 Dir.chdir(@opt.f_pth[:pth])
114 end
115 if @@fns !=@fns \
116 or @@pth !=Dir.pwd #@opt.f_pth[:pth]
117 @@fns,@@pth=@fns,Dir.pwd #@opt.f_pth[:pth]
118 @@md=nil
119 end
120 if @@md.nil? \
121 or @opt.act[:maintenance][:set]==:on #not particularly helpful, as current cycle is through output types, with files changing, only helpful if deal with a file all output types before going to next file
122 if File.exist?(@pstorefile)
123 param_msg='Parameters from pstore'
124 store=PStore.new(@pstorefile)
125 store.transaction do
126 @md=store['md']
127 end
128 @md
129 else
130 param_msg='Parameters extracted'
131 fns_array=@env.read_source_file(@opt.fns)
132 @md=SiSU_Param::Parameters::Instructions.new(fns_array,@opt).extract
133 @md
134 end
135 if defined? @md.title.main # on removal check problems with -U
136 if (@opt.act[:verbose][:set]==:on \
137 || @opt.act[:verbose_plus][:set]==:on \
138 || @opt.act[:maintenance][:set]==:on)
139 SiSU_Screen::Ansi.new(
140 @opt.act[:color_state][:set],
141 param_msg,
142 @md.title.main
143 ).txt_grey
144 end
145 end
146 @@md=@md
147 else @@md
148 end
149 begin
150 @@md.opt=@opt
151 @@md
152 rescue
153 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('has an existing option been selected?')
154 exit
155 end
156 end
157 class MdDefault
158 def rights(author,date)
159 @author,@date=author,date
160 def assignment(author)
161 'copyright not explicitly stated, ' \
162 + 'program "assigning" copyright to author: ' \
163 + author
164 end
165 def all
166 s=nil
167 if @author
168 #puts assignment(@author)
169 s ||=((@date =~/((?:1[4-9]|2[01])\d{2})/ ) \
170 ? ("Copyright (C) #{$1} #{@author}")
171 : ('Copyright (C)' + @author)) #matches years 1400 through 21\d\d
172 end
173 s
174 end
175 def copyright_and_license
176 s=nil
177 if @author
178 #puts assignment(@author)
179 s ||=((@date =~/((?:1[4-9]|2[01])\d{2})/ ) \
180 ? ("Copyright (C) #{$1} #{@author}")
181 : ('Copyright (C)' + @author)) #matches years 1400 through 21\d\d
182 end
183 s
184 end
185 def text
186 all
187 end
188 def copyright
189 def all
190 s=nil
191 if @author
192 s ||=((@date =~/((?:1[4-9]|2[01])\d{2})/ ) \
193 ? ("Copyright (C) #{$1} #{@author}")
194 : ('Copyright (C)' + @author)) #matches years 1400 through 21\d\d
195 end
196 s
197 end
198 def text
199 all
200 end
201 self
202 end
203 self
204 end
205 end
206 class MdMake < SiSU_Param_Make::MdMake
207 end
208 class Md
209 def initialize(str,opt,env)
210 @s,@opt,@env=str,opt,env
211 end
212 def validate_length(s,l,n)
213 #s=(s.length <= l) ? s : nil
214 s=if s.is_a?(String) \
215 and s.length <= l
216 s
217 elsif s.is_a?(NilClass)
218 nil
219 elsif s.class !=String
220 STDERR.puts "#{n} is #{s.class}: programming error, String expected #{__FILE__}:#{__LINE__}"
221 s
222 else
223 SiSU_Screen::Ansi.new(
224 'v',
225 "*WARN* #{n} length #{s.length} exceeds set db field length #{l}, metadata dropped",
226 @opt.fns
227 ).warn unless @opt.act[:quiet][:set]==:on
228 nil
229 end
230 end
231 def name_format(name)
232 if name
233 name=name.strip
234 @name_a_h=[]
235 authors=name.scan(/[^;]+/)
236 authors.each_with_index do |a,i|
237 b=((a =~/\s*\|\s*/) ? (a.split(/\|/)) : [a])
238 if b[0] =~/"(.+?)"/
239 @name_a_h << { the: $1 }
240 else
241 x=b[0].scan(/[^,]+/)
242 if x.length==1
243 @name_a_h << { the: x[0].strip }
244 elsif x.length==2
245 @name_a_h << { the: x[0].strip, others: x[1].strip }
246 else #p x.length
247 end
248 end
249 b.delete_at(0)
250 b.each do |d|
251 k,c=nil
252 k,c=/^(\S+)\s+(.*)/.match(d)[1,2] if d
253 @name_a_h[i][:hon]=c.strip if k=='hon'
254 @name_a_h[i][:affiliation]=c.strip if k=='affiliation'
255 @name_a_h[i][:nationality]=c.strip if k=='nationality'
256 end
257 end
258 l=@name_a_h.length
259 name_str=''
260 @name_a_h.each_with_index do |a,i|
261 name_str += if a[:others]
262 z=(((l - i) > 1) ? ', ' : '')
263 "#{a[:others].strip} #{a[:the].strip}" + z
264 else
265 z=(((l - i) > 2) ? ', ' : '')
266 "#{a[:the].strip}" + z
267 end
268 end
269 { name_a_h: @name_a_h, name_str: name_str }
270 else nil
271 end
272 end
273 def build_hash(arr)
274 @h={}
275 arr.each_with_index do |x,i|
276 a,b=nil,nil
277 if x =~/^%\s/ #ignore comment
278 elsif x =~/:(\S+?):\s+(.+)/
279 a,b=/:(\S+?):\s+(.+)\Z/m.match(x)[1,2]
280 b=b.gsub(/\s*<br(?: \/)?>\s*/,' \\\\\\ ')
281 b=if b =~/\n/m
282 (b =~/;\n/m) \
283 ? (b.split(/;\s*\n\s*/).join(';'))
284 : (b.split(/\s*\n\s*/).join(' '))
285 else
286 b
287 end
288 elsif i == 0
289 a='main'
290 b=x
291 else
292 end
293 @h[a]=b
294 end
295 @h
296 end
297 def title
298 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
299 @h=build_hash(a)
300 def main
301 s=@h['main']
302 l,n=Db[:col_title_part],'title.main'
303 validate_length(s,l,n)
304 end
305 def sub
306 s=@h['subtitle']
307 l,n=Db[:col_title_part],'title.subtitle'
308 validate_length(s,l,n)
309 end
310 def edition
311 s=@h['edition']
312 l,n=Db[:col_title_edition],'title.edition'
313 validate_length(s,l,n)
314 end
315 def note
316 s=@h['note']
317 l,n=Db[:col_info_note],'title.note'
318 validate_length(s,l,n)
319 end
320 def short
321 s=@h['short'] \
322 ? @h['short']
323 : @h['main']
324 l,n=Db[:col_title_part],'title.short'
325 validate_length(s,l,n)
326 end
327 def full
328 s=@h['subtitle'] \
329 ? (@h['main'] + ' - ' + @h['subtitle'])
330 : @h['main']
331 l,n=Db[:col_title],'title.full'
332 validate_length(s,l,n)
333 end
334 def language
335 s=@h['language']
336 l,n=Db[:col_language],'title.language'
337 validate_length(s,l,n)
338 end
339 def language_char # look into, this must be set, from 1 directory stub (.fi), 2 filename (~fi), [3 (not used) document header (@title:\n :language_char: fi)]
340 s=@h['language_char']
341 l,n=Db[:col_language_char],'title.language_char'
342 validate_length(s,l,n)
343 end
344 self
345 end
346 def creator #there are sub categories that need to be catered for and sometimes more than one author etc.; implement array.to_s.length validation test later, current test on string approximate as string is not used
347 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
348 @h=build_hash(a)
349 def author
350 @h['author']=(@h['author'] \
351 ? @h['author']
352 : @h['main'])
353 names=name_format(@h['author'])
354 s=names[:name_str]
355 l,n=Db[:col_name],'creator.author'
356 validate_length(s,l,n)
357 end
358 def author_detail
359 s=@h['author'] \
360 ? @h['author']
361 : @h['main']
362 names=name_format(s)
363 names[:name_a_h]
364 end
365 def editor
366 names=@h['editor'] \
367 ? name_format(@h['editor'])
368 : nil
369 s=(names.is_a?(Hash)) \
370 ? names[:name_str]
371 : nil
372 s=if s
373 l,n=Db[:col_name],'creator.editor'
374 validate_length(s,l,n)
375 else nil
376 end
377 end
378 def editor_detail
379 names=@h['editor'] \
380 ? name_format(@h['editor'])
381 : nil
382 (names.is_a?(Hash)) \
383 ? names[:name_a_h]
384 : nil
385 end
386 def contributor
387 names=@h['contributor'] \
388 ? name_format(@h['contributor'])
389 : nil
390 s=(names.is_a?(Hash)) \
391 ? names[:name_str]
392 : nil
393 s=if s
394 l,n=Db[:col_name],'creator.author'
395 validate_length(s,l,n)
396 else nil
397 end
398 end
399 def contributor_detail
400 names=@h['contributor'] \
401 ? name_format(@h['contributor'])
402 : nil
403 (names.is_a?(Hash)) \
404 ? names[:name_a_h]
405 : nil
406 end
407 def illustrator
408 names=@h['illustrator'] \
409 ? name_format(@h['illustrator'])
410 : nil
411 s=(names.is_a?(Hash)) \
412 ? names[:name_str]
413 : nil
414 s=if s
415 l,n=Db[:col_name],'creator.illustrator'
416 validate_length(s,l,n)
417 else nil
418 end
419 end
420 def illustrator_detail
421 names=@h['illustrator'] \
422 ? name_format(@h['illustrator'])
423 : nil
424 (names.is_a?(Hash)) \
425 ? names[:name_a_h]
426 : nil
427 end
428 def photographer
429 names=@h['photographer'] \
430 ? name_format(@h['photographer'])
431 : nil
432 s=(names.is_a?(Hash)) \
433 ? names[:name_str]
434 : nil
435 s=if s
436 l,n=Db[:col_name],'creator.photographer'
437 validate_length(s,l,n)
438 else nil
439 end
440 end
441 def photographer_detail
442 names=@h['photographer'] \
443 ? name_format(@h['photographer'])
444 : nil
445 (names.is_a?(Hash)) \
446 ? names[:name_a_h]
447 : nil
448 end
449 def translator
450 names=@h['translator'] \
451 ? name_format(@h['translator'])
452 : nil
453 s=(names.is_a?(Hash)) \
454 ? names[:name_str]
455 : nil
456 s=if s
457 l,n=Db[:col_name],'creator.translator'
458 validate_length(s,l,n)
459 else nil
460 end
461 end
462 def translator_detail
463 names=@h['translator'] \
464 ? name_format(@h['translator'])
465 : nil
466 (names.is_a?(Hash)) \
467 ? names[:name_a_h]
468 : nil
469 end
470 def audio
471 names=@h['audio'] \
472 ? name_format(@h['audio'])
473 : nil
474 s=(names.is_a?(Hash)) \
475 ? names[:name_str]
476 : nil
477 s=if s
478 l,n=Db[:col_name],'creator.audio'
479 validate_length(s,l,n)
480 else nil
481 end
482 end
483 def audio_detail
484 names=@h['audio'] \
485 ? name_format(@h['audio'])
486 : nil
487 (names.is_a?(Hash)) \
488 ? names[:name_a_h]
489 : nil
490 end
491 def digitized_by
492 names=@h['digitized_by'] \
493 ? name_format(@h['digitized_by'])
494 : nil
495 s=(names.is_a?(Hash)) \
496 ? names[:name_str]
497 : nil
498 s=if s
499 l,n=Db[:col_name],'creator.digitized_by'
500 validate_length(s,l,n)
501 else nil
502 end
503 end
504 def digitized_by_detail
505 names=@h['digitized_by'] \
506 ? name_format(@h['digitized_by'])
507 : nil
508 (names.is_a?(Hash)) \
509 ? names[:name_a_h]
510 : nil
511 end
512 def prepared_by
513 names=@h['prepared_by'] \
514 ? name_format(@h['prepared_by'])
515 : nil
516 s=(names.is_a?(Hash)) \
517 ? names[:name_str]
518 : nil
519 s=if s
520 l,n=Db[:col_name],'creator.prepared_by'
521 validate_length(s,l,n)
522 else nil
523 end
524 end
525 def prepared_by_detail
526 names=@h['prepared_by'] \
527 ? name_format(@h['prepared_by'])
528 : nil
529 names=name_format(@h['prepared_by'])
530 (names.is_a?(Hash)) \
531 ? names[:name_a_h]
532 : nil
533 end
534 self
535 end
536 def rights
537 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
538 @h=build_hash(a)
539 def copyright
540 def text #you may wish to expand to take from all
541 s=if @h['copyright'] then @h['copyright']
542 elsif @h['text'] then @h['text']
543 elsif @h['main'] then @h['main']
544 else
545 SiSU_Screen::Ansi.new(
546 @opt.act[:color_state][:set],
547 'WARNING Document Copyright missing; provide @rights: :copyright:'
548 ).warn unless @opt.act[:quiet][:set]==:on
549 ''
550 end
551 l,n=Db[:col_info_note],'rights.copyright.text'
552 validate_length(s,l,n)
553 end
554 def translation
555 s=@h['translation'] \
556 ? @h['translation']
557 : nil
558 l,n=Db[:col_info_note],'rights.copyright.translation'
559 validate_length(s,l,n)
560 end
561 def illustrations
562 s=@h['illustrations'] \
563 ? @h['illustrations']
564 : nil
565 l,n=Db[:col_info_note],'rights.copyright.illustrations'
566 validate_length(s,l,n)
567 end
568 def photographs
569 s=@h['photographs'] \
570 ? @h['photographs']
571 : nil
572 l,n=Db[:col_info_note],'rights.copyright.photographs'
573 validate_length(s,l,n)
574 end
575 def digitization
576 s=@h['digitization'] \
577 ? @h['digitization']
578 : nil
579 l,n=Db[:col_info_note],'rights.copyright.digitization'
580 validate_length(s,l,n)
581 end
582 def audio
583 s=@h['audio'] \
584 ? @h['audio']
585 : nil
586 l,n=Db[:col_info_note],'rights.copyright.audio'
587 validate_length(s,l,n)
588 end
589 self
590 end
591 def license
592 s=@h['license'] \
593 ? @h['license']
594 : nil
595 l,n=Db[:col_info_note],'rights.license'
596 validate_length(s,l,n)
597 end
598 def sep(str)
599 ' \\\\ '
600 end
601 def copyright_and_license
602 s=if @h['copyright_and_license'] then @h['copyright_and_license']
603 else
604 s=''
605 if defined? copyright.text \
606 and copyright.text \
607 and not copyright.text.empty?
608 v=sep(copyright.text)
609 s +=copyright.text + v
610 end
611 if defined? copyright.license \
612 and copyright.license \
613 and not copyright.license.empty?
614 s +=copyright.license
615 end
616 if s.empty?
617 SiSU_Screen::Ansi.new(
618 @opt.act[:color_state][:set],
619 'WARNING Document Rights information missing; provide @rights: :copyright:'
620 ).warn unless @opt.act[:quiet][:set]==:on
621 else
622 l,n=Db[:col_info_note],'rights.all'
623 validate_length(s,l,n)
624 end
625 s=s.gsub(/ [\\]+\s+$/,'')
626 end
627 s
628 end
629 def all
630 s=if @h['all'] then @h['all']
631 else
632 s=''
633 if defined? copyright.text \
634 and copyright.text \
635 and not copyright.text.empty?
636 v=sep(copyright.text)
637 s +='Copyright: ' + copyright.text + v
638 end
639 if defined? copyright.translation \
640 and copyright.translation \
641 and not copyright.translation.empty?
642 v=sep(copyright.translation)
643 s +='translation: ' + copyright.translation + v
644 end
645 if defined? copyright.illustrations \
646 and copyright.illustrations \
647 and not copyright.illustrations.empty?
648 v=sep(copyright.illustrations)
649 s +='illustrations: ' + copyright.illustrations + v
650 end
651 if defined? copyright.photographs \
652 and copyright.photographs \
653 and not copyright.photographs.empty?
654 v=sep(copyright.photographs)
655 s +='photographs: ' + copyright.photographs + v
656 end
657 if defined? copyright.digitization \
658 and copyright.digitization \
659 and not copyright.digitization.empty?
660 v=sep(copyright.digitization)
661 s +='digitization: ' + copyright.digitization + v
662 end
663 if defined? copyright.audio \
664 and copyright.audio \
665 and not copyright.audio.empty?
666 v=sep(copyright.audio)
667 s +='audio: ' + copyright.audio + v
668 end
669 if defined? copyright.license \
670 and copyright.license \
671 and not copyright.license.empty?
672 s +='License: ' + copyright.license
673 end
674 if s.empty?
675 SiSU_Screen::Ansi.new(
676 @opt.act[:color_state][:set],
677 'WARNING Document Rights information missing; provide @rights: :copyright:'
678 ).warn unless @opt.act[:quiet][:set]==:on
679 else
680 l,n=Db[:col_info_note],'rights.all'
681 validate_length(s,l,n)
682 end
683 s=s.gsub(/ [\\]+\s+$/,'')
684 end
685 s
686 end
687 self
688 end
689 def identifier
690 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
691 @h=build_hash(a)
692 def oclc
693 s=@h['oclc']
694 l,n=Db[:col_library],'identifier.oclc'
695 validate_length(s,l,n)
696 end
697 def isbn
698 s=@h['isbn']
699 l,n=Db[:col_small],'identifier.isbn'
700 validate_length(s,l,n)
701 end
702 def pg
703 s=@h['pg']
704 l,n=Db[:col_small],'identifier.pg'
705 validate_length(s,l,n)
706 end
707 self
708 end
709 def classify
710 a=@s.split(/(\n%\s.+?$|[ ]*)(?:\n[ ]*(?=:)|\Z)/m)
711 @h=build_hash(a)
712 def topic_register
713 s=@h['topic_register']
714 l,n=Db[:col_info_note],'classify.topic_register'
715 validate_length(s,l,n)
716 end
717 def subject
718 s=@h['subject']
719 l,n=Db[:col_txt_long],'classify.subject'
720 validate_length(s,l,n)
721 end
722 def keywords
723 s=@h['keywords']
724 l,n=Db[:col_txt_long],'classify.keywords'
725 validate_length(s,l,n)
726 end
727 def loc
728 s=@h['loc']
729 l,n=Db[:col_library],'classify.loc'
730 validate_length(s,l,n)
731 end
732 def dewey
733 s=@h['dewey']
734 l,n=Db[:col_library],'classify.dewey'
735 validate_length(s,l,n)
736 end
737 self
738 end
739 def publisher
740 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
741 @h=build_hash(a)
742 s=@h['main']
743 l,n=Db[:col_name],'publisher'
744 validate_length(s,l,n)
745 end
746 def date
747 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
748 @h=build_hash(a)
749 def added_to_site
750 s=@h['added_to_site']
751 l,n=Db[:col_date_text],'date.added_to_site'
752 validate_length(s,l,n)
753 end
754 def available
755 s=@h['available']
756 l,n=Db[:col_date_text],'date.available'
757 validate_length(s,l,n)
758 end
759 def created
760 s=@h['created']
761 l,n=Db[:col_date_text],'date.created'
762 validate_length(s,l,n)
763 end
764 def issued
765 s=@h['issued']
766 l,n=Db[:col_date_text],'date.issued'
767 validate_length(s,l,n)
768 end
769 def modified
770 s=@h['modified']
771 l,n=Db[:col_date_text],'date.modified'
772 validate_length(s,l,n)
773 end
774 def published
775 s=@h['published']=(@h['published'] ? @h['published'] : @h['main'])
776 l,n=Db[:col_date_text],'date.published'
777 validate_length(s,l,n)
778 end
779 def valid
780 s=@h['valid']
781 l,n=Db[:col_date_text],'date.valid'
782 validate_length(s,l,n)
783 end
784 self
785 end
786 #def language # as things stand this should really be populated from title.language and original.language, resolve
787 # a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
788 # @h=build_hash(a)
789 # def document
790 # s=@h['document']=(@h['document'] ? @h['document'] : @h['main'])
791 # l,n=Db[:col_language],'language.document'
792 # validate_length(s,l,n)
793 # end
794 # def document_char
795 # s=@h['document_char']=(@h['document_char'] ? @h['document_char'] : nil)
796 # l,n=Db[:col_language_char],'language.document_char'
797 # validate_length(s,l,n)
798 # end
799 # def original
800 # s=@h['original']
801 # l,n=Db[:col_language],'language.original'
802 # validate_length(s,l,n)
803 # end
804 # def original_char
805 # s=@h['original_char']
806 # l,n=Db[:col_language_char],'language.original_char'
807 # validate_length(s,l,n)
808 # end
809 # self
810 #end
811 def current_publisher
812 @s
813 end
814 def original
815 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
816 @h=build_hash(a)
817 def publisher
818 s=@h['publisher']
819 l,n=Db[:col_name],'original.publisher'
820 validate_length(s,l,n)
821 end
822 def language
823 s=@h['language']
824 l,n=Db[:col_language],'original.language'
825 validate_length(s,l,n)
826 end
827 def language_char
828 s=@h['language_char']
829 l,n=Db[:col_language_char],'original.language_char'
830 validate_length(s,l,n)
831 end
832 def source
833 s=@h['source']
834 l,n=Db[:col_name],'original.source'
835 validate_length(s,l,n)
836 end
837 def institution
838 s=@h['institution']
839 l,n=Db[:col_name],'original.institution'
840 validate_length(s,l,n)
841 end
842 def nationality
843 s=@h['nationality']
844 l,n=Db[:col_language],'original.nationality'
845 validate_length(s,l,n)
846 end
847 self
848 end
849 def notes
850 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
851 @h=build_hash(a)
852 def description
853 s=@h['description']
854 l,n=Db[:col_info_note],'notes.description'
855 validate_length(s,l,n)
856 end
857 def abstract
858 s=@h['abstract']
859 l,n=Db[:col_info_note],'notes.abstract'
860 validate_length(s,l,n)
861 end
862 def comment
863 s=@h['comment']
864 l,n=Db[:col_info_note],'notes.comment'
865 validate_length(s,l,n)
866 end
867 def coverage
868 s=@h['coverage']
869 l,n=Db[:col_info_note],'notes.coverage'
870 validate_length(s,l,n)
871 end
872 def relation
873 s=@h['relation']
874 l,n=Db[:col_info_note],'notes.relation'
875 validate_length(s,l,n)
876 end
877 def source
878 s=@h['source']
879 l,n=Db[:col_txt_long],'notes.source'
880 validate_length(s,l,n)
881 end
882 def history
883 s=@h['history']
884 l,n=Db[:col_txt_long],'notes.history'
885 validate_length(s,l,n)
886 end
887 def type
888 s=@h['type']
889 l,n=Db[:col_txt_long],'notes.relation'
890 validate_length(s,l,n)
891 end
892 def format
893 s=@h['format']
894 l,n=Db[:col_txt_short],'notes.format'
895 validate_length(s,l,n)
896 end
897 def prefix
898 @h['prefix']
899 end
900 self
901 end
902 end
903 class Instructions
904 @doc={ lv: [] }
905 @doc[:fns],@doc[:fnb],@doc[:scr_suffix]='','',''
906 @@publisher='SiSU scribe'
907 attr_accessor :make,:env,:path,:file,:fn,:fns,:fno,:fnb,:fnn,:fnt,:fnl,:flv,:fnz,:fnstex,:ocn,:sfx_src,:pdf,:file_type,:dir_out,:dir_tex,:dir_lout,:txt_path,:sisu,:project_details,:ruby_version,:title,:subtitle,:full_title,:html_title,:subtitle_tex,:creator,:classify,:author_home,:author,:author_title,:author_nationality,:authors,:authorship,:translator,:illustrator,:prepared_by,:digitized_by,:subject,:description,:publisher,:current_publisher,:contributor,:date,:date_created,:date_issued,:date_available,:date_valid,:date_modified,:date_translated,:date_added_to_site,:date_scheme,:date_created_scheme,:date_issued_scheme,:date_available_scheme,:date_valid_scheme,:date_modified_scheme,:type,:format,:identifier,:source,:language,:language_original,:relation,:coverage,:rights,:keywords,:comments,:abstract,:cls_loc,:cls_dewey,:cls_pg,:cls_isbn,:papersize,:papersize_array,:toc,:lv0,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:lvs,:pagenew,:pagebreak,:pageline,:num_top,:bold_match_list,:italics_match_list,:substitution_match_list,:emphasis_set_to,:toc_lev_limit,:flag_endnotes,:flag_auto_endnotes,:flag_separate_endnotes,:flag_separate_endnotes_make,:markup,:markup_instruction,:flag_tables,:vocabulary,:doc_css,:yaml,:lnk,:links,:prefix_a,:prefix_b,:suffix,:information,:contact,:icon,:image,:ad_url,:ad_png,:ad_alt,:ad_began,:flag_promo,:promo,:ad_home,:stmp,:stmpd,:sc_filename,:sc_number,:sc_date,:sc_time,:sc_info,:yamladdr,:locale,:wc_lines,:wc_words,:wc_bytes,:file_encoding,:filesize,:user,:home,:hostname,:pwd,:firstseg,:programs,:author_copymark,:i18n,:lang,:lang_code_insert,:en,:notes,:dgst,:generated,:tags,:tag_array,:concord_make,:seg_names,:seg_autoname_safe,:set_header_title,:set_heading_top,:set_heading_seg,:heading_seg_first,:heading_seg_first_flag,:base_program,:ec,:opt,:sem_tag,:book_idx,:topic_register,:topic_register_array,:original,:writing_focus,:audio,:daisy,:home_button_image,:home_button_links,:footer_links,:cover_image,:man_section
908 def initialize(fns_array,opt)
909 @env=@path,@file=@fn=@fns=@fno=@fnb=@fnn=@fnt=@fnl=@flv=@fnz=@fnstex=@ocn=@sfx_src=@pdf=@file_type=@dir_out=@dir_tex=@dir_lout=@txt_path=@make=@flag_endnotes=@flag_auto_endnotes=@flag_separate_endnotes=@flag_separate_endnotes_make=@sisu=@project_details=@ruby_version=@title=@subtitle=@full_title=@html_title=@subtitle_tex=@creator=@classify=@author_home=@author=@author_title=@author_nationality=@translator=@illustrator=@prepared_by=@digitized_by=@subject=@description=@publisher=@current_publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@date_translated=@date_added_to_site=@date_scheme=@date_created_scheme=@date_issued_scheme=@date_available_scheme=@date_valid_scheme=@date_modified_scheme=@type=@format=@identifier=@source=@language=@language_original=@relation=@coverage=@rights=@keywords=@comments=@abstract=@cls_loc=@cls_dewey=@cls_pg=@cls_isbn=@papersize=@toc=@lv0=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@pagenew=@pagebreak=@pageline=@num_top=@bold_match_list=@italics_match_list=@substitution_match_list=@emphasis_set_to=@toc_lev_limit=@flag_tables=@vocabulary=@doc_css=@yaml=@lnk=@links=@prefix_a=@prefix_b=@suffix=@information=@contact=@icon=@ad_url=@ad_png=@ad_alt=@ad_began=@promo=@ad_home=@stmp=@stmpd=@sc_filename=@sc_number=@sc_date=@sc_time=@sc_info=@yamladdr=@locale=@wc_lines=@wc_words=@wc_bytes=@file_encoding=@filesize=@firstseg=@programs=@author_copymark=@i18n=@lang=@lang_code_insert=@en=@notes=@dgst=@generated=@heading_seg_first=@base_program=@topic_register=@original=@writing_focus=@audio=@home_button_image=@home_button_links=@cover_image=@man_section=nil
910 @data, @path, @fns, @fno, @opt=
911 fns_array,opt.pth,opt.fns,opt.fno,opt #@data used as data
912 @flag_tables,@set_header_title,@set_heading_top,@set_heading_seg,@heading_seg_first_flag,@flag_promo,@book_idx=
913 false, false, false, false, false, false, false
914 @seg_autoname_safe=true
915 @daisy,@sem_tag=false,false
916 @authorship,@markup_instruction,@image='','','','' #check which other values should be set to empty rather than nil
917 @markup=@markup_instruction #use @markup_instruction
918 @doc,@fn,@make_italic,@tag_hash,@ec={},{},{},{},{},{}
919 @flv,@lang,@seg_names,@tags,@tag_array,@tag_a,@ec[:image],@ec[:audio],@ec[:multimedia]=Array.new(9){[]}
920 @authors,@topic_register_array,@papersize_array=[],[],[]
921 @lvs=[nil,0,0,0,0,0,0]
922 @emphasis_set_to='bold'
923 @lang_code_insert=SiSU_Env::FilenameLanguageCodeInsert.new(@opt).language_code_insert
924 @footer_links= { left: { say: '', url: '' }, center: { say: '', url: '' } }
925 @rgx_image=/(?:^|[^_\\])\{(?:\s*|\~\^\s+)(\S+?\.(?:png|jpg|gif)\b)/m
926 @rgx_audio=/\{\s*(\S+?\.(?:mp3|ogg))/
927 @rgx_mm=/\{\s*(\S+?\.(?:ogg|mpeg))/ #expand and distinguish ogg
928 Dir.chdir(@opt.f_pth[:pth])
929 begin
930 rescue
931 SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@fns).location do
932 __LINE__.to_s + ':' + __FILE__
933 end
934 ensure
935 end
936 @header_make_links_append=:no
937 common_makes=(defined? @opt.make_instructions_pod) \
938 && @opt.make_instructions_pod !=nil \
939 && @opt.make_instructions_pod[:makeset]==true \
940 ? @opt.make_instructions_pod
941 : @opt.make_instructions
942 if common_makes[:makeset]
943 @pagenew=common_makes[:pagenew]
944 @pagebreak=common_makes[:pagebreak]
945 @pageline=common_makes[:pageline]
946 @toc=common_makes[:toc]
947 @lv0=common_makes[:lv0]
948 @lv1=common_makes[:lv1]
949 @lv2=common_makes[:lv2]
950 @lv3=common_makes[:lv3]
951 @lv4=common_makes[:lv4]
952 @lv5=common_makes[:lv5]
953 @lv6=common_makes[:lv6]
954 @num_top=common_makes[:num_top]
955 @i18n=common_makes[:i18n]
956 @man_section=common_makes[:man_section]
957 @emphasis_set_to=common_makes[:emphasis_set_to]
958 @bold_match_list=common_makes[:bold_match_list]
959 @italics_match_list=common_makes[:italics_match_list]
960 @substitution_match_list=common_makes[:substitution_match_list]
961 @footer_links=common_makes[:footer_links]
962 @home_button_links=common_makes[:home_button_links]
963 @home_button_image=common_makes[:home_button_image]
964 @cover_image=common_makes[:cover_image]
965 @lnk=@links=common_makes[:links]
966 @header_make_links_append=common_makes[:links_append]
967 end
968 end
969 #protected
970 def extract
971 begin
972 @user,@home,@hostname,@pwd=ENV['USER'],ENV['HOME'],ENV['HOSTNAME'],ENV['PWD']
973 @programs,@wc,@language,@language_original={},{},{},{}
974 @en={ sum: 0, mark: 0, note: 0, mismatch: 0 }
975 @prog=SiSU_Env::InfoSettings.new
976 @sys=SiSU_Env::SystemCall.new
977 @env=SiSU_Env::InfoEnv.new(@fns) #watch
978 if (@opt.act[:verbose_plus][:set]==:on \
979 || @opt.act[:maintenance][:set]==:on)
980 puts 'system locale: ' + @sys.locale
981 end
982 if @prog.wc \
983 and @sys.wc
984 wc=%x{wc #{fns}}
985 wca=wc.scan(/\d+/)
986 @wc_lines,@wc_words,@wc_bytes=wca[0].to_i,wca[1].to_i,wca[2].to_i
987 else
988 fns_a=@data.dup
989 tmp=fns_a.join
990 fns_a=tmp.scan(/\S+/)
991 @wc_words=fns_a.length
992 fns_a=tmp=nil
993 end
994 @concord_make=(@wc_words > @env.concord_max) ? false : true
995 @locale=@sys.locale
996 @file_encoding=@sys.file_encoding(fns,@opt.act)
997 # programs set here for things that affect output appearance only
998 @programs[:pdf]=SiSU_Env::SystemCall.new.program_found?('pdflatex')
999 if @opt.act[:psql][:set] == [:ok]
1000 m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/ #watch added match for sss
1001 @fnn,@fnb,@fnt=@fns[m,1],@fns[m,2],@fns[m,3]
1002 @flv=@env.document_language_versions_found[:f]
1003 else
1004 m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm)$/ #watch added match for sss
1005 @fnn,@fnb,@fnt=@fns[m,1],@fns[m,2],@fns[m,3]
1006 @flv=@env.document_language_versions_found[:f]
1007 @fnz=(@fns =~/\.(?:ssm\.sst|ssm)$/) ? (@fnn + '.ssm.txz') : (@fnn + '.sst.txz')
1008 end
1009 @papersize=@env.papersize #'A4' #default size #get first from SiSU_Env:: # @env is probably no longer most appropriate name! as default info is more general
1010 @sfx_src=@fns[m,2]
1011 if @fns =~ /(?:-|ssm\.)?sst$/ \
1012 and not @opt.act[:psql][:set] == [:ok]
1013 @env_out_root=@env.path.output
1014 @dir_out="#{@env.path.output}/#{@fnb}"
1015 @dir_tex=@env.processing_path.tex
1016 @dir_lout=@env.processing_path.lout
1017 @@publisher='SiSU http://www.jus.uio.no/sisu'
1018 end
1019 @txt_path=@txt_path ||= @env.path.output
1020 @stmp=%{#{@fns}}[/^(.+?)\..*/m,1]
1021 @fnstex=@fns.gsub(/_/,'\_\-').gsub(/\./,'.\-')
1022 @flag_endnotes,@flag_auto_endnotes,@flag_separate_endnotes=false,false,false
1023 @flag_separate_endnotes_make=true
1024 ver=SiSU_Env::InfoVersion.instance
1025 @project_details=ver.get_version
1026 @ruby_version=ver.rbversion
1027 @generated=Time.now
1028 fns_array=@data.dup
1029 skip unless fns_array # consider
1030 @code_flag=false
1031 fns_array.each do |para| #% scan document
1032 if para !~/^%+\s/ \
1033 and para =~/<![abcdeghijklmnopqrstuvwxyz]/i # <!f not included
1034 raise "Old markup style in file #{@fns}, current version #{@project_details.project} #{@project_details.version} #{@project_details.date_stamp} #{@project_details.date}:\n\t\t#{para}\n\n"
1035 end
1036 @code_flag=case para
1037 when /^code\{\s*$/ then true
1038 when /^\}code\s*$/ then false
1039 else @code_flag
1040 end
1041 regx_header=/^@\S+?:[+-]?\s/
1042 if para =~regx_header \
1043 and not @code_flag #or para=~/^(?:1|:?A)~/
1044 case para
1045 when /^@title:(.+)/m #% * header metadata - title
1046 @title=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).title
1047 when /^@creator:(.+)/m #% * header metadata - creator
1048 @creator=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).creator
1049 @authorship=@author=@creator.author
1050 @authors=@creator.author_detail
1051 when /^@date:(.+)/m #% * header metadata - date
1052 @date=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).date
1053 when /^@publisher:\s+(.+)/m #% * header metadata - publisher
1054 @publisher=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).current_publisher
1055 @current_publisher=@publisher
1056 when /^@rights:(.+)/m #% * header metadata - rights
1057 @rights=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).rights
1058 when /^@classify:(.+)/m #% * header metadata - classify
1059 @classify=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).classify
1060 when /^@identifier:(.+)/m #% * header metadata - identifier
1061 @identifier=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).identifier
1062 when /^@original:(.+)/m #% * header metadata - original (document)
1063 @original=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).original
1064 @source=@original.source
1065 when /^@notes?:\s(.+)\Z/m #% * header metadata - notes
1066 @notes=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).notes
1067 when /^@links:\s+(.+?)\Z/m #% * header metadata - links
1068 links=SiSU_Param::Parameters::MdMake.new($1.strip,@opt,@env).make_links.links
1069 @lnk=@links=if @header_make_links_append == :yes
1070 (links) \
1071 ? (links + @links)
1072 : @links
1073 else
1074 (links) \
1075 ? (links)
1076 : @links
1077 end
1078 when /^@make:(.+)/m #% * header processing - make
1079 @make=SiSU_Param::Parameters::MdMake.new($1.strip,@opt,@env).make
1080 makes=SiSU_Param_Make::MakeHead.new(@make).make_instruct
1081 @pagenew=(makes[:pagenew]) \
1082 ? (makes[:pagenew]) \
1083 : @pagenew
1084 @pagebreak=(makes[:pagebreak]) \
1085 ? (makes[:pagebreak]) \
1086 : @pagebreak
1087 @pageline=(makes[:pageline]) \
1088 ? (makes[:pageline]) \
1089 : @pageline
1090 @toc=(makes[:toc]) ? (makes[:toc]) : @toc
1091 @lv0=(makes[:lv0]) ? (makes[:lv0]) : @lv0
1092 @lv1=(makes[:lv1]) ? (makes[:lv1]) : @lv1
1093 @lv2=(makes[:lv2]) ? (makes[:lv2]) : @lv2
1094 @lv3=(makes[:lv3]) ? (makes[:lv3]) : @lv3
1095 @lv4=(makes[:lv4]) ? (makes[:lv4]) : @lv4
1096 @lv5=(makes[:lv5]) ? (makes[:lv5]) : @lv5
1097 @lv6=(makes[:lv6]) ? (makes[:lv6]) : @lv6
1098 @num_top=
1099 (makes[:num_top]) \
1100 ? (makes[:num_top]) \
1101 : @num_top
1102 @substitution_match_list=
1103 (makes[:substitution_match_list]) \
1104 ? (makes[:substitution_match_list]) \
1105 : @substitution_match_list
1106 @bold_match_list=
1107 (makes[:bold_match_list]) \
1108 ? (makes[:bold_match_list]) \
1109 : @bold_match_list
1110 @italics_match_list=
1111 (makes[:italics_match_list]) \
1112 ? (makes[:italics_match_list]) \
1113 : @italics_match_list
1114 @emphasis_set_to=
1115 (makes[:emphasis_set_to]) \
1116 ? (makes[:emphasis_set_to]) \
1117 : @emphasis_set_to
1118 @i18n=
1119 (makes[:i18n]) \
1120 ? (makes[:i18n]) \
1121 : @i18n
1122 @man_section=
1123 (makes[:man_section]) \
1124 ? (makes[:man_section]) \
1125 : @man_section
1126 @footer_links=
1127 (makes[:footer_links]) \
1128 ? (makes[:footer_links]) \
1129 : @footer_links
1130 @home_button_links=
1131 (makes[:home_button_links]) \
1132 ? (makes[:home_button_links]) \
1133 : @home_button_links
1134 @home_button_image=
1135 (makes[:home_button_image]) \
1136 ? (makes[:home_button_image]) \
1137 : @home_button_image
1138 @cover_image=
1139 (makes[:cover_image]) \
1140 ? (makes[:cover_image]) \
1141 : @cover_image
1142 end
1143 @lv0 ||=/^0~/
1144 @lv1 ||=/^1~/
1145 @lv2 ||=/^2~/
1146 @lv3 ||=/^3~/
1147 @lv4 ||=/^4~/
1148 @lv5 ||=/^5~/
1149 @lv6 ||=/^6~/
1150 else #% *
1151 l_0=l_1=l_2=l_3=l_4=l_5=''
1152 if defined? @make.headings[0]
1153 l_0=if defined? @make.headings[0][0] \
1154 and @make.headings[0][0] =~/\S+/
1155 "|^#{@make.headings[0][0]}"
1156 end
1157 l_1=if defined? @make.headings[0][1] \
1158 and @make.headings[0][1] =~/\S+/
1159 "|^#{@make.headings[0][1]}"
1160 end
1161 l_2=if defined? @make.headings[0][2] \
1162 and @make.headings[0][2] =~/\S+/
1163 "|^#{@make.headings[0][2]}"
1164 end
1165 l_3=if defined? @make.headings[0][3] \
1166 and @make.headings[0][3] =~/\S+/
1167 "|^#{@make.headings[0][3]}"
1168 end
1169 l_4=if defined? @make.headings[0][4] \
1170 and @make.headings[0][4] =~/\S+/
1171 "|^#{@make.headings[0][4]}"
1172 end
1173 l_5=if defined? @make.headings[0][5] \
1174 and @make.headings[0][5] =~/\S+/
1175 "|^#{@make.headings[0][5]}"
1176 end
1177 end
1178 case para
1179 #when /^:?A~/
1180 when /^:?B~#{l_0}/
1181 @lvs[1]=1
1182 when /^:?C~#{l_1}/
1183 @lvs[2]=1
1184 when /^:?D~#{l_2}/
1185 @lvs[3]=1
1186 when /^1~#{l_3}/
1187 @lvs[4]=1
1188 when /^2~#{l_4}/
1189 @lvs[5]=1
1190 when /^3~#{l_5}/
1191 @lvs[6]=1
1192 end
1193 if para =~ /^:?A~/ #% processing
1194 if not defined? @title.full.nil?
1195 tf=para[/^:A~\S*(.+)$/m,1]
1196 tf="@title: #{tf}"
1197 @title=SiSU_Param::Parameters::Md.new(tf.strip,@opt,@env).title
1198 end
1199 creator=(@creator.is_a?(SiSU_Param::Parameters::Md) \
1200 && defined? @creator.author \
1201 && @creator.author.is_a?(String)) \
1202 ? " #{@creator.author}"
1203 : ''
1204 title=@title.full.gsub(/\s*(?:<p>|<p \/>|<br>|<br \/>)\s*/,' ').
1205 gsub(/~\{.+?\}~/,'')
1206 SiSU_Screen::Ansi.new(
1207 @opt.act[:color_state][:set],
1208 'Document Parameters',
1209 %{#{title}#{creator}}
1210 ).txt_grey if @opt.act[:verbose][:set]==:on
1211 end
1212 if not @book_idx \
1213 and para =~/^=\{(.+?)\}[\s`]*\Z/m
1214 @book_idx=true
1215 end
1216 unless @code_flag
1217 case para
1218 when /~\{\s+.+?\}~/m #% processing
1219 en=para.scan(/~\{.+?\}~/m)
1220 en.each { |e| @en[:sum] +=1 }
1221 when /~\^(?:\s|$)/m #% processing
1222 mk=para.scan(/~\^(?:\s|$)/)
1223 mk.each { |e| @en[:mark] +=1 }
1224 when /^\^~\s+\S/ then @en[:note] +=1 #% processing
1225 end
1226 end
1227 if para =~/~\{|\^~ |~\^|\{.+?\[[1-6]\]\}\S+?\.ss[tm]/m
1228 @flag_auto_endnotes,@flag_endnotes=true,true
1229 end
1230 if para =~/^(?:table\{|\{table)/i
1231 @flag_tables=true
1232 end
1233 end
1234 if para =~/^:?A~/
1235 @set_heading_top=true
1236 end
1237 if para =~/^1~/
1238 m=nil
1239 if para =~/^1~(\S+)\s+(.+)$/
1240 m,t=$1,$2
1241 elsif para =~/^1~\s+(.+)$/
1242 t=$1
1243 end
1244 unless @heading_seg_first_flag # extract first segment name
1245 @heading_seg_first=t
1246 @heading_seg_first_flag=true
1247 end
1248 if m # list all segment names
1249 @seg_names << m
1250 @set_heading_seg=true
1251 if m=~/^\d{1,3}/ \
1252 and m !~/^0/
1253 @seg_autoname_safe=false
1254 end
1255 end
1256 end
1257 para=para.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image)
1258 if para !~/^%+\s/ \
1259 and para =~@rgx_image
1260 @ec[:image] << para.scan(@rgx_image).uniq
1261 end
1262 @ec[:audio] << para.scan(@rgx_audio).uniq if para =~@rgx_audio #embedded content
1263 @ec[:multimedia] << para.scan(@rgx_mm).uniq if para =~@rgx_mm #embedded content
1264 unless @sem_tag
1265 @sem_tag=true if para=~/[:;]\{.+?\}[:;][a-z+]/ #refix later
1266 end
1267 end #% here endeth the document loop
1268 unless @make
1269 if (@opt.act[:verbose_plus][:set]==:on \
1270 || @opt.act[:maintenance][:set]==:on)
1271 SiSU_Screen::Ansi.new(
1272 @opt.act[:color_state][:set],
1273 '@make:',
1274 'header absent'
1275 ).warn
1276 end
1277 @make=SiSU_Param::Parameters::MdMake.new('@make: ',@opt,@env).make
1278 end
1279 if @cover_image \
1280 and @cover_image.is_a?(Hash) \
1281 and (@cover_image[:cover] =~@rgx_image \
1282 or @cover_image[:cover] =~/\S+?.(?:jpg|png|gif)/)
1283 @ec[:image] << @cover_image[:cover]
1284 end
1285 if @home_button_image \
1286 and @home_button_image.is_a?(Hash) \
1287 and (@home_button_image =~@rgx_image \
1288 or @home_button_image =~/\S+?\.(?:jpg|png|gif)/)
1289 @ec[:image] << @home_button_image
1290 end
1291 if @ec[:image].length > 0
1292 @ec[:image]=@ec[:image].flatten.uniq
1293 @ec[:image].delete_if {|x| x =~/https?:\/\// }
1294 @ec[:image]=@ec[:image].sort
1295 end
1296 @ec[:audio]=@ec[:audio].uniq.flatten.sort
1297 @ec[:multimedia]=@ec[:multimedia].uniq.flatten.sort
1298 unless @rights
1299 if defined? @creator.author \
1300 and @creator.author.is_a?(String) \
1301 and defined? @date.published \
1302 and @date.published.is_a?(String)
1303 @rights=SiSU_Param::Parameters::MdDefault.new.rights(@creator.author,@date.published)
1304 elsif defined? @creator.author \
1305 and @creator.author.is_a?(String)
1306 @rights=SiSU_Param::Parameters::MdDefault.new.rights("[#{@creator.author}]",'')
1307 end
1308 end
1309 if defined? @classify.topic_register \
1310 and @classify.topic_register.is_a?(String) \
1311 and @classify.topic_register.length >3
1312 topic_register=@classify.topic_register
1313 u=topic_register.scan(/[^;]+/m).sort
1314 v=[]
1315 u.each do |l|
1316 v << l.scan(/[^:]+/m)
1317 end
1318 v.each do |s|
1319 s[-1]=s[-1].scan(/[^|]+/m) if s[-1] =~/[|]/m
1320 @topic_register_array << s
1321 end
1322 @topic_register_array
1323 end
1324 if @i18n
1325 @i18n=@i18n.uniq
1326 @i18n << 'en' unless @i18n.find_index("en")
1327 else
1328 @i18n=[ 'en' ]
1329 end
1330 translated=[]
1331 translate_list=[@pagenew,@pagebreak,@pageline,@num_top,@toc_lev_limit]
1332 translate_list.each do |t|
1333 translate=t.to_s if t
1334 translated << if translate
1335 translate.gsub!(/3/,'6')
1336 translate.gsub!(/2/,'5')
1337 translate.gsub!(/1/,'4')
1338 translate.gsub!(/:?C/,'3')
1339 translate.gsub!(/:?B/,'2')
1340 translate.gsub!(/:?A/,'1')
1341 # looks like an ok substituion for the above but is not, causes problems, check why
1342 #translate=translate.gsub(/3/,'6').
1343 # gsub(/2/,'5').
1344 # gsub(/1/,'4').
1345 # gsub(/:?C/,'3').
1346 # gsub(/:?B/,'2').
1347 # gsub(/:?A/,'1')
1348 translate=(translate =~/^\d+$/) \
1349 ? translate.to_i
1350 : translate
1351 else nil
1352 end
1353 end
1354 @pagenew,@pagebreak,@pageline,@num_top,@toc_lev_limit=translated
1355 @markup=@markup.gsub(/page_new\s*=\s*([\dA-C])/,"page_new=#{@pagenew}").
1356 gsub(/page_break\s*=\s*([\dA-C])/,"page_break=#{@pagebreak}").
1357 gsub(/page_line\s*=\s*([\dA-C])/,"page_line=#{@pageline}").
1358 gsub(/num_top\s*=\s*([\dA-C])/,"num_top=#{@num_top}").
1359 gsub(/toc_lev_limit\s*=\s*([\dA-C])/,"toc_lev_limit=#{@toc_lev_limit}")
1360 papersize_array_rc=@papersize.downcase.scan(/(?:a4|letter|legal|book|a5|b5)/)
1361 papersize_array_opt=[
1362 ((@opt.act[:pdf_a4][:set]==:on) ? 'a4' : ''),
1363 ((@opt.act[:pdf_a5][:set]==:on) ? 'a5' : ''),
1364 ((@opt.act[:pdf_b5][:set]==:on) ? 'b5' : ''),
1365 ((@opt.act[:pdf_letter][:set]==:on) ? 'letter' : ''),
1366 ((@opt.act[:pdf_legal][:set]==:on) ? 'legal' : ''),
1367 ] - [""]
1368 @papersize_array=(papersize_array_opt.length > 0) \
1369 ? papersize_array_opt
1370 : papersize_array_rc
1371 fn=@opt.fno #decide what to do a filesize on .ssm tells very little about actual document size
1372 @filesize=(File.size(fn)).to_s
1373 if @sys.openssl !=false \
1374 and FileTest.file?(@env.source_file_with_path)
1375 @dgst=[]
1376 case @env.digest(@opt).type
1377 when :sha512
1378 dgst=@sys.sha512(@env.source_file_with_path)
1379 @dgst=dgst[1].length==128 ? dgst : nil
1380 puts 'check document (sha512) digest' if not @dgst
1381 when :sha256
1382 dgst=@sys.sha256(@env.source_file_with_path)
1383 @dgst=dgst[1].length==64 ? dgst : nil
1384 puts 'check document (sha256) digest' if not @dgst
1385 when :md5
1386 dgst=@sys.md5(@env.source_file_with_path)
1387 @dgst=dgst[1].length==32 ? dgst : nil
1388 puts 'check document (md5) digest' if not @dgst
1389 else
1390 dgst=@sys.sha256(@env.source_file_with_path)
1391 @dgst=dgst[1].length==64 ? dgst : nil
1392 puts 'check document (sha256) digest' if not @dgst
1393 end
1394 elsif not FileTest.file?(@env.source_file_with_path)
1395 #puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia)
1396 end
1397 @publisher ||= "#{@@publisher} (this copy)"
1398 fn_set_lang=SiSU_Env::StandardiseLanguage.new(@opt.lng).language
1399 unless @language[:code] \
1400 and @language[:name]
1401 lang=@env.i18n.language #default language settings for directory by name, or in sysrc.yml
1402 @language[:code] ||= lang.code
1403 @language[:name] ||= lang.title
1404 end
1405 unless fn_set_lang[:d]==true #decide, naming convention overrides other settings, within document, etc.
1406 @language[:code]=fn_set_lang[:c]
1407 @language[:name]=fn_set_lang[:n]
1408 end
1409 @fnl=@env.i18n.lang_filename(fn_set_lang[:c])
1410 @lang=@lang.uniq
1411 @fn=SiSU_Env::EnvCall.new(@fns).lang(fn_set_lang[:c])
1412 if @en[:note] > 0 \
1413 and @en[:sum] > 0
1414 if @en[:sum] > 0
1415 else
1416 SiSU_Screen::Ansi.new(
1417 @opt.act[:color_state][:set],
1418 '*WARN* both endnote styles used',
1419 "~{ #{@en[:sum]} }~ and ^~ #{@en[:mark]}"
1420 ).warn unless @opt.act[:quiet][:set]==:on
1421 end
1422 end
1423 if @en[:mark] != @en[:note] \
1424 and @en[:note] > 0
1425 @en[:mismatch]=@en[:note] - @en[:mark]
1426 SiSU_Screen::Ansi.new(
1427 @opt.act[:color_state][:set],
1428 '*WARN* endnote number mismatch',
1429 "endnotes: #{@en[:note]} != endnote reference marks: #{@en[:mark]} (difference = #{@en[:mismatch]})"
1430 ).warn unless @opt.act[:quiet][:set]==:on
1431 footnote_conversion_errors=File.new("#{Dir.pwd}/footnote_conversion_errors.txt",'a')
1432 footnote_conversion_errors <<
1433 "#{@fns}:\n\tendnotes: #{@en[:note]} != endnote reference marks: #{@en[:mark]} (difference = #{@en[:mismatch]})\n"
1434 end
1435 if not @title \
1436 or not defined? @title.main \
1437 or @title.main !~/[\S]/
1438 if @fns =~/\.ssm$/ \
1439 and @opt.inspect =~/P/
1440 #@title=Md.new('Text Insert',@opt,@env).title
1441 else
1442 SiSU_Screen::Ansi.new(
1443 @opt.act[:color_state][:set],
1444 'WARNING: Document Title missing',
1445 'please provide @title:'
1446 ).warn unless @opt.act[:quiet][:set]==:on
1447 end
1448 end
1449 if @author !~/[\S]/
1450 if @fns =~/\.ssm$/ \
1451 and @opt.inspect =~/P/
1452 #@creator=SiSU_Param::Md.new('Text Insert',@opt,@env).creator
1453 else
1454 SiSU_Screen::Ansi.new(
1455 @opt.act[:color_state][:set],
1456 'WARNING: Document Author missing',
1457 'please provide @creator: :author:'
1458 ).warn unless @opt.act[:quiet][:set]==:on
1459 end
1460 end
1461 @struct={}
1462 doc_struct=Hash.new(0)
1463 if @lv1.nil?
1464 fns_array.each do |para|
1465 if para =~/^(Part|Chapter|Section|Article)\b/i
1466 case para
1467 when /^(Part|PART)\b/
1468 @struct[:part]=doc_struct[:part]
1469 doc_struct[:part]=doc_struct[:part] + 1
1470 when /^(Chapter|CHAPTER)\b/
1471 @struct[:chapter]=doc_struct[:chapter]
1472 doc_struct[:chapter]=doc_struct[:chapter] + 1
1473 when /^(Section|SECTION)\b/
1474 @struct[:section]=doc_struct[:section]
1475 doc_struct[:section]=doc_struct[:section] + 1
1476 when /^(Article|ARTICLE)\b/
1477 @struct[:article]=doc_struct[:article]
1478 doc_struct[:article]=doc_struct[:article] + 1
1479 when /^(Clause|CLAUSE)\b/
1480 @struct[:clause]=doc_struct[:clause]
1481 doc_struct[:clause]=doc_struct[:clause] + 1
1482 when /^\d\..*[^\.]$/
1483 @struct[:number]=doc_struct[:number]
1484 doc_struct[:number]=doc_struct[:number] + 1
1485 end
1486 end
1487 end
1488 if doc_struct[:article] > 2 #%~level 4
1489 @lv4=/^(?:Article|ARTICLE)\b/
1490 elsif doc_struct[:chapter] > 2 \
1491 and doc_struct[:article] \
1492 and doc_struct[:article] < 3
1493 @lv4=/^(?:Chapter|CHAPTER)\b/
1494 elsif doc_struct[:clause] > 2
1495 @lv4=/^(?:Clause|CLAUSE)\b/
1496 elsif doc_struct[:number] > 2
1497 @lv4="^\d\..*[^\.]$"
1498 end
1499 if doc_struct[:section] > 2 #%~level 3
1500 @lv3=/^(?:Section|SECTION)\b/
1501 end
1502 if doc_struct[:chapter] > 2 \
1503 and doc_struct[:article] \
1504 and doc_struct[:article] > 2
1505 @lv2=/^(?:Chapter|CHAPTER)\b/
1506 end
1507 if doc_struct[:part] > 2 \
1508 and @lv[2].nil?
1509 @lv2=/^(?:Part|PART)\b/
1510 end
1511 if doc_struct[:part] > 2 \
1512 and @lv[2].inspect !~/Part/ \
1513 and @lv[1].nil?
1514 @lv1=/^(Part|PART)\b/
1515 end
1516 end
1517 @lnk=@lnk.compact if @lnk
1518 @lv0 ||=/^0~/
1519 @lv1 ||=/^1~/
1520 @lv2 ||=/^2~/
1521 @lv3 ||=/^3~/
1522 @lv4 ||=/^4~/
1523 @lv5 ||=/^5~/
1524 @lv6 ||=/^6~/
1525 @data=nil #else whole file's contents are stored in md pstore & is not required to be... big waste actually
1526 @file=SiSU_Env::FileOp.new(self) #watch
1527 Store.new(self,@env).store #% pstore
1528 self
1529 rescue
1530 if @opt.act[:harvest][:set]==:on
1531 exit
1532 end
1533 end
1534 end
1535 private
1536 class Store
1537 def initialize(md,env)
1538 @md,@env=md,env
1539 end
1540 def store
1541 begin
1542 pstorefile="#{@env.processing_path.ao}/#{@md.fns}.pstore"
1543 File.unlink(pstorefile) if FileTest.file?(pstorefile)
1544 if (@md.opt.act[:verbose_plus][:set]==:on \
1545 || @md.opt.act[:maintenance][:set]==:on)
1546 SiSU_Screen::Ansi.new(
1547 @md.opt.act[:color_state][:set],
1548 "PStore -> #{pstorefile}"
1549 ).txt_grey
1550 end
1551 store=PStore.new(pstorefile)
1552 store.transaction do
1553 store['md']=@md
1554 store.commit
1555 end
1556 @@md=@md=nil
1557 rescue
1558 SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
1559 __LINE__.to_s + ':' + __FILE__
1560 end
1561 ensure
1562 end
1563 end
1564 end
1565 end
1566 end
1567 class Instantiate
1568 def param_instantiate
1569 @@date=SiSU_Env::InfoDate.new
1570 @@proc=
1571 @@filename_txt=
1572 @@filename_texinfo=
1573 @@filename_lout_portrait=
1574 @@filename_lout_landscape=
1575 @@filename_html_scroll=
1576 @@filename_html_index=
1577 @@filename_html_segtoc=
1578 @@filename_semantic=
1579 @@filename_rss=
1580 @@newfile=
1581 @@drr=
1582 nil
1583 @doc={
1584 initialise: nil,
1585 markup: '',
1586 lnks: '',
1587 stmp: '',
1588 prefix_a: '',
1589 prefix_b: '',
1590 req: {}
1591 }
1592 @@yaml=@@yamladdr=nil
1593 @@flag={}
1594 @@publisher='SiSU scribe'
1595 end
1596 end
1597 end
1598 __END__