c57112de20563addfad5d0e429b1d6607ffe1192
[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 unless @opt.act[:quiet][:set]==:on
544 ''
545 end
546 l,n=Db[:col_info_note],'rights.copyright.text'
547 validate_length(s,l,n)
548 end
549 def translation
550 s=@h['translation'] \
551 ? @h['translation']
552 : nil
553 l,n=Db[:col_info_note],'rights.copyright.translation'
554 validate_length(s,l,n)
555 end
556 def illustrations
557 s=@h['illustrations'] \
558 ? @h['illustrations']
559 : nil
560 l,n=Db[:col_info_note],'rights.copyright.illustrations'
561 validate_length(s,l,n)
562 end
563 def photographs
564 s=@h['photographs'] \
565 ? @h['photographs']
566 : nil
567 l,n=Db[:col_info_note],'rights.copyright.photographs'
568 validate_length(s,l,n)
569 end
570 def digitization
571 s=@h['digitization'] \
572 ? @h['digitization']
573 : nil
574 l,n=Db[:col_info_note],'rights.copyright.digitization'
575 validate_length(s,l,n)
576 end
577 def audio
578 s=@h['audio'] \
579 ? @h['audio']
580 : nil
581 l,n=Db[:col_info_note],'rights.copyright.audio'
582 validate_length(s,l,n)
583 end
584 self
585 end
586 def license
587 s=@h['license'] \
588 ? @h['license']
589 : nil
590 l,n=Db[:col_info_note],'rights.license'
591 validate_length(s,l,n)
592 end
593 def sep(str)
594 ' \\\\ '
595 end
596 def copyright_and_license
597 s=if @h['copyright_and_license'] then @h['copyright_and_license']
598 else
599 s=''
600 if defined? copyright.text \
601 and copyright.text \
602 and not copyright.text.empty?
603 v=sep(copyright.text)
604 s +=copyright.text + v
605 end
606 if defined? copyright.license \
607 and copyright.license \
608 and not copyright.license.empty?
609 s +=copyright.license
610 end
611 if s.empty?
612 SiSU_Screen::Ansi.new(
613 @opt.act[:color_state][:set],
614 'WARNING Document Rights information missing; provide @rights: :copyright:'
615 ).warn unless @opt.act[:quiet][:set]==:on
616 else
617 l,n=Db[:col_info_note],'rights.all'
618 validate_length(s,l,n)
619 end
620 s=s.gsub(/ [\\]+\s+$/,'')
621 end
622 s
623 end
624 def all
625 s=if @h['all'] then @h['all']
626 else
627 s=''
628 if defined? copyright.text \
629 and copyright.text \
630 and not copyright.text.empty?
631 v=sep(copyright.text)
632 s +='Copyright: ' + copyright.text + v
633 end
634 if defined? copyright.translation \
635 and copyright.translation \
636 and not copyright.translation.empty?
637 v=sep(copyright.translation)
638 s +='translation: ' + copyright.translation + v
639 end
640 if defined? copyright.illustrations \
641 and copyright.illustrations \
642 and not copyright.illustrations.empty?
643 v=sep(copyright.illustrations)
644 s +='illustrations: ' + copyright.illustrations + v
645 end
646 if defined? copyright.photographs \
647 and copyright.photographs \
648 and not copyright.photographs.empty?
649 v=sep(copyright.photographs)
650 s +='photographs: ' + copyright.photographs + v
651 end
652 if defined? copyright.digitization \
653 and copyright.digitization \
654 and not copyright.digitization.empty?
655 v=sep(copyright.digitization)
656 s +='digitization: ' + copyright.digitization + v
657 end
658 if defined? copyright.audio \
659 and copyright.audio \
660 and not copyright.audio.empty?
661 v=sep(copyright.audio)
662 s +='audio: ' + copyright.audio + v
663 end
664 if defined? copyright.license \
665 and copyright.license \
666 and not copyright.license.empty?
667 s +='License: ' + copyright.license
668 end
669 if s.empty?
670 SiSU_Screen::Ansi.new(
671 @opt.act[:color_state][:set],
672 'WARNING Document Rights information missing; provide @rights: :copyright:'
673 ).warn unless @opt.act[:quiet][:set]==:on
674 else
675 l,n=Db[:col_info_note],'rights.all'
676 validate_length(s,l,n)
677 end
678 s=s.gsub(/ [\\]+\s+$/,'')
679 end
680 s
681 end
682 self
683 end
684 def identifier
685 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
686 @h=build_hash(a)
687 def oclc
688 s=@h['oclc']
689 l,n=Db[:col_library],'identifier.oclc'
690 validate_length(s,l,n)
691 end
692 def isbn
693 s=@h['isbn']
694 l,n=Db[:col_small],'identifier.isbn'
695 validate_length(s,l,n)
696 end
697 def pg
698 s=@h['pg']
699 l,n=Db[:col_small],'identifier.pg'
700 validate_length(s,l,n)
701 end
702 self
703 end
704 def classify
705 a=@s.split(/(\n%\s.+?$|[ ]*)(?:\n[ ]*(?=:)|\Z)/m)
706 @h=build_hash(a)
707 def topic_register
708 s=@h['topic_register']
709 l,n=Db[:col_info_note],'classify.topic_register'
710 validate_length(s,l,n)
711 end
712 def subject
713 s=@h['subject']
714 l,n=Db[:col_txt_long],'classify.subject'
715 validate_length(s,l,n)
716 end
717 def keywords
718 s=@h['keywords']
719 l,n=Db[:col_txt_long],'classify.keywords'
720 validate_length(s,l,n)
721 end
722 def loc
723 s=@h['loc']
724 l,n=Db[:col_library],'classify.loc'
725 validate_length(s,l,n)
726 end
727 def dewey
728 s=@h['dewey']
729 l,n=Db[:col_library],'classify.dewey'
730 validate_length(s,l,n)
731 end
732 self
733 end
734 def publisher
735 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
736 @h=build_hash(a)
737 s=@h['main']
738 l,n=Db[:col_name],'publisher'
739 validate_length(s,l,n)
740 end
741 def date
742 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
743 @h=build_hash(a)
744 def added_to_site
745 s=@h['added_to_site']
746 l,n=Db[:col_date_text],'date.added_to_site'
747 validate_length(s,l,n)
748 end
749 def available
750 s=@h['available']
751 l,n=Db[:col_date_text],'date.available'
752 validate_length(s,l,n)
753 end
754 def created
755 s=@h['created']
756 l,n=Db[:col_date_text],'date.created'
757 validate_length(s,l,n)
758 end
759 def issued
760 s=@h['issued']
761 l,n=Db[:col_date_text],'date.issued'
762 validate_length(s,l,n)
763 end
764 def modified
765 s=@h['modified']
766 l,n=Db[:col_date_text],'date.modified'
767 validate_length(s,l,n)
768 end
769 def published
770 s=@h['published']=(@h['published'] ? @h['published'] : @h['main'])
771 l,n=Db[:col_date_text],'date.published'
772 validate_length(s,l,n)
773 end
774 def valid
775 s=@h['valid']
776 l,n=Db[:col_date_text],'date.valid'
777 validate_length(s,l,n)
778 end
779 self
780 end
781 #def language # as things stand this should really be populated from title.language and original.language, resolve
782 # a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
783 # @h=build_hash(a)
784 # def document
785 # s=@h['document']=(@h['document'] ? @h['document'] : @h['main'])
786 # l,n=Db[:col_language],'language.document'
787 # validate_length(s,l,n)
788 # end
789 # def document_char
790 # s=@h['document_char']=(@h['document_char'] ? @h['document_char'] : nil)
791 # l,n=Db[:col_language_char],'language.document_char'
792 # validate_length(s,l,n)
793 # end
794 # def original
795 # s=@h['original']
796 # l,n=Db[:col_language],'language.original'
797 # validate_length(s,l,n)
798 # end
799 # def original_char
800 # s=@h['original_char']
801 # l,n=Db[:col_language_char],'language.original_char'
802 # validate_length(s,l,n)
803 # end
804 # self
805 #end
806 def current_publisher
807 @s
808 end
809 def original
810 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
811 @h=build_hash(a)
812 def publisher
813 s=@h['publisher']
814 l,n=Db[:col_name],'original.publisher'
815 validate_length(s,l,n)
816 end
817 def language
818 s=@h['language']
819 l,n=Db[:col_language],'original.language'
820 validate_length(s,l,n)
821 end
822 def language_char
823 s=@h['language_char']
824 l,n=Db[:col_language_char],'original.language_char'
825 validate_length(s,l,n)
826 end
827 def source
828 s=@h['source']
829 l,n=Db[:col_name],'original.source'
830 validate_length(s,l,n)
831 end
832 def institution
833 s=@h['institution']
834 l,n=Db[:col_name],'original.institution'
835 validate_length(s,l,n)
836 end
837 def nationality
838 s=@h['nationality']
839 l,n=Db[:col_language],'original.nationality'
840 validate_length(s,l,n)
841 end
842 self
843 end
844 def notes
845 a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
846 @h=build_hash(a)
847 def description
848 s=@h['description']
849 l,n=Db[:col_info_note],'notes.description'
850 validate_length(s,l,n)
851 end
852 def abstract
853 s=@h['abstract']
854 l,n=Db[:col_info_note],'notes.abstract'
855 validate_length(s,l,n)
856 end
857 def comment
858 s=@h['comment']
859 l,n=Db[:col_info_note],'notes.comment'
860 validate_length(s,l,n)
861 end
862 def coverage
863 s=@h['coverage']
864 l,n=Db[:col_info_note],'notes.coverage'
865 validate_length(s,l,n)
866 end
867 def relation
868 s=@h['relation']
869 l,n=Db[:col_info_note],'notes.relation'
870 validate_length(s,l,n)
871 end
872 def source
873 s=@h['source']
874 l,n=Db[:col_txt_long],'notes.source'
875 validate_length(s,l,n)
876 end
877 def history
878 s=@h['history']
879 l,n=Db[:col_txt_long],'notes.history'
880 validate_length(s,l,n)
881 end
882 def type
883 s=@h['type']
884 l,n=Db[:col_txt_long],'notes.relation'
885 validate_length(s,l,n)
886 end
887 def format
888 s=@h['format']
889 l,n=Db[:col_txt_short],'notes.format'
890 validate_length(s,l,n)
891 end
892 def prefix
893 @h['prefix']
894 end
895 self
896 end
897 end
898 class Instructions
899 @doc={ lv: [] }
900 @doc[:fns],@doc[:fnb],@doc[:scr_suffix]='','',''
901 @@publisher='SiSU scribe'
902 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
903 def initialize(fns_array,opt)
904 @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
905 @data, @path, @fns, @fno, @opt=
906 fns_array,opt.pth,opt.fns,opt.fno,opt #@data used as data
907 @flag_tables,@set_header_title,@set_heading_top,@set_heading_seg,@heading_seg_first_flag,@flag_promo,@book_idx=
908 false, false, false, false, false, false, false
909 @seg_autoname_safe=true
910 @daisy,@sem_tag=false,false
911 @authorship,@markup_instruction,@image='','','','' #check which other values should be set to empty rather than nil
912 @markup=@markup_instruction #use @markup_instruction
913 @doc,@fn,@make_italic,@tag_hash,@ec={},{},{},{},{},{}
914 @flv,@lang,@seg_names,@tags,@tag_array,@tag_a,@ec[:image],@ec[:audio],@ec[:multimedia]=Array.new(9){[]}
915 @authors,@topic_register_array,@papersize_array=[],[],[]
916 @lvs=[nil,0,0,0,0,0,0]
917 @emphasis_set_to='bold'
918 @lang_code_insert=SiSU_Env::FilenameLanguageCodeInsert.new(@opt).language_code_insert
919 @footer_links= { left: { say: '', url: '' }, center: { say: '', url: '' } }
920 @rgx_image=/(?:^|[^_\\])\{(?:\s*|\~\^\s+)(\S+?\.(?:png|jpg|gif)\b)/m
921 @rgx_audio=/\{\s*(\S+?\.(?:mp3|ogg))/
922 @rgx_mm=/\{\s*(\S+?\.(?:ogg|mpeg))/ #expand and distinguish ogg
923 Dir.chdir(@opt.f_pth[:pth])
924 begin
925 rescue
926 SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@fns).location do
927 __LINE__.to_s + ':' + __FILE__
928 end
929 ensure
930 end
931 @header_make_links_append=:no
932 common_makes=(defined? @opt.make_instructions_pod) \
933 && @opt.make_instructions_pod !=nil \
934 && @opt.make_instructions_pod[:makeset]==true \
935 ? @opt.make_instructions_pod
936 : @opt.make_instructions
937 if common_makes[:makeset]
938 @pagenew=common_makes[:pagenew]
939 @pagebreak=common_makes[:pagebreak]
940 @pageline=common_makes[:pageline]
941 @toc=common_makes[:toc]
942 @lv0=common_makes[:lv0]
943 @lv1=common_makes[:lv1]
944 @lv2=common_makes[:lv2]
945 @lv3=common_makes[:lv3]
946 @lv4=common_makes[:lv4]
947 @lv5=common_makes[:lv5]
948 @lv6=common_makes[:lv6]
949 @num_top=common_makes[:num_top]
950 @i18n=common_makes[:i18n]
951 @man_section=common_makes[:man_section]
952 @emphasis_set_to=common_makes[:emphasis_set_to]
953 @bold_match_list=common_makes[:bold_match_list]
954 @italics_match_list=common_makes[:italics_match_list]
955 @substitution_match_list=common_makes[:substitution_match_list]
956 @footer_links=common_makes[:footer_links]
957 @home_button_links=common_makes[:home_button_links]
958 @home_button_image=common_makes[:home_button_image]
959 @cover_image=common_makes[:cover_image]
960 @lnk=@links=common_makes[:links]
961 @header_make_links_append=common_makes[:links_append]
962 end
963 end
964 #protected
965 def extract
966 begin
967 @user,@home,@hostname,@pwd=ENV['USER'],ENV['HOME'],ENV['HOSTNAME'],ENV['PWD']
968 @programs,@wc,@language,@language_original={},{},{},{}
969 @en={ sum: 0, mark: 0, note: 0, mismatch: 0 }
970 @prog=SiSU_Env::InfoSettings.new
971 @sys=SiSU_Env::SystemCall.new
972 @env=SiSU_Env::InfoEnv.new(@fns) #watch
973 if (@opt.act[:verbose_plus][:set]==:on \
974 || @opt.act[:maintenance][:set]==:on)
975 puts 'system locale: ' + @sys.locale
976 end
977 if @prog.wc \
978 and @sys.wc
979 wc=%x{wc #{fns}}
980 wca=wc.scan(/\d+/)
981 @wc_lines,@wc_words,@wc_bytes=wca[0].to_i,wca[1].to_i,wca[2].to_i
982 else
983 fns_a=@data.dup
984 tmp=fns_a.join
985 fns_a=tmp.scan(/\S+/)
986 @wc_words=fns_a.length
987 fns_a=tmp=nil
988 end
989 @concord_make=(@wc_words > @env.concord_max) ? false : true
990 @locale=@sys.locale
991 @file_encoding=@sys.file_encoding(fns,@opt.act)
992 # programs set here for things that affect output appearance only
993 @programs[:pdf]=SiSU_Env::SystemCall.new.program_found?('pdflatex')
994 if @opt.act[:psql][:set] == [:ok]
995 m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/ #watch added match for sss
996 @fnn,@fnb,@fnt=@fns[m,1],@fns[m,2],@fns[m,3]
997 @flv=@env.document_language_versions_found[:f]
998 else
999 m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm)$/ #watch added match for sss
1000 @fnn,@fnb,@fnt=@fns[m,1],@fns[m,2],@fns[m,3]
1001 @flv=@env.document_language_versions_found[:f]
1002 @fnz=(@fns =~/\.(?:ssm\.sst|ssm)$/) ? (@fnn + '.ssm.txz') : (@fnn + '.sst.txz')
1003 end
1004 @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
1005 @sfx_src=@fns[m,2]
1006 if @fns =~ /(?:-|ssm\.)?sst$/ \
1007 and not @opt.act[:psql][:set] == [:ok]
1008 @env_out_root=@env.path.output
1009 @dir_out="#{@env.path.output}/#{@fnb}"
1010 @dir_tex=@env.processing_path.tex
1011 @dir_lout=@env.processing_path.lout
1012 @@publisher='SiSU http://www.jus.uio.no/sisu'
1013 end
1014 @txt_path=@txt_path ||= @env.path.output
1015 @stmp=%{#{@fns}}[/^(.+?)\..*/m,1]
1016 @fnstex=@fns.gsub(/_/,'\_\-').gsub(/\./,'.\-')
1017 @flag_endnotes,@flag_auto_endnotes,@flag_separate_endnotes=false,false,false
1018 @flag_separate_endnotes_make=true
1019 ver=SiSU_Env::InfoVersion.instance
1020 @sisu_version=ver.get_version
1021 @ruby_version=ver.rbversion
1022 @generated=Time.now
1023 fns_array=@data.dup
1024 skip unless fns_array # consider
1025 @code_flag=false
1026 fns_array.each do |para| #% scan document
1027 if para !~/^%+\s/ \
1028 and para =~/<![abcdeghijklmnopqrstuvwxyz]/i # <!f not included
1029 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"
1030 end
1031 @code_flag=case para
1032 when /^code\{\s*$/ then true
1033 when /^\}code\s*$/ then false
1034 else @code_flag
1035 end
1036 regx_header=/^@\S+?:[+-]?\s/
1037 if para =~regx_header \
1038 and not @code_flag #or para=~/^(?:1|:?A)~/
1039 case para
1040 when /^@title:(.+)/m #% * header metadata - title
1041 @title=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).title
1042 when /^@creator:(.+)/m #% * header metadata - creator
1043 @creator=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).creator
1044 @authorship=@author=@creator.author
1045 @authors=@creator.author_detail
1046 when /^@date:(.+)/m #% * header metadata - date
1047 @date=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).date
1048 when /^@publisher:\s+(.+)/m #% * header metadata - publisher
1049 @publisher=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).current_publisher
1050 @current_publisher=@publisher
1051 when /^@rights:(.+)/m #% * header metadata - rights
1052 @rights=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).rights
1053 when /^@classify:(.+)/m #% * header metadata - classify
1054 @classify=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).classify
1055 when /^@identifier:(.+)/m #% * header metadata - identifier
1056 @identifier=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).identifier
1057 when /^@original:(.+)/m #% * header metadata - original (document)
1058 @original=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).original
1059 @source=@original.source
1060 when /^@notes?:\s(.+)\Z/m #% * header metadata - notes
1061 @notes=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).notes
1062 when /^@links:\s+(.+?)\Z/m #% * header metadata - links
1063 links=SiSU_Param::Parameters::MdMake.new($1.strip,@opt,@env).make_links.links
1064 @lnk=@links=if @header_make_links_append == :yes
1065 (links) \
1066 ? (links + @links)
1067 : @links
1068 else
1069 (links) \
1070 ? (links)
1071 : @links
1072 end
1073 when /^@make:(.+)/m #% * header processing - make
1074 @make=SiSU_Param::Parameters::MdMake.new($1.strip,@opt,@env).make
1075 makes=SiSU_Param_Make::MakeHead.new(@make).make_instruct
1076 @pagenew=(makes[:pagenew]) \
1077 ? (makes[:pagenew]) \
1078 : @pagenew
1079 @pagebreak=(makes[:pagebreak]) \
1080 ? (makes[:pagebreak]) \
1081 : @pagebreak
1082 @pageline=(makes[:pageline]) \
1083 ? (makes[:pageline]) \
1084 : @pageline
1085 @toc=(makes[:toc]) ? (makes[:toc]) : @toc
1086 @lv0=(makes[:lv0]) ? (makes[:lv0]) : @lv0
1087 @lv1=(makes[:lv1]) ? (makes[:lv1]) : @lv1
1088 @lv2=(makes[:lv2]) ? (makes[:lv2]) : @lv2
1089 @lv3=(makes[:lv3]) ? (makes[:lv3]) : @lv3
1090 @lv4=(makes[:lv4]) ? (makes[:lv4]) : @lv4
1091 @lv5=(makes[:lv5]) ? (makes[:lv5]) : @lv5
1092 @lv6=(makes[:lv6]) ? (makes[:lv6]) : @lv6
1093 @num_top=
1094 (makes[:num_top]) \
1095 ? (makes[:num_top]) \
1096 : @num_top
1097 @substitution_match_list=
1098 (makes[:substitution_match_list]) \
1099 ? (makes[:substitution_match_list]) \
1100 : @substitution_match_list
1101 @bold_match_list=
1102 (makes[:bold_match_list]) \
1103 ? (makes[:bold_match_list]) \
1104 : @bold_match_list
1105 @italics_match_list=
1106 (makes[:italics_match_list]) \
1107 ? (makes[:italics_match_list]) \
1108 : @italics_match_list
1109 @emphasis_set_to=
1110 (makes[:emphasis_set_to]) \
1111 ? (makes[:emphasis_set_to]) \
1112 : @emphasis_set_to
1113 @i18n=
1114 (makes[:i18n]) \
1115 ? (makes[:i18n]) \
1116 : @i18n
1117 @man_section=
1118 (makes[:man_section]) \
1119 ? (makes[:man_section]) \
1120 : @man_section
1121 @footer_links=
1122 (makes[:footer_links]) \
1123 ? (makes[:footer_links]) \
1124 : @footer_links
1125 @home_button_links=
1126 (makes[:home_button_links]) \
1127 ? (makes[:home_button_links]) \
1128 : @home_button_links
1129 @home_button_image=
1130 (makes[:home_button_image]) \
1131 ? (makes[:home_button_image]) \
1132 : @home_button_image
1133 @cover_image=
1134 (makes[:cover_image]) \
1135 ? (makes[:cover_image]) \
1136 : @cover_image
1137 end
1138 @lv0 ||=/^0~/
1139 @lv1 ||=/^1~/
1140 @lv2 ||=/^2~/
1141 @lv3 ||=/^3~/
1142 @lv4 ||=/^4~/
1143 @lv5 ||=/^5~/
1144 @lv6 ||=/^6~/
1145 else #% *
1146 l_0=l_1=l_2=l_3=l_4=l_5=''
1147 if defined? @make.headings[0]
1148 l_0=if defined? @make.headings[0][0] \
1149 and @make.headings[0][0] =~/\S+/
1150 "|^#{@make.headings[0][0]}"
1151 end
1152 l_1=if defined? @make.headings[0][1] \
1153 and @make.headings[0][1] =~/\S+/
1154 "|^#{@make.headings[0][1]}"
1155 end
1156 l_2=if defined? @make.headings[0][2] \
1157 and @make.headings[0][2] =~/\S+/
1158 "|^#{@make.headings[0][2]}"
1159 end
1160 l_3=if defined? @make.headings[0][3] \
1161 and @make.headings[0][3] =~/\S+/
1162 "|^#{@make.headings[0][3]}"
1163 end
1164 l_4=if defined? @make.headings[0][4] \
1165 and @make.headings[0][4] =~/\S+/
1166 "|^#{@make.headings[0][4]}"
1167 end
1168 l_5=if defined? @make.headings[0][5] \
1169 and @make.headings[0][5] =~/\S+/
1170 "|^#{@make.headings[0][5]}"
1171 end
1172 end
1173 case para
1174 #when /^:?A~/
1175 when /^:?B~#{l_0}/
1176 @lvs[1]=1
1177 when /^:?C~#{l_1}/
1178 @lvs[2]=1
1179 when /^:?D~#{l_2}/
1180 @lvs[3]=1
1181 when /^1~#{l_3}/
1182 @lvs[4]=1
1183 when /^2~#{l_4}/
1184 @lvs[5]=1
1185 when /^3~#{l_5}/
1186 @lvs[6]=1
1187 end
1188 if para =~ /^:?A~/ #% processing
1189 if not defined? @title.full.nil?
1190 tf=para[/^:A~\S*(.+)$/m,1]
1191 tf="@title: #{tf}"
1192 @title=SiSU_Param::Parameters::Md.new(tf.strip,@opt,@env).title
1193 end
1194 creator=(@creator.is_a?(SiSU_Param::Parameters::Md) \
1195 && defined? @creator.author \
1196 && @creator.author.is_a?(String)) \
1197 ? " #{@creator.author}"
1198 : ''
1199 title=@title.full.gsub(/\s*(?:<p>|<p \/>|<br>|<br \/>)\s*/,' ').
1200 gsub(/~\{.+?\}~/,'')
1201 SiSU_Screen::Ansi.new(
1202 @opt.act[:color_state][:set],
1203 'Document Parameters',
1204 %{#{title}#{creator}}
1205 ).txt_grey if @opt.act[:verbose][:set]==:on
1206 end
1207 if not @book_idx \
1208 and para =~/^=\{(.+?)\}[\s`]*\Z/m
1209 @book_idx=true
1210 end
1211 unless @code_flag
1212 case para
1213 when /~\{\s+.+?\}~/m #% processing
1214 en=para.scan(/~\{.+?\}~/m)
1215 en.each { |e| @en[:sum] +=1 }
1216 when /~\^(?:\s|$)/m #% processing
1217 mk=para.scan(/~\^(?:\s|$)/)
1218 mk.each { |e| @en[:mark] +=1 }
1219 when /^\^~\s+\S/ then @en[:note] +=1 #% processing
1220 end
1221 end
1222 if para =~/~\{|\^~ |~\^|\{.+?\[[1-6]\]\}\S+?\.ss[tm]/m
1223 @flag_auto_endnotes,@flag_endnotes=true,true
1224 end
1225 if para =~/^(?:table\{|\{table)/i
1226 @flag_tables=true
1227 end
1228 end
1229 if para =~/^:?A~/
1230 @set_heading_top=true
1231 end
1232 if para =~/^1~/
1233 m=nil
1234 if para =~/^1~(\S+)\s+(.+)$/
1235 m,t=$1,$2
1236 elsif para =~/^1~\s+(.+)$/
1237 t=$1
1238 end
1239 unless @heading_seg_first_flag # extract first segment name
1240 @heading_seg_first=t
1241 @heading_seg_first_flag=true
1242 end
1243 if m # list all segment names
1244 @seg_names << m
1245 @set_heading_seg=true
1246 if m=~/^\d{1,3}/ \
1247 and m !~/^0/
1248 @seg_autoname_safe=false
1249 end
1250 end
1251 end
1252 para=para.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image)
1253 if para !~/^%+\s/ \
1254 and para =~@rgx_image
1255 @ec[:image] << para.scan(@rgx_image).uniq
1256 end
1257 @ec[:audio] << para.scan(@rgx_audio).uniq if para =~@rgx_audio #embedded content
1258 @ec[:multimedia] << para.scan(@rgx_mm).uniq if para =~@rgx_mm #embedded content
1259 unless @sem_tag
1260 @sem_tag=true if para=~/[:;]\{.+?\}[:;][a-z+]/ #refix later
1261 end
1262 end #% here endeth the document loop
1263 unless @make
1264 if (@opt.act[:verbose_plus][:set]==:on \
1265 || @opt.act[:maintenance][:set]==:on)
1266 SiSU_Screen::Ansi.new(
1267 @opt.act[:color_state][:set],
1268 '@make:',
1269 'header absent'
1270 ).warn
1271 end
1272 @make=SiSU_Param::Parameters::MdMake.new('@make: ',@opt,@env).make
1273 end
1274 if @cover_image \
1275 and @cover_image.is_a?(Hash) \
1276 and (@cover_image[:cover] =~@rgx_image \
1277 or @cover_image[:cover] =~/\S+?.(?:jpg|png|gif)/)
1278 @ec[:image] << @cover_image[:cover]
1279 end
1280 if @home_button_image \
1281 and @home_button_image.is_a?(Hash) \
1282 and (@home_button_image =~@rgx_image \
1283 or @home_button_image =~/\S+?\.(?:jpg|png|gif)/)
1284 @ec[:image] << @home_button_image
1285 end
1286 if @ec[:image].length > 0
1287 @ec[:image]=@ec[:image].flatten.uniq
1288 @ec[:image].delete_if {|x| x =~/https?:\/\// }
1289 @ec[:image]=@ec[:image].sort
1290 end
1291 @ec[:audio]=@ec[:audio].uniq.flatten.sort
1292 @ec[:multimedia]=@ec[:multimedia].uniq.flatten.sort
1293 unless @rights
1294 if defined? @creator.author \
1295 and @creator.author.is_a?(String) \
1296 and defined? @date.published \
1297 and @date.published.is_a?(String)
1298 @rights=SiSU_Param::Parameters::MdDefault.new.rights(@creator.author,@date.published)
1299 elsif defined? @creator.author \
1300 and @creator.author.is_a?(String)
1301 @rights=SiSU_Param::Parameters::MdDefault.new.rights("[#{@creator.author}]",'')
1302 end
1303 end
1304 if defined? @classify.topic_register \
1305 and @classify.topic_register.is_a?(String) \
1306 and @classify.topic_register.length >3
1307 topic_register=@classify.topic_register
1308 u=topic_register.scan(/[^;]+/m).sort
1309 v=[]
1310 u.each do |l|
1311 v << l.scan(/[^:]+/m)
1312 end
1313 v.each do |s|
1314 s[-1]=s[-1].scan(/[^|]+/m) if s[-1] =~/[|]/m
1315 @topic_register_array << s
1316 end
1317 @topic_register_array
1318 end
1319 if @i18n
1320 @i18n=@i18n.uniq
1321 @i18n << 'en' unless @i18n.find_index("en")
1322 else
1323 @i18n=[ 'en' ]
1324 end
1325 translated=[]
1326 translate_list=[@pagenew,@pagebreak,@pageline,@num_top,@toc_lev_limit]
1327 translate_list.each do |t|
1328 translate=t.to_s if t
1329 translated << if translate
1330 translate.gsub!(/3/,'6')
1331 translate.gsub!(/2/,'5')
1332 translate.gsub!(/1/,'4')
1333 translate.gsub!(/:?C/,'3')
1334 translate.gsub!(/:?B/,'2')
1335 translate.gsub!(/:?A/,'1')
1336 # looks like an ok substituion for the above but is not, causes problems, check why
1337 #translate=translate.gsub(/3/,'6').
1338 # gsub(/2/,'5').
1339 # gsub(/1/,'4').
1340 # gsub(/:?C/,'3').
1341 # gsub(/:?B/,'2').
1342 # gsub(/:?A/,'1')
1343 translate=(translate =~/^\d+$/) \
1344 ? translate.to_i
1345 : translate
1346 else nil
1347 end
1348 end
1349 @pagenew,@pagebreak,@pageline,@num_top,@toc_lev_limit=translated
1350 @markup=@markup.gsub(/page_new\s*=\s*([\dA-C])/,"page_new=#{@pagenew}").
1351 gsub(/page_break\s*=\s*([\dA-C])/,"page_break=#{@pagebreak}").
1352 gsub(/page_line\s*=\s*([\dA-C])/,"page_line=#{@pageline}").
1353 gsub(/num_top\s*=\s*([\dA-C])/,"num_top=#{@num_top}").
1354 gsub(/toc_lev_limit\s*=\s*([\dA-C])/,"toc_lev_limit=#{@toc_lev_limit}")
1355 papersize_array_rc=@papersize.downcase.scan(/(?:a4|letter|legal|book|a5|b5)/)
1356 papersize_array_opt=[
1357 ((@opt.act[:pdf_a4][:set]==:on) ? 'a4' : ''),
1358 ((@opt.act[:pdf_a5][:set]==:on) ? 'a5' : ''),
1359 ((@opt.act[:pdf_b5][:set]==:on) ? 'b5' : ''),
1360 ((@opt.act[:pdf_letter][:set]==:on) ? 'letter' : ''),
1361 ((@opt.act[:pdf_legal][:set]==:on) ? 'legal' : ''),
1362 ] - [""]
1363 @papersize_array=(papersize_array_opt.length > 0) \
1364 ? papersize_array_opt
1365 : papersize_array_rc
1366 fn=@opt.fno #decide what to do a filesize on .ssm tells very little about actual document size
1367 @filesize=(File.size(fn)).to_s
1368 if @sys.openssl !=false \
1369 and FileTest.file?(@env.source_file_with_path)
1370 @dgst=[]
1371 case @env.digest(@opt).type
1372 when :sha512
1373 dgst=@sys.sha512(@env.source_file_with_path)
1374 @dgst=dgst[1].length==128 ? dgst : nil
1375 puts 'check document (sha512) digest' if not @dgst
1376 when :sha256
1377 dgst=@sys.sha256(@env.source_file_with_path)
1378 @dgst=dgst[1].length==64 ? dgst : nil
1379 puts 'check document (sha256) digest' if not @dgst
1380 when :md5
1381 dgst=@sys.md5(@env.source_file_with_path)
1382 @dgst=dgst[1].length==32 ? dgst : nil
1383 puts 'check document (md5) digest' if not @dgst
1384 else
1385 dgst=@sys.sha256(@env.source_file_with_path)
1386 @dgst=dgst[1].length==64 ? dgst : nil
1387 puts 'check document (sha256) digest' if not @dgst
1388 end
1389 elsif not FileTest.file?(@env.source_file_with_path)
1390 #puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia)
1391 end
1392 @publisher ||= "#{@@publisher} (this copy)"
1393 fn_set_lang=SiSU_Env::StandardiseLanguage.new(@opt.lng).language
1394 unless @language[:code] \
1395 and @language[:name]
1396 lang=@env.i18n.language #default language settings for directory by name, or in sysrc.yml
1397 @language[:code] ||= lang.code
1398 @language[:name] ||= lang.title
1399 end
1400 unless fn_set_lang[:d]==true #decide, naming convention overrides other settings, within document, etc.
1401 @language[:code]=fn_set_lang[:c]
1402 @language[:name]=fn_set_lang[:n]
1403 end
1404 @fnl=@env.i18n.lang_filename(fn_set_lang[:c])
1405 @lang=@lang.uniq
1406 @fn=SiSU_Env::EnvCall.new(@fns).lang(fn_set_lang[:c])
1407 if @en[:note] > 0 \
1408 and @en[:sum] > 0
1409 if @en[:sum] > 0
1410 else
1411 SiSU_Screen::Ansi.new(
1412 @opt.act[:color_state][:set],
1413 '*WARN* both endnote styles used',
1414 "~{ #{@en[:sum]} }~ and ^~ #{@en[:mark]}"
1415 ).warn unless @opt.act[:quiet][:set]==:on
1416 end
1417 end
1418 if @en[:mark] != @en[:note] \
1419 and @en[:note] > 0
1420 @en[:mismatch]=@en[:note] - @en[:mark]
1421 SiSU_Screen::Ansi.new(
1422 @opt.act[:color_state][:set],
1423 '*WARN* endnote number mismatch',
1424 "endnotes: #{@en[:note]} != endnote reference marks: #{@en[:mark]} (difference = #{@en[:mismatch]})"
1425 ).warn unless @opt.act[:quiet][:set]==:on
1426 footnote_conversion_errors=File.new("#{Dir.pwd}/footnote_conversion_errors.txt",'a')
1427 footnote_conversion_errors <<
1428 "#{@fns}:\n\tendnotes: #{@en[:note]} != endnote reference marks: #{@en[:mark]} (difference = #{@en[:mismatch]})\n"
1429 end
1430 if not @title \
1431 or not defined? @title.main \
1432 or @title.main !~/[\S]/
1433 if @fns =~/\.ssm$/ \
1434 and @opt.inspect =~/P/
1435 #@title=Md.new('Text Insert',@opt,@env).title
1436 else
1437 SiSU_Screen::Ansi.new(
1438 @opt.act[:color_state][:set],
1439 'WARNING: Document Title missing',
1440 'please provide @title:'
1441 ).warn unless @opt.act[:quiet][:set]==:on
1442 end
1443 end
1444 if @author !~/[\S]/
1445 if @fns =~/\.ssm$/ \
1446 and @opt.inspect =~/P/
1447 #@creator=SiSU_Param::Md.new('Text Insert',@opt,@env).creator
1448 else
1449 SiSU_Screen::Ansi.new(
1450 @opt.act[:color_state][:set],
1451 'WARNING: Document Author missing',
1452 'please provide @creator: :author:'
1453 ).warn unless @opt.act[:quiet][:set]==:on
1454 end
1455 end
1456 @struct={}
1457 doc_struct=Hash.new(0)
1458 if @lv1.nil?
1459 fns_array.each do |para|
1460 if para =~/^(Part|Chapter|Section|Article)\b/i
1461 case para
1462 when /^(Part|PART)\b/
1463 @struct[:part]=doc_struct[:part]
1464 doc_struct[:part]=doc_struct[:part] + 1
1465 when /^(Chapter|CHAPTER)\b/
1466 @struct[:chapter]=doc_struct[:chapter]
1467 doc_struct[:chapter]=doc_struct[:chapter] + 1
1468 when /^(Section|SECTION)\b/
1469 @struct[:section]=doc_struct[:section]
1470 doc_struct[:section]=doc_struct[:section] + 1
1471 when /^(Article|ARTICLE)\b/
1472 @struct[:article]=doc_struct[:article]
1473 doc_struct[:article]=doc_struct[:article] + 1
1474 when /^(Clause|CLAUSE)\b/
1475 @struct[:clause]=doc_struct[:clause]
1476 doc_struct[:clause]=doc_struct[:clause] + 1
1477 when /^\d\..*[^\.]$/
1478 @struct[:number]=doc_struct[:number]
1479 doc_struct[:number]=doc_struct[:number] + 1
1480 end
1481 end
1482 end
1483 if doc_struct[:article] > 2 #%~level 4
1484 @lv4=/^(?:Article|ARTICLE)\b/
1485 elsif doc_struct[:chapter] > 2 \
1486 and doc_struct[:article] \
1487 and doc_struct[:article] < 3
1488 @lv4=/^(?:Chapter|CHAPTER)\b/
1489 elsif doc_struct[:clause] > 2
1490 @lv4=/^(?:Clause|CLAUSE)\b/
1491 elsif doc_struct[:number] > 2
1492 @lv4="^\d\..*[^\.]$"
1493 end
1494 if doc_struct[:section] > 2 #%~level 3
1495 @lv3=/^(?:Section|SECTION)\b/
1496 end
1497 if doc_struct[:chapter] > 2 \
1498 and doc_struct[:article] \
1499 and doc_struct[:article] > 2
1500 @lv2=/^(?:Chapter|CHAPTER)\b/
1501 end
1502 if doc_struct[:part] > 2 \
1503 and @lv[2].nil?
1504 @lv2=/^(?:Part|PART)\b/
1505 end
1506 if doc_struct[:part] > 2 \
1507 and @lv[2].inspect !~/Part/ \
1508 and @lv[1].nil?
1509 @lv1=/^(Part|PART)\b/
1510 end
1511 end
1512 @lnk=@lnk.compact if @lnk
1513 @lv0 ||=/^0~/
1514 @lv1 ||=/^1~/
1515 @lv2 ||=/^2~/
1516 @lv3 ||=/^3~/
1517 @lv4 ||=/^4~/
1518 @lv5 ||=/^5~/
1519 @lv6 ||=/^6~/
1520 @data=nil #else whole file's contents are stored in md pstore & is not required to be... big waste actually
1521 @file=SiSU_Env::FileOp.new(self) #watch
1522 Store.new(self,@env).store #% pstore
1523 self
1524 rescue
1525 if @opt.act[:harvest][:set]==:on
1526 exit
1527 end
1528 end
1529 end
1530 private
1531 class Store
1532 def initialize(md,env)
1533 @md,@env=md,env
1534 end
1535 def store
1536 begin
1537 pstorefile="#{@env.processing_path.ao}/#{@md.fns}.pstore"
1538 File.unlink(pstorefile) if FileTest.file?(pstorefile)
1539 if (@md.opt.act[:verbose_plus][:set]==:on \
1540 || @md.opt.act[:maintenance][:set]==:on)
1541 SiSU_Screen::Ansi.new(
1542 @md.opt.act[:color_state][:set],
1543 "PStore -> #{pstorefile}"
1544 ).txt_grey
1545 end
1546 store=PStore.new(pstorefile)
1547 store.transaction do
1548 store['md']=@md
1549 store.commit
1550 end
1551 @@md=@md=nil
1552 rescue
1553 SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
1554 __LINE__.to_s + ':' + __FILE__
1555 end
1556 ensure
1557 end
1558 end
1559 end
1560 end
1561 end
1562 class Instantiate
1563 def param_instantiate
1564 @@date=SiSU_Env::InfoDate.new
1565 @@proc=
1566 @@filename_txt=
1567 @@filename_texinfo=
1568 @@filename_lout_portrait=
1569 @@filename_lout_landscape=
1570 @@filename_html_scroll=
1571 @@filename_html_index=
1572 @@filename_html_segtoc=
1573 @@filename_semantic=
1574 @@filename_rss=
1575 @@newfile=
1576 @@drr=
1577 nil
1578 @doc={
1579 initialise: nil,
1580 markup: '',
1581 lnks: '',
1582 stmp: '',
1583 prefix_a: '',
1584 prefix_b: '',
1585 req: {}
1586 }
1587 @@yaml=@@yamladdr=nil
1588 @@flag={}
1589 @@publisher='SiSU scribe'
1590 end
1591 end
1592 end
1593 __END__