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