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