# coding: utf-8 =begin * Name: SiSU * Description: a framework for document structuring, publishing and search * Author: Ralph Amissah * Copyright: (C) 1997 - 2010, Ralph Amissah, All Rights Reserved. * License: GPL 3 or later: SiSU, a framework for document structuring, publishing and search Copyright (C) Ralph Amissah This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . If you have Internet connection, the latest version of the GPL should be available at these locations: * SiSU uses: * Standard SiSU markup syntax, * Standard SiSU meta-markup syntax, and the * Standard SiSU object citation numbering and system * Hompages: * Download: * Ralph Amissah ** Description: parameters extracted from input file(s) for program use =end module SiSU_Param require 'uri' require 'pstore' require "#{SiSU_lib}/sysenv" # sysenv.rb include SiSU_Env require "#{SiSU_lib}/param_identify_markup" # param_identify_markup.rb require "#{SiSU_lib}/help" # help.rb include SiSU_Help @@date=SiSU_Env::Info_date.new @@symlnk=Create_system_link.new @@proc=@@filename_txt=@@filename_texinfo=@@filename_lout_portrait=@@filename_lout_landscape=@@filename_html_scroll=@@filename_html_index=@@filename_html_segtoc=@@filename_semantic=@@filename_rss=@@newfile=@@drr=nil @doc={ :initialise=>nil,:markup=>'',:lnks=>'',:stmp=>'',:req=>{} } @@yaml=@@yamladdr=nil @@trigger=nil @@lv,@@flag={},{} @@tex_backslash="\\\\" class Parameters @@publisher='SiSU scribe' @@md=@@fns=nil def initialize(opt) @opt=opt @cX||=SiSU_Screen::Ansi.new(opt.cmd) @cmd,@mod=opt.cmd,opt.mod @fns=opt.fns.gsub(/\.ssm$/,'.ssm.sst') #revisit CHECK Instantiate.new.param_instantiate @env=SiSU_Env::Info_env.new(@fns) @pstorefile="#{@env.path.dal}/#{@fns}.pstore" end def get unless @@fns==@fns @@fns=@fns @@md=nil end if @@md.nil? \ or @cmd =~/M/ #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 if File.exist?(@pstorefile) param_msg='Parameters from pstore' store=PStore.new(@pstorefile) store.transaction do @md=store['md'] end @md else param_msg='Parameters extracted' fns_array=@env.read_source_file(@opt.fns) md=Instructions.new(fns_array,@opt) @md=Instructions.new(fns_array,@opt).extract @md end if defined? @md.title.main # on removal check problems with -U tell=SiSU_Screen::Ansi.new(@cmd,param_msg,@md.title.main) tell.txt_grey if @cmd =~/[MVv]/ end @@md=@md else @@md end @@md.cmd=@cmd @@md end class Md_default def rights(author,date) @author,@date=author,date def all s=nil if @author s ||=((@date =~/([12][890]\d{2})/ ) \ ? ("Copyright (C) #{$1} #{@author}") \ : ('Copyright (C)' + @author)) #matches years 1800 through 20\d\d 2004w19 end s end def text all end def copyright def all s=nil if @author s ||=((@date =~/([12][890]\d{2})/ ) \ ? ("Copyright (C) #{$1} #{@author}") \ : ('Copyright (C)' + @author)) #matches years 1800 through 20\d\d 2004w19 end s end def text all end self end self end end class Md def initialize(str) @s=str end def validate_length(s,l,n) #s=(s.length <= l) ? s : nil s=if s.class==String \ and s.length <= l s elsif s.class==NilClass; nil elsif s.class !=String puts "#{n} is #{s.class}: programming error, String expected #{__FILE__}:#{__LINE__}" s else tell=SiSU_Screen::Ansi.new('v',"#{n} length #{s.length} exceeds set db field length #{l}, metadata dropped") tell.warn nil end end def name_format(name) if name name.strip! @name_a_h=[] authors=name.scan(/[^;]+/) authors.each_with_index do |a,i| b=((a =~/\s*\|\s*/) ? (a.split(/\|/)) : [a]) if b[0] =~/"(.+?)"/ @name_a_h << { :the => $1 } else x=b[0].scan(/[^,]+/) if x.length==1 @name_a_h << { :the => x[0].strip } elsif x.length==2 @name_a_h << { :the => x[0].strip, :others => x[1].strip } else #p x.length end end b.delete_at(0) b.each do |d| k,c=nil k,c=/^(\S+)\s+(.*)/.match(d)[1,2] if d @name_a_h[i][:hon]=c.strip if k=='hon' @name_a_h[i][:affiliation]=c.strip if k=='affiliation' @name_a_h[i][:nationality]=c.strip if k=='nationality' end end l=@name_a_h.length name_str='' @name_a_h.each_with_index do |a,i| name_str += if a[:others] z=(((l - i) > 1) ? ', ' : '') "#{a[:others].strip} #{a[:the].strip}" + z else z=(((l - i) > 2) ? ', ' : '') "#{a[:the].strip}" + z end end {:name_a_h =>@name_a_h,:name_str =>name_str} else nil end end def build_hash(arr) @h={} arr.each_with_index do |x,i| a,b=nil,nil if x =~/^%\s/ #ignore comment elsif x =~/:(\S+?):\s+(.+)/ a,b=/:(\S+?):\s+(.+)/.match(x)[1,2] elsif i == 0 a='main' b=x else end @h[a]=b end @h end def title a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def main s=@h['main'] l,n=Db[:col_title_part],'title.main' validate_length(s,l,n) end def sub s=@h['subtitle'] l,n=Db[:col_title_part],'title.subtitle' validate_length(s,l,n) end def edition s=@h['edition'] l,n=Db[:col_title_edition],'title.edition' validate_length(s,l,n) end def note @h['note'] #TEXT end def short s=(@h['short'] ? @h['short'] : @h['main']) l,n=Db[:col_title_part],'title.short' validate_length(s,l,n) end def full s=(@h['subtitle'] ? (@h['main'] + ' - ' + @h['subtitle']) : @h['main']) l,n=Db[:col_title],'title.full' validate_length(s,l,n) end def language s=@h['language'] l,n=Db[:col_language],'title.language' validate_length(s,l,n) end def language_char s=@h['language_char'] l,n=Db[:col_language_char],'title.language_char' validate_length(s,l,n) end self end 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 a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def author @h['author']=(@h['author'] ? @h['author'] : @h['main']) names=name_format(@h['author']) s=names[:name_str] l,n=Db[:col_name],'creator.author' validate_length(s,l,n) end def author_detail s=(@h['author'] ? @h['author'] : @h['main']) names=name_format(s) names[:name_a_h] end def contributor names=(@h['contributor'] ? name_format(@h['contributor']) : nil) s=(names.class==Hash) ? names[:name_str] : nil s=if s l,n=Db[:col_name],'creator.author' validate_length(s,l,n) else nil end end def contributor_detail names=(@h['contributor'] ? name_format(@h['contributor']) : nil) (names.class==Hash) ? names[:name_a_h] : nil end def illustrator names=(@h['illustrator'] ? name_format(@h['illustrator']) : nil) s=(names.class==Hash) ? names[:name_str] : nil s=if s l,n=Db[:col_name],'creator.illustrator' validate_length(s,l,n) else nil end end def illustrator_detail names=(@h['illustrator'] ? name_format(@h['illustrator']) : nil) (names.class==Hash) ? names[:name_a_h] : nil end def photographer names=(@h['photographer'] ? name_format(@h['photographer']) : nil) s=(names.class==Hash) ? names[:name_str] : nil s=if s l,n=Db[:col_name],'creator.photographer' validate_length(s,l,n) else nil end end def photographer_detail names=(@h['photographer'] ? name_format(@h['photographer']) : nil) (names.class==Hash) ? names[:name_a_h] : nil end def translator names=(@h['translator'] ? name_format(@h['translator']) : nil) s=(names.class==Hash) ? names[:name_str] : nil s=if s l,n=Db[:col_name],'creator.translator' validate_length(s,l,n) else nil end end def translator_detail names=(@h['translator'] ? name_format(@h['translator']) : nil) (names.class==Hash) ? names[:name_a_h] : nil end def audio names=(@h['audio'] ? name_format(@h['audio']) : nil) s=(names.class==Hash) ? names[:name_str] : nil s=if s l,n=Db[:col_name],'creator.audio' validate_length(s,l,n) else nil end end def audio_detail names=(@h['audio'] ? name_format(@h['audio']) : nil) (names.class==Hash) ? names[:name_a_h] : nil end def digitized_by names=(@h['digitized_by'] ? name_format(@h['digitized_by']) : nil) s=(names.class==Hash) ? names[:name_str] : nil s=if s l,n=Db[:col_name],'creator.digitized_by' validate_length(s,l,n) else nil end end def digitized_by_detail names=(@h['digitized_by'] ? name_format(@h['digitized_by']) : nil) (names.class==Hash) ? names[:name_a_h] : nil end def prepared_by names=(@h['prepared_by'] ? name_format(@h['prepared_by']) : nil) s=(names.class==Hash) ? names[:name_str] : nil s=if s l,n=Db[:col_name],'creator.prepared_by' validate_length(s,l,n) else nil end end def prepared_by_detail names=(@h['prepared_by'] ? name_format(@h['prepared_by']) : nil) names=name_format(@h['prepared_by']) (names.class==Hash) ? names[:name_a_h] : nil end self end def rights a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def copyright # TEXT used db sql def text #you may wish to expand to take from all r=if @h['copyright'] @h['copyright'] elsif @h['text'] @h['text'] elsif @h['main'] @h['main'] else p 'provide copyright' end end def translation r=(@h['translation'] ? @h['translation'] : nil) end def illustrations r=(@h['illustrations'] ? @h['illustrations'] : nil) end def photographs r=(@h['photographs'] ? @h['photographs'] : nil) end def digitiztion r=(@h['digitization'] ? @h['digitization'] : nil) end def audio r=(@h['audio'] ? @h['audio'] : nil) end self end def license r=(@h['license'] ? @h['license'] : nil) end def all s=if @h['all']; @h['all'] else s=copyright.text + ';' if defined? copyright.translation \ and copyright.translation s +=' translation ' + copyright.translation + ';' end if defined? copyright.illustrations \ and copyright.illustrations s +=' illustrations ' + copyright.illustrations + ';' end if defined? copyright.photographs \ and copyright.photographs s +=' photographs ' + copyright.photographs + ';' end if defined? copyright.digitization \ and copyright.digitization s +=' digitization ' + copyright.digitization + ';' end if defined? copyright.audio \ and copyright.audio s +=' audio ' + copyright.audio + ';' end if defined? copyright.license \ and copyright.license s +=' License: ' + copyright.license end s end s end self end def classify a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def coverage s=@h['coverage'] l,n=Db[:col_classify_short],'classify.coverage' validate_length(s,l,n) end def relation s=@h['relation'] l,n=Db[:col_classify_short],'classify.short' validate_length(s,l,n) end def subject s=@h['subject'] l,n=Db[:col_classify_txt_short],'classify.subject' validate_length(s,l,n) end def topic_register s=@h['topic_register'] l,n=Db[:col_classify_txt_long],'classify.topic_register' validate_length(s,l,n) end def type s=@h['type'] l,n=Db[:col_classify_txt_short],'classify.type' validate_length(s,l,n) end def identifier s=@h['identifier'] l,n=Db[:col_classify_identify],'classify.identifier' validate_length(s,l,n) end def loc s=@h['loc'] l,n=Db[:col_classify_library],'classify.loc' validate_length(s,l,n) end def dewey s=@h['dewey'] l,n=Db[:col_classify_library],'classify.dewey' validate_length(s,l,n) end def pg s=@h['pg'] l,n=Db[:col_classify_small],'classify.pg' validate_length(s,l,n) end def isbn s=@h['isbn'] l,n=Db[:col_classify_small],'classify.isbn' validate_length(s,l,n) end self end def publisher a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) s=@h['main'] l,n=Db[:col_name],'publisher' validate_length(s,l,n) end def date a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def added_to_site s=@h['added_to_site'] l,n=Db[:col_date_text],'date.added_to_site' validate_length(s,l,n) end def available s=@h['available'] l,n=Db[:col_date_text],'date.available' validate_length(s,l,n) end def created s=@h['created'] l,n=Db[:col_date_text],'date.created' validate_length(s,l,n) end def issued s=@h['issued'] l,n=Db[:col_date_text],'date.issued' validate_length(s,l,n) end def modified s=@h['modified'] l,n=Db[:col_date_text],'date.modified' validate_length(s,l,n) end def published s=@h['published']=(@h['published'] ? @h['published'] : @h['main']) l,n=Db[:col_date_text],'date.published' validate_length(s,l,n) end def valid s=@h['valid'] l,n=Db[:col_date_text],'date.valid' validate_length(s,l,n) end self end def language # as things stand this should really be populated from title.language and original.language, resolve a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def document s=@h['document']=(@h['document'] ? @h['document'] : @h['main']) l,n=Db[:col_language],'language.document' validate_length(s,l,n) end def document_char s=@h['document_char']=(@h['document_char'] ? @h['document_char'] : nil) l,n=Db[:col_language_char],'language.document_char' validate_length(s,l,n) end def original s=@h['original'] l,n=Db[:col_language],'language.original' validate_length(s,l,n) end def original_char s=@h['original_char'] l,n=Db[:col_language_char],'language.original_char' validate_length(s,l,n) end self end def make a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def headings lv=[] s=@s s=((s =~/;/) ? (s.split(/;\s*/)) : [ s ]) lv[0]=s lv1=s[0] ||='1~ ' #some arbitrary changes made lv[1]=/^#{lv1}/ lv2=s[1] ||='2~ ' lv[2]=/^#{lv2}/ lv3=s[2] ||='3~ ' lv[3]=/^#{lv3}/ lv4=s[3] ||='4~ ' lv[4]=/^#{lv4}/ lv5=s[4] ||='5~ ' lv[5]=/^#{lv5}/ lv6=s[5] ||='6~ ' lv[6]=/^#{lv6}/ lv end def num_top @h['num_top'] end def breaks pagebreaks=((@h['breaks'] =~/;/) \ ? (@h['breaks'].split(/;\s*/)) \ : [ @h['breaks'] ]) page_new,page_break=nil,nil pagebreaks.each do |x| page_new=x[/(:?[\dA-C],?)+/] if x=~/new|clear/ page_break=x[/(:?[\dA-C],?)+/] if x =~/break/ end {:page_new =>page_new, :page_break =>page_break} end def bold m=@h['bold'] x=(m=~/\/i$/)? 'i' : '' m.gsub!(/^\/(.+?)\/i?/,'\1') m.gsub!(/\(/,'(?:') # avoid need to escape use of brackets within regex provided rgx='\b(' + m + ')\b' y=((x =~/i/) ? (/#{rgx}/i) : (/#{rgx}/)) { :str =>'\b(?:' + m + ')\b', :regx => y } end def italics m=@h['italics'] x=((m=~/\/i$/) ? 'i' : '') m.gsub!(/^\/(.+?)\/i?/,'\1') m.gsub!(/\(/,'(?:') # avoid need to escape use of brackets within regex provided rgx='\b(' + m + ')\b' y=((x =~/i/) ? (/#{rgx}/i) : (/#{rgx}/)) { :str =>'\b(?:' + m + ')\b', :regx => y } end def skin @h['skin'] end def promo @h['promo'] end def ad @h['ad'] end def manpage manpage={} if @h['manpage'] if @h['manpage'] =~/;/m man=@h['manpage'].split(/;/m) man.each do |x| m=(x=~/=/m) ? x.split(/=/m) : nil if m manpage[m[0].strip] = m[1].split(/ \. /) end end end end if manpage['name'] manpage['name']=manpage['name'].join("\n.BR\n") manpage['name'].gsub!(/(-)/m,"\\\\\\1") manpage['name'].gsub!(/\A/,"\n.SH NAME\n") else manpage['name']='man page "name/whatis" information not provided, set in header @man: name=[whatis information]' end if manpage['synopsis'] manpage['synopsis']=manpage['synopsis'].join("\n\n.BR\n") manpage['synopsis'].gsub!(/(-)/m,"\\\\\\1") manpage['synopsis'].gsub!(/\A/,"\n.SH SYNOPSIS\n") else manpage['synopsis']='' end unless manpage['section'] manpage['section']=1 end manpage end self end def current_publisher @s end def original a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def publisher s=@h['publisher'] l,n=Db[:col_name],'original.publisher' validate_length(s,l,n) end def language s=@h['language'] l,n=Db[:col_language],'original.language' validate_length(s,l,n) end def language_char s=@h['language_char'] l,n=Db[:col_language_char],'original.language_char' validate_length(s,l,n) end def source s=@h['source'] l,n=Db[:col_name],'original.source' validate_length(s,l,n) end def institution s=@h['institution'] l,n=Db[:col_name],'original.institution' validate_length(s,l,n) end def nationality s=@h['nationality'] l,n=Db[:col_language],'original.nationality' validate_length(s,l,n) end self end def links a=@s.split(/[ ]*\n[ ]*/m) a end def notes a=@s.split(/[ ]*\n[ ]*/m) @h=build_hash(a) def abstract @h['abstract'] end def comment @h['comment'] end def description @h['description'] end def history @h['history'] end def prefix @h['prefix'] end self end end class Instructions @doc={ :lv=>[] } @doc[:fns],@doc[:fnb],@doc[:scr_suffix]='','','' @@publisher='SiSU scribe' attr_accessor :cmd,:make,:mod,:env,:fn,:fns,:fnb,:fnn,:fnt,:fnl,:flv,:fnz,:fnstex,:ocn,:sfx_src,:pdf,:file_type,:dir_out,:dir_tex,:dir_lout,:txt_path,:site_skin,: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,: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,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:lvs,:pagenew,:pagebreak,:num_top,:toc_lev_limit,:flag_endnotes,:flag_auto_endnotes,:flag_separate_endnotes,:flag_separate_endnotes_make,:markup,:markup_instruction,:markup_version,:markup_declared,:flag_tables,:vocabulary,:doc_skin,:doc_css,:yaml,:lnk,: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,:file_size,:user,:home,:hostname,:pwd,:firstseg,:programs,:author_copymark,:lang,:en,:dgst,:dgst_skin,: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_publication,:original_publication_date,:original_publication_nationality,:original_publication_institution,:writing_focus,:audio,:daisy def initialize(fns_array,opt) @env=@fn=@fns=@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=@site_skin=@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=@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=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@pagenew=@pagebreak=@num_top=@toc_lev_limit=@flag_tables=@vocabulary=@doc_skin=@doc_css=@yaml=@lnk=@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=@file_size=@firstseg=@programs=@author_copymark=@lang=@en=@dgst=@dgst_skin=@generated=@heading_seg_first=@base_program=@topic_register=@original_publication_details=@original_publication=@original_publication_date=@original_publication_nationality=@original_publication_institution=@writing_focus=@audio=nil @data,@fns,@cmd,@mod,@opt=fns_array,opt.fns,opt.cmd,opt.mod,opt #@data used as data @flag_tables,@set_header_title,@set_heading_top,@set_heading_seg,@heading_seg_first_flag,@flag_promo,@book_idx=false,false,false,false,false,false,false @seg_autoname_safe=true @daisy,@sem_tag=false,false @authorship,@markup_instruction,@markup_declared,@image='','','','' #check which other values should be set to empty rather than nil @markup=@markup_instruction #use @markup_instruction @doc,@fn,@make_italic,@tag_hash,@ec={},{},{},{},{},{} @flv,@lang,@seg_names,@tags,@tag_array,@tag_a,@ec[:image],@ec[:audio],@ec[:multimedia]=Array.new(9){[]} @authors,@topic_register_array,@papersize_array=[],[],[] @lvs=[nil,0,0,0,0,0,0] @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ @rgx_audio=/\{\s*(\S+?\.(?:mp3|ogg))/ @rgx_mm=/\{\s*(\S+?\.(?:ogg|mpeg))/ #expand and distinguish ogg begin rescue; SiSU_Errors::Info_error.new($!,$@,@cmd,@fns).error ensure end end #protected def determine_papersize(l) l=case l when /eu|europe|uk/i; 'A4' #European default, SiSU default when /(?:us-)?legal|legal/i; 'US_legal' #U.S. alternative when /(?:us-)?letter|u.s.|us/i; 'US_letter' #U.S. default when /book_a5|a5/i; 'book_a5' when /book_b5|b5|book/i; 'book_b5' #book default - larger else 'A4' end end def extract @user,@home,@hostname,@pwd=ENV['USER'],ENV['HOME'],ENV['HOSTNAME'],ENV['PWD'] @programs,@wc,@language,@language_original={},{},{},{} @en={ :sum=>0,:mark=>0,:note=>0,:mismatch=>0 } @prog=SiSU_Env::Info_settings.new @sys=SiSU_Env::System_call.new @env=SiSU_Env::Info_env.new(@fns) #watch puts 'system locale: ' + @sys.locale if @opt.cmd =~/[MV]/ if @prog.wc \ and @sys.wc wc=%x{wc #{fns}} wca=wc.scan(/\d+/) @wc_lines,@wc_words,@wc_bytes=wca[0].to_i,wca[1].to_i,wca[2].to_i else fns_a=@data.dup tmp=fns_a.join fns_a=tmp.scan(/\S+/) @wc_words=fns_a.length fns_a=tmp=nil end @concord_make=(@wc_words > @env.concord_max) ? false : true @locale=@sys.locale @file_encoding=@sys.file_encoding(fns,@cmd) # programs set here for things that affect output appearance only @programs[:pdf]=SiSU_Env::System_call.new.program_found?('pdflatex') if @env.i18n.multilingual m=/((.+?)(?:\~\w{2,3})?)\.((?:-|ssm\.)?sst)$/ #watch added match for sss @fnn,@fnb,@fnt=@fns[m,1],@fns[m,2],@fns[m,3] @flv=@env.document_language_versions_found[:f] @fnz=(@fns =~/\.(?:ssm\.sst|ssm)$/) ? (@fnn + '.ssm.zip') : (@fnn + '.sst.zip') else m=/(.+?)\.((?:-|ssm\.)?sst)$/ @fnb=@fnn=@fns[m,1] @fnt=@fns[m,2] @flv<<@fns @fnz=(@fns =~/\.(?:_sst|ssm)$/) ? (@fnb + '.ssm.zip') : (@@fnb + '.sst.zip') end @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 @sfx_src=@fns[m,2] if @fns =~ /(?:-|ssm\.)?sst$/ #watch @env_out_root=@env.path.output @dir_out="#{@env.path.output}/#{@fnb}" @dir_tex=@env.path.tex @dir_lout=@env.path.lout @@publisher='SiSU http://www.jus.uio.no/sisu' end @txt_path=@txt_path ||= @env.path.output @stmp=%{#{@fns}}[/^(.+?)\..*/m,1] @fnstex=@fns.gsub(/_/,'\_') @flag_endnotes,@flag_auto_endnotes,@flag_separate_endnotes=false,false,false @flag_separate_endnotes_make=true regx_date=/^\d{4}(?:-(?:[0][0-9]|1[0-2])(-(?:[0-2][0-9]|3[01]))?)?$/ ver=SiSU_Env::Info_version.instance @sisu_version=ver.get_version @ruby_version=ver.rbversion @generated=Time.now fns_array=@data.dup skip unless fns_array # consider @markup_version=SiSU_Markup_type::Markup_identify.new(fns_array,@opt).markup_version? #% determine markup version if fns_array[0] =~ /^(?:% )?(?:SiSU\s+(?:master\s+)?[\d.]*|sisu-[\d.]+)$/ #check markup and markup version if fns_array[0] =~ /^(?:% )?(?:SiSU\s+(?:master\s+)?|sisu-)[\d.]+$/ #check markup and markup version @markup_version_declared=fns_array[0].match(/^(?:% )?(?:SiSU\s+(?:master\s+)?|sisu-)([\d.]+)$/)[1] sm_a,sm_b,sm_c=fns_array[0].match(/^(?:% )?(?:SiSU\s+(?:master\s+)?|sisu-)([0-9]+)?(?:\.([0-9]+))?(?:\.([0-9]+))?$/)[1..3] sm_c ||=0 sv=(@cmd =~/[VMv]/) ? ("SiSU version (#{@sisu_version[:version]})") : '' s_a,s_b,s_c=@sisu_version[:version].match(/^([0-9]+)?(?:\.([0-9]+))?(?:\.([0-9]+))?(?:\-\S+)?$/)[1..3] tell=(@markup_version_declared.to_f==@markup_version.to_f) \ ? SiSU_Screen::Ansi.new(@cmd,"Markup version (#{@markup_version})",sv) \ : SiSU_Screen::Ansi.new(@cmd,"Markup version declared (#{@markup_version_declared}), determined (#{@markup_version})",sv) ok=if s_a.to_i > sm_a.to_i true elsif s_a.to_i == sm_a.to_i \ and s_b.to_i >= sm_b.to_i true elsif s_a.to_i == sm_a.to_i \ and s_b.to_i == sm_b.to_i \ and s_c.to_i >= sm_c.to_i true else false end if ok tell.txt_green if @cmd =~/[vVM]/ else tell=SiSU_Screen::Ansi.new(@cmd,"Warning: markup version determined (#{@markup_version}) or markup version declared (#{@markup_version_declared}) is newer than SiSU version (#{@sisu_version[:version]})") tell.warn unless @cmd =~/q/ end else tell=SiSU_Screen::Ansi.new(@cmd,'No SiSU markup version provided') tell.warn if @cmd =~/[VM]/ end else tell=SiSU_Screen::Ansi.new(@cmd,'SiSU filetype indicator not provided') tell.warn unless @cmd =~/q/ end @code_flag=false fns_array.each do |para| #% Scan document if para !~/^%+\s/ \ and para =~//,Mx[:br_line]) #% metainfo DC copyright, public domain, copyleft, creative commons, etc. @rights=Md.new($1.strip).rights when /^@papersize:\s+(.+?)$/m #% metainfo DC l=$1 if @mod.inspect !~/--papersize[=-]\S+/ l=determine_papersize(l.dup) @papersize=l end when /^@make:(.+)/m #% metainfo DC @make=Md.new($1.strip).make if defined? @make.breaks \ and @make.breaks[:page_new] #clearpage @pagenew=@make.breaks[:page_new] end if defined? @make.breaks \ and @make.breaks[:page_break] #newpage @pagebreak=@make.breaks[:page_break] end if defined? @make.headings \ and @make.headings @toc=@make.headings[0] @lv1=@make.headings[1] @lv2=@make.headings[2] @lv3=@make.headings[3] @lv4=@make.headings[4] @lv5=@make.headings[5] @lv6=@make.headings[6] end if defined? @make.num_top \ and @make.num_top @num_top=@make.num_top # remove @num_top end if defined? @make.skin \ and @make.skin @doc_skin=@make.skin end if defined? @make.manpage \ and @make.manpage @man_section=(defined? @make.manpage.section) ? @make.manpage.section : 1 end when /^@links:\s+(.+?)\Z/m #% processing doc_links=Md.new($1.strip).links count=1 @lnk=[] doc_links.each do |doc_link| if doc_link=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ @lnk[count]={} @lnk[count][:say],@lnk[count][:url]=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2] count +=1 end end when /^@notes?:\s(.+)/ #% metainfo Md.new($1.strip).notes when /^@base_program:\s+(.+?)$/; @base_program=$1 #% processing end @lv1 ||=/^1~/ @lv2 ||=/^2~/ @lv3 ||=/^3~/ @lv4 ||=/^4~/ @lv5 ||=/^5~/ @lv6 ||=/^6~/ else #% case para when /^:?A~/ @lvs[1]=1 when /^:?B~/ @lvs[2]=1 when /^:?C~/ @lvs[3]=1 when /^1~/ @lvs[4]=1 when /^2~/ @lvs[5]=1 when /^3~/ @lvs[6]=1 end if para =~ /^(?:1|:?A)~/ #% processing if para=~/^:?A~/ if @markup.nil? \ or @markup.empty? @markup=@markup_version.to_s elsif @markup !~/0\.38/; @markup=@markup.strip + "; #{@markup_version}" end end if (para=~/^:?A~/ and @markup_version >= 0.38) \ or (para=~/^1~/ and @markup_version < 0.38) if @title.nil? @title=para[/^:?[A1]~\S*(.+)$/m,1] @html_title=@title.gsub(/(

|

|
|
)/,'') @title.chomp!("\n") @html_title.chomp!("\n") tell=SiSU_Screen::Ansi.new(@cmd,'Parameters',@html_title) tell.txt_grey if @cmd =~/v/ end end end if not @book_idx \ and para =~/^=\{(.+?)\}\s*$/ @book_idx=true end unless @code_flag case para when /~\{\s+.+?\}~/m #% processing en=para.scan(/~\{.+?\}~/m) en.each { |e| @en[:sum] +=1 } when /~\^(?:\s|$)/m #% processing mk=para.scan(/~\^(?:\s|$)/) mk.each { |e| @en[:mark] +=1 } when /^\^~\s+\S/; @en[:note] +=1 #% processing end end if para =~/~\{|\^~ |~\^|<:ee>|\{.+?\[[1-6]\]\}\S+?\.ss[tm]/m; @flag_auto_endnotes,@flag_endnotes=true,true end unless @flag_auto_endnotes if para =~/^(4~endnotes\b|<:ee>)/ @flag_separate_endnotes=true @flag_endnotes=true end end if para =~/^(?:4~endnotes|<:ee>)/; @flag_separate_endnotes_make=false end if para =~/\s*.+/; @flag_endnotes=true end if para =~/^(?:table\{|\{table)/i; @flag_tables=true end end if para =~/^:?A~/ @set_heading_top=true end if para =~/^1~/ m=nil if para =~/^1~(\S+)\s+(.+)$/ m,t=$1,$2 elsif para =~/^1~\s+(.+)$/ t=$1 end unless @heading_seg_first_flag # extract first segment name @heading_seg_first=t @heading_seg_first_flag=true end if m # list all segment names @seg_names << m @set_heading_seg=true if m=~/^\d{1,3}/ \ and m !~/^0/ @seg_autoname_safe=false end end end if para !~/^%+\s/ \ and para =~@rgx_image @ec[:image] << para.scan(@rgx_image).uniq end @ec[:audio] << para.scan(@rgx_audio).uniq if para =~@rgx_audio #embedded content @ec[:multimedia] << para.scan(@rgx_mm).uniq if para =~@rgx_mm #embedded content unless @sem_tag @sem_tag=true if para=~/[:;]\{.+?\}[:;][a-z+]/ #refix later end end #% here endeth the document loop if @ec[:image].length > 0 @ec[:image].flatten! @ec[:image].uniq! @ec[:image].delete_if {|x| x =~/http:\/\// } @ec[:image].sort! end @ec[:audio].uniq!; @ec[:audio].flatten!; @ec[:audio].sort! @ec[:multimedia].uniq!; @ec[:multimedia].flatten!; @ec[:multimedia].sort! unless @rights if defined? @creator.author \ and @creator.author \ and defined? @date.published \ and @date.published @rights=Md_default.new.rights(@creator.author,@date.published) elsif defined? @creator.author \ and @creator.author @rights=Md_default.new.rights("[#{@creator.author}]",'') end end if @markup_version.to_f >= 0.38 #convert values in headers to internal representation translated=[] translate_list=[@pagenew,@pagebreak,@num_top,@toc_lev_limit] translate_list.each do |t| translate=t.to_s if t translated << if translate translate.gsub!(/3/,'6') translate.gsub!(/2/,'5') translate.gsub!(/1/,'4') translate.gsub!(/:?C/,'3') translate.gsub!(/:?B/,'2') translate.gsub!(/:?A/,'1') translate=if translate =~/^\d+$/; translate.to_i else translate end else nil end end @pagenew,@pagebreak,@num_top,@toc_lev_limit=translated @markup.gsub!(/page_new\s*=\s*([\dA-C])/,"page_new=#{@pagenew}") @markup.gsub!(/page_break\s*=\s*([\dA-C])/,"page_break=#{@pagebreak}") @markup.gsub!(/num_top\s*=\s*([\dA-C])/,"num_top=#{@num_top}") @markup.gsub!(/toc_lev_limit\s*=\s*([\dA-C])/,"toc_lev_limit=#{@toc_lev_limit}") end if @mod.inspect =~/--papersize[=-]\S+|--pdf[=-]\S+/ \ or @mod.inspect =~/--(?:a4|letter|legal|book|a5|b5)\b/i #command line config/header override @papersize=determine_papersize(@mod.inspect) end @papersize_array=@papersize.scan(/(?:a4|letter|legal|book|a5|b5)/i) if @sys.openssl !=false skin=@doc_skin \ ? (SiSU_Env::Info_skin.new(@opt,@doc_skin).select) \ : SiSU_Env::Info_skin.new(@opt).select @dgst,@dgst_skin=[],[] if @env.digest.type =~/sha256/ @dgst=@sys.sha256(@env.source_file_with_path) @dgst_skin=skin ? (@sys.sha256(skin)) : nil else @dgst=@sys.md5(@env.source_file_with_path) @dgst_skin=skin ? (@sys.md5(skin)) : nil end end @publisher ||= "#@@publisher (this copy)" fn_set_lang=SiSU_Env::Standardise_language.new.file_to_language(@fns) unless @language[:code] \ and @language[:name] lang=@env.i18n.language #default language settings for directory by name, or in sysrc.yml @language[:code] ||= lang.code @language[:name] ||= lang.title end unless fn_set_lang[:d]==true #decide, naming convention overrides other settings, within document, etc. @language[:code]=fn_set_lang[:c] @language[:name]=fn_set_lang[:l] end @fnl=@env.i18n.lang_filename(fn_set_lang[:c]) @flv.each do |l| lang=SiSU_Env::Standardise_language.new.file_to_language(l) c={ :a=>'',:b=>'',:c=>'' } if @fnl[:pre] =~/\S/; c[:a]="#{lang[:c]}." elsif @fnl[:mid] =~/\S/; c[:b]=".#{lang[:c]}" elsif @fnl[:post] =~/\S/; c[:c]=".#{lang[:c]}" end @lang << [lang[:l],"#{c[:a]}sisu_manifest#{c[:b]}.html#{c[:c]}"] end if @flv @lang.uniq! @fn=SiSU_Env::Env_call.new(@fns).lang(fn_set_lang[:c]) @identifier="#{@env.url.root}/#{@fnb}/#{@fn[:toc]}" #DC note constructed dc identifier if @en[:note] > 0 \ and @en[:sum] > 0 if @en[:sum] > 0 else tell=SiSU_Screen::Ansi.new(@cmd,'both endnote styles used',"~{ #{@en[:sum]} }~ and ^~ #{@en[:mark]}") tell.warn if @cmd !~/q/ end end if @en[:mark] != @en[:note] \ and @en[:note] > 0 @en[:mismatch]=@en[:note] - @en[:mark] SiSU_Screen::Ansi.new(@cmd,'endnote number mismatch',"endnotes: #{@en[:note]} != endnote reference marks: #{@en[:mark]} (difference = #{@en[:mismatch]})").warn if @cmd !~/q/ footnote_conversion_errors=File.new("#{Dir.pwd}/footnote_conversion_errors.txt",'a') footnote_conversion_errors << "#{@fns}:\n\tendnotes: #{@en[:note]} != endnote reference marks: #{@en[:mark]} (difference = #{@en[:mismatch]})\n" end if @title.main !~/[\S]/ tell=SiSU_Screen::Ansi.new(@cmd,'Document Title Missing','please provide it') tell.warn if @cmd =~/v/ end if @author !~/[\S]/ tell=SiSU_Screen::Ansi.new(@cmd,'Document Author/Creator Missing','please provide it') tell.warn if @cmd =~/v/ end # Elementary Document Structure Analysis - adds complexity may remove - need to develop - appears to work, proof of concept if @title.nil? title_trigger=nil fns_array.each do |para| if para !~/@\S+:[+-]?\s/ \ and para =~/\S/ \ and title_trigger.nil? @title=para[/(\S.+)/m,1] @html_title=@title.gsub(/(

|

|
|
)/,'') @title.chomp!("\n") @html_title.chomp!("\n") title_trigger=1 tell=SiSU_Screen::Ansi.new(@cmd,@html_title) tell.txt_cyan unless @cmd =~/q/ tell=SiSU_Screen::Ansi.new(@cmd,'Parameters') tell.txt_grey unless @cmd =~/q/ end end end @struct={} doc_struct=Hash.new(0) if @lv1.nil? fns_array.each do |para| if para =~/^(Part|Chapter|Section|Article)\b/i case para when /^(Part|PART)\b/ @struct[:part]=doc_struct[:part] doc_struct[:part]=doc_struct[:part] + 1 when /^(Chapter|CHAPTER)\b/ @struct[:chapter]=doc_struct[:chapter] doc_struct[:chapter]=doc_struct[:chapter] + 1 when /^(Section|SECTION)\b/ @struct[:section]=doc_struct[:section] doc_struct[:section]=doc_struct[:section] + 1 when /^(Article|ARTICLE)\b/ @struct[:article]=doc_struct[:article] doc_struct[:article]=doc_struct[:article] + 1 when /^(Clause|CLAUSE)\b/ @struct[:clause]=doc_struct[:clause] doc_struct[:clause]=doc_struct[:clause] + 1 when /^\d\..*[^\.]$/ @struct[:number]=doc_struct[:number] doc_struct[:number]=doc_struct[:number] + 1 end end end if doc_struct[:article] > 2 #%~level 4 @lv4=/^(?:Article|ARTICLE)\b/ elsif doc_struct[:chapter] > 2 \ and doc_struct[:article] \ and doc_struct[:article] < 3 @lv4=/^(?:Chapter|CHAPTER)\b/ elsif doc_struct[:clause] > 2 @lv4=/^(?:Clause|CLAUSE)\b/ elsif doc_struct[:number] > 2 @lv4="^\d\..*[^\.]$" end if doc_struct[:section] > 2 #%~level 3 @lv3=/^(?:Section|SECTION)\b/ end if doc_struct[:chapter] > 2 \ and doc_struct[:article] \ and doc_struct[:article] > 2 @lv2=/^(?:Chapter|CHAPTER)\b/ end if doc_struct[:part] > 2 \ and @lv[2].nil? @lv2=/^(?:Part|PART)\b/ end if doc_struct[:part] > 2 \ and @lv[2].inspect !~/Part/ \ and @lv[1].nil? @lv1=/^(Part|PART)\b/ end end @lnk=@lnk.compact if @lnk @lv1 ||=/^1~/ @lv2 ||=/^2~/ @lv3 ||=/^3~/ @lv4 ||=/^4~/ @lv5 ||=/^5~/ @lv6 ||=/^6~/ if @doc_skin tell=SiSU_Screen::Ansi.new(@cmd,"doc_skin <- #{@doc_skin}") tell.txt_grey if @cmd =~/v/ end @data=nil #else whole file's contents are stored in md pstore & is not required to be... big waste actually Store.new(self,@env).store #% pstore self end private class Store def initialize(md,env) @md=md @pstorefile="#{env.path.dal}/#{md.fns}.pstore" end def store File.unlink(@pstorefile) if FileTest.file?(@pstorefile) tell=SiSU_Screen::Ansi.new(@md.cmd,"PStore -> #{@pstorefile}") tell.txt_grey if @md.cmd =~/v/ store=PStore.new(@pstorefile) store.transaction do store['md']=@md store.commit end @@md=@md=nil end end end end class Instantiate def param_instantiate @@date=SiSU_Env::Info_date.new @@symlnk=SiSU_Env::Create_system_link.new @@proc=@@filename_txt=@@filename_texinfo=@@filename_lout_portrait=@@filename_lout_landscape=@@filename_html_scroll=@@filename_html_index=@@filename_html_segtoc=@@filename_semantic=@@filename_rss=@@newfile=@@drr=nil @doc={ :initialise=>nil, :markup=>'',:lnks=>'',:stmp=>'',:prefix_a=>'',:prefix_b=>'', :req=>{} } @@yaml=@@yamladdr=nil @@flag={} @@publisher='SiSU scribe' end end end __END__