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