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