From 64e5c9120ffb7a65b96eded0850f481e116f1d3f Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 8 Aug 2014 00:16:16 -0400 Subject: v6: use opt.act, code internals (simplify, cleaner; remove opt.cmd & opt.mod) * v5 dp, indentation changed to retain easy comparison with v6 --- lib/sisu/v5/dp.rb | 1045 +++++++++++++++++++++++++++-------------------------- 1 file changed, 524 insertions(+), 521 deletions(-) (limited to 'lib/sisu/v5') diff --git a/lib/sisu/v5/dp.rb b/lib/sisu/v5/dp.rb index eb9de5e6..0dde14b8 100644 --- a/lib/sisu/v5/dp.rb +++ b/lib/sisu/v5/dp.rb @@ -926,563 +926,566 @@ module SiSU_Param end #protected 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::InfoSettings.new - @sys=SiSU_Env::SystemCall.new - @env=SiSU_Env::InfoEnv.new(@fns) #watch - if (@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - puts 'system locale: ' + @sys.locale - end - 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,@opt.cmd) - # programs set here for things that affect output appearance only - @programs[:pdf]=SiSU_Env::SystemCall.new.program_found?('pdflatex') - if @opt.cmd =~/P/ #if @env.multilingual? - m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/ #watch added match for sss - @fnn,@fnb,@fnt=@fns[m,1],@fns[m,2],@fns[m,3] - @flv=@env.document_language_versions_found[:f] - else - m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm)$/ #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.txz') : (@fnn + '.sst.txz') - 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$/ \ - and not @opt.cmd =~/P/ #watch - @env_out_root=@env.path.output - @dir_out="#{@env.path.output}/#{@fnb}" - @dir_tex=@env.processing_path.tex - @dir_lout=@env.processing_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(/_/,'\_\-').gsub(/\./,'.\-') - @flag_endnotes,@flag_auto_endnotes,@flag_separate_endnotes=false,false,false - @flag_separate_endnotes_make=true - ver=SiSU_Env::InfoVersion.instance - @sisu_version=ver.get_version - @ruby_version=ver.rbversion - @generated=Time.now - fns_array=@data.dup - skip unless fns_array # consider - @code_flag=false - fns_array.each do |para| #% scan document - if para !~/^%+\s/ \ - and para =~/ @env.concord_max) ? false : true + @locale=@sys.locale + @file_encoding=@sys.file_encoding(fns,@opt.cmd) + # programs set here for things that affect output appearance only + @programs[:pdf]=SiSU_Env::SystemCall.new.program_found?('pdflatex') + if @opt.cmd =~/P/ #if @env.multilingual? + m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/ #watch added match for sss + @fnn,@fnb,@fnt=@fns[m,1],@fns[m,2],@fns[m,3] + @flv=@env.document_language_versions_found[:f] + else + m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm)$/ #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.txz') : (@fnn + '.sst.txz') + 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$/ \ + and not @opt.cmd =~/P/ #watch + @env_out_root=@env.path.output + @dir_out="#{@env.path.output}/#{@fnb}" + @dir_tex=@env.processing_path.tex + @dir_lout=@env.processing_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(/_/,'\_\-').gsub(/\./,'.\-') + @flag_endnotes,@flag_auto_endnotes,@flag_separate_endnotes=false,false,false + @flag_separate_endnotes_make=true + ver=SiSU_Env::InfoVersion.instance + @sisu_version=ver.get_version + @ruby_version=ver.rbversion + @generated=Time.now + fns_array=@data.dup + skip unless fns_array # consider + @code_flag=false + fns_array.each do |para| #% scan document + if para !~/^%+\s/ \ + and para =~/|

|
|
)\s*/,' '). + gsub(/~\{.+?\}~/,'') + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'Document Parameters', + %{#{title}#{creator}} + ).txt_grey if @opt.act[:verbose][:set]==:on end - l_4=if defined? @make.headings[0][4] \ - and @make.headings[0][4] =~/\S+/ - "|^#{@make.headings[0][4]}" + if not @book_idx \ + and para =~/^=\{(.+?)\}[\s`]*\Z/m + @book_idx=true end - l_5=if defined? @make.headings[0][5] \ - and @make.headings[0][5] =~/\S+/ - "|^#{@make.headings[0][5]}" + 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/ then @en[:note] +=1 #% processing + end end - end - case para - #when /^:?A~/ - when /^:?B~#{l_0}/ - @lvs[1]=1 - when /^:?C~#{l_1}/ - @lvs[2]=1 - when /^:?D~#{l_2}/ - @lvs[3]=1 - when /^1~#{l_3}/ - @lvs[4]=1 - when /^2~#{l_4}/ - @lvs[5]=1 - when /^3~#{l_5}/ - @lvs[6]=1 - end - if para =~ /^:?A~/ #% processing - if not defined? @title.full.nil? - tf=para[/^:A~\S*(.+)$/m,1] - tf="@title: #{tf}" - @title=SiSU_Param::Parameters::Md.new(tf.strip,@opt,@env).title + if para =~/~\{|\^~ |~\^|\{.+?\[[1-6]\]\}\S+?\.ss[tm]/m + @flag_auto_endnotes,@flag_endnotes=true,true end - creator=(@creator.is_a?(SiSU_Param::Parameters::Md) \ - && defined? @creator.author \ - && @creator.author.is_a?(String)) \ - ? " #{@creator.author}" - : '' - title=@title.full.gsub(/\s*(?:

|

|
|
)\s*/,' '). - gsub(/~\{.+?\}~/,'') - SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - 'Document Parameters', - %{#{title}#{creator}} - ).txt_grey if @opt.act[:verbose][:set]==:on - end - if not @book_idx \ - and para =~/^=\{(.+?)\}[\s`]*\Z/m - @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/ then @en[:note] +=1 #% processing + if para =~/^(?:table\{|\{table)/i + @flag_tables=true end end - if para =~/~\{|\^~ |~\^|\{.+?\[[1-6]\]\}\S+?\.ss[tm]/m - @flag_auto_endnotes,@flag_endnotes=true,true + if para =~/^:?A~/ + @set_heading_top=true end - if para =~/^(?:table\{|\{table)/i - @flag_tables=true + 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 - 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 + para=para.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image) + if para !~/^%+\s/ \ + and para =~@rgx_image + @ec[:image] << para.scan(@rgx_image).uniq end - unless @heading_seg_first_flag # extract first segment name - @heading_seg_first=t - @heading_seg_first_flag=true + @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 - 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 #% here endeth the document loop + unless @make + if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + '@make:', + 'header absent' + ).warn end + @make=SiSU_Param::Parameters::MdMake.new('@make: ',@opt,@env).make end - para=para.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image) - if para !~/^%+\s/ \ - and para =~@rgx_image - @ec[:image] << para.scan(@rgx_image).uniq + if @cover_image \ + and @cover_image.is_a?(Hash) \ + and (@cover_image[:cover] =~@rgx_image \ + or @cover_image[:cover] =~/\S+?.(?:jpg|png|gif)/) + @ec[:image] << @cover_image[:cover] 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 + if @home_button_image \ + and @home_button_image.is_a?(Hash) \ + and (@home_button_image =~@rgx_image \ + or @home_button_image =~/\S+?\.(?:jpg|png|gif)/) + @ec[:image] << @home_button_image end - end #% here endeth the document loop - unless @make - if (@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - '@make:', - 'header absent' - ).warn + if @ec[:image].length > 0 + @ec[:image]=@ec[:image].flatten.uniq + @ec[:image].delete_if {|x| x =~/https?:\/\// } + @ec[:image]=@ec[:image].sort end - @make=SiSU_Param::Parameters::MdMake.new('@make: ',@opt,@env).make - end - if @cover_image \ - and @cover_image.is_a?(Hash) \ - and (@cover_image[:cover] =~@rgx_image \ - or @cover_image[:cover] =~/\S+?.(?:jpg|png|gif)/) - @ec[:image] << @cover_image[:cover] - end - if @home_button_image \ - and @home_button_image.is_a?(Hash) \ - and (@home_button_image =~@rgx_image \ - or @home_button_image =~/\S+?\.(?:jpg|png|gif)/) - @ec[:image] << @home_button_image - end - if @ec[:image].length > 0 - @ec[:image]=@ec[:image].flatten.uniq - @ec[:image].delete_if {|x| x =~/https?:\/\// } - @ec[:image]=@ec[:image].sort - end - @ec[:audio]=@ec[:audio].uniq.flatten.sort - @ec[:multimedia]=@ec[:multimedia].uniq.flatten.sort - unless @rights - if defined? @creator.author \ - and @creator.author.is_a?(String) \ - and defined? @date.published \ - and @date.published.is_a?(String) - @rights=SiSU_Param::Parameters::MdDefault.new.rights(@creator.author,@date.published) - elsif defined? @creator.author \ - and @creator.author.is_a?(String) - @rights=SiSU_Param::Parameters::MdDefault.new.rights("[#{@creator.author}]",'') + @ec[:audio]=@ec[:audio].uniq.flatten.sort + @ec[:multimedia]=@ec[:multimedia].uniq.flatten.sort + unless @rights + if defined? @creator.author \ + and @creator.author.is_a?(String) \ + and defined? @date.published \ + and @date.published.is_a?(String) + @rights=SiSU_Param::Parameters::MdDefault.new.rights(@creator.author,@date.published) + elsif defined? @creator.author \ + and @creator.author.is_a?(String) + @rights=SiSU_Param::Parameters::MdDefault.new.rights("[#{@creator.author}]",'') + end end - end - if defined? @classify.topic_register \ - and @classify.topic_register.is_a?(String) \ - and @classify.topic_register.length >3 - topic_register=@classify.topic_register - u=topic_register.scan(/[^;]+/m).sort - v=[] - u.each do |l| - v << l.scan(/[^:]+/m) - end - v.each do |s| - s[-1]=s[-1].scan(/[^|]+/m) if s[-1] =~/[|]/m - @topic_register_array << s - end - @topic_register_array - end - if @i18n - @i18n=@i18n.uniq - @i18n << 'en' unless @i18n.find_index("en") - else - @i18n=[ 'en' ] - end - translated=[] - translate_list=[@pagenew,@pagebreak,@pageline,@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') - # looks like an ok substituion for the above but is not, causes problems, check why - #translate=translate.gsub(/3/,'6'). - # gsub(/2/,'5'). - # gsub(/1/,'4'). - # gsub(/:?C/,'3'). - # gsub(/:?B/,'2'). - # gsub(/:?A/,'1') - translate=(translate =~/^\d+$/) \ - ? translate.to_i - : translate - else nil + if defined? @classify.topic_register \ + and @classify.topic_register.is_a?(String) \ + and @classify.topic_register.length >3 + topic_register=@classify.topic_register + u=topic_register.scan(/[^;]+/m).sort + v=[] + u.each do |l| + v << l.scan(/[^:]+/m) + end + v.each do |s| + s[-1]=s[-1].scan(/[^|]+/m) if s[-1] =~/[|]/m + @topic_register_array << s + end + @topic_register_array end - end - @pagenew,@pagebreak,@pageline,@num_top,@toc_lev_limit=translated - @markup=@markup.gsub(/page_new\s*=\s*([\dA-C])/,"page_new=#{@pagenew}"). - gsub(/page_break\s*=\s*([\dA-C])/,"page_break=#{@pagebreak}"). - gsub(/page_line\s*=\s*([\dA-C])/,"page_line=#{@pageline}"). - gsub(/num_top\s*=\s*([\dA-C])/,"num_top=#{@num_top}"). - gsub(/toc_lev_limit\s*=\s*([\dA-C])/,"toc_lev_limit=#{@toc_lev_limit}") - papersize_array_rc=@papersize.downcase.scan(/(?:a4|letter|legal|book|a5|b5)/) - papersize_array_opt=[ - ((@opt.act[:pdf_a4][:set]==:on) ? 'a4' : ''), - ((@opt.act[:pdf_a5][:set]==:on) ? 'a5' : ''), - ((@opt.act[:pdf_b5][:set]==:on) ? 'b5' : ''), - ((@opt.act[:pdf_letter][:set]==:on) ? 'letter' : ''), - ((@opt.act[:pdf_legal][:set]==:on) ? 'legal' : ''), - ] - [""] - @papersize_array=(papersize_array_opt.length > 0) \ - ? papersize_array_opt - : papersize_array_rc - fn=@opt.fno #decide what to do a filesize on .ssm tells very little about actual document size - @filesize=(File.size(fn)).to_s - if @sys.openssl !=false \ - and FileTest.file?(@env.source_file_with_path) - @dgst=[] - case @env.digest(@opt).type - when :sha512 - dgst=@sys.sha512(@env.source_file_with_path) - @dgst=dgst[1].length==128 ? dgst : nil - puts 'check document (sha512) digest' if not @dgst - when :sha256 - dgst=@sys.sha256(@env.source_file_with_path) - @dgst=dgst[1].length==64 ? dgst : nil - puts 'check document (sha256) digest' if not @dgst - when :md5 - dgst=@sys.md5(@env.source_file_with_path) - @dgst=dgst[1].length==32 ? dgst : nil - puts 'check document (md5) digest' if not @dgst + if @i18n + @i18n=@i18n.uniq + @i18n << 'en' unless @i18n.find_index("en") else - dgst=@sys.sha256(@env.source_file_with_path) - @dgst=dgst[1].length==64 ? dgst : nil - puts 'check document (sha256) digest' if not @dgst + @i18n=[ 'en' ] end - elsif not FileTest.file?(@env.source_file_with_path) - #puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) - end - @publisher ||= "#{@@publisher} (this copy)" - fn_set_lang=SiSU_Env::StandardiseLanguage.new(@opt.lng).language - 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[:n] - end - @fnl=@env.i18n.lang_filename(fn_set_lang[:c]) - @lang=@lang.uniq - @fn=SiSU_Env::EnvCall.new(@fns).lang(fn_set_lang[:c]) - if @en[:note] > 0 \ - and @en[:sum] > 0 - if @en[:sum] > 0 - else - SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - '*WARN* both endnote styles used', - "~{ #{@en[:sum]} }~ and ^~ #{@en[:mark]}" - ).warn unless @opt.act[:quiet][:set]==:on + translated=[] + translate_list=[@pagenew,@pagebreak,@pageline,@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') + # looks like an ok substituion for the above but is not, causes problems, check why + #translate=translate.gsub(/3/,'6'). + # gsub(/2/,'5'). + # gsub(/1/,'4'). + # gsub(/:?C/,'3'). + # gsub(/:?B/,'2'). + # gsub(/:?A/,'1') + translate=(translate =~/^\d+$/) \ + ? translate.to_i + : translate + else nil + end end - end - if @en[:mark] != @en[:note] \ - and @en[:note] > 0 - @en[:mismatch]=@en[:note] - @en[:mark] - SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - '*WARN* endnote number mismatch', - "endnotes: #{@en[:note]} != endnote reference marks: #{@en[:mark]} (difference = #{@en[:mismatch]})" - ).warn unless @opt.act[:quiet][:set]==:on - 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 not @title \ - or not defined? @title.main \ - or @title.main !~/[\S]/ - if @fns =~/\.ssm$/ \ - and @opt.inspect =~/P/ - #@title=Md.new('Text Insert',@opt,@env).title - else - SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - 'WARNING: Document Title missing', - 'please provide @title:' - ).warn unless @opt.act[:quiet][:set]==:on + @pagenew,@pagebreak,@pageline,@num_top,@toc_lev_limit=translated + @markup=@markup.gsub(/page_new\s*=\s*([\dA-C])/,"page_new=#{@pagenew}"). + gsub(/page_break\s*=\s*([\dA-C])/,"page_break=#{@pagebreak}"). + gsub(/page_line\s*=\s*([\dA-C])/,"page_line=#{@pageline}"). + gsub(/num_top\s*=\s*([\dA-C])/,"num_top=#{@num_top}"). + gsub(/toc_lev_limit\s*=\s*([\dA-C])/,"toc_lev_limit=#{@toc_lev_limit}") + papersize_array_rc=@papersize.downcase.scan(/(?:a4|letter|legal|book|a5|b5)/) + papersize_array_opt=[ + ((@opt.act[:pdf_a4][:set]==:on) ? 'a4' : ''), + ((@opt.act[:pdf_a5][:set]==:on) ? 'a5' : ''), + ((@opt.act[:pdf_b5][:set]==:on) ? 'b5' : ''), + ((@opt.act[:pdf_letter][:set]==:on) ? 'letter' : ''), + ((@opt.act[:pdf_legal][:set]==:on) ? 'legal' : ''), + ] - [""] + @papersize_array=(papersize_array_opt.length > 0) \ + ? papersize_array_opt + : papersize_array_rc + fn=@opt.fno #decide what to do a filesize on .ssm tells very little about actual document size + @filesize=(File.size(fn)).to_s + if @sys.openssl !=false \ + and FileTest.file?(@env.source_file_with_path) + @dgst=[] + case @env.digest(@opt).type + when :sha512 + dgst=@sys.sha512(@env.source_file_with_path) + @dgst=dgst[1].length==128 ? dgst : nil + puts 'check document (sha512) digest' if not @dgst + when :sha256 + dgst=@sys.sha256(@env.source_file_with_path) + @dgst=dgst[1].length==64 ? dgst : nil + puts 'check document (sha256) digest' if not @dgst + when :md5 + dgst=@sys.md5(@env.source_file_with_path) + @dgst=dgst[1].length==32 ? dgst : nil + puts 'check document (md5) digest' if not @dgst + else + dgst=@sys.sha256(@env.source_file_with_path) + @dgst=dgst[1].length==64 ? dgst : nil + puts 'check document (sha256) digest' if not @dgst + end + elsif not FileTest.file?(@env.source_file_with_path) + #puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) end - end - if @author !~/[\S]/ - if @fns =~/\.ssm$/ \ - and @opt.inspect =~/P/ - #@creator=SiSU_Param::Md.new('Text Insert',@opt,@env).creator - else + @publisher ||= "#{@@publisher} (this copy)" + fn_set_lang=SiSU_Env::StandardiseLanguage.new(@opt.lng).language + 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[:n] + end + @fnl=@env.i18n.lang_filename(fn_set_lang[:c]) + @lang=@lang.uniq + @fn=SiSU_Env::EnvCall.new(@fns).lang(fn_set_lang[:c]) + if @en[:note] > 0 \ + and @en[:sum] > 0 + if @en[:sum] > 0 + else + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + '*WARN* both endnote styles used', + "~{ #{@en[:sum]} }~ and ^~ #{@en[:mark]}" + ).warn unless @opt.act[:quiet][:set]==:on + end + end + if @en[:mark] != @en[:note] \ + and @en[:note] > 0 + @en[:mismatch]=@en[:note] - @en[:mark] SiSU_Screen::Ansi.new( @opt.act[:color_state][:set], - 'WARNING: Document Author missing', - 'please provide @creator: :author:' + '*WARN* endnote number mismatch', + "endnotes: #{@en[:note]} != endnote reference marks: #{@en[:mark]} (difference = #{@en[:mismatch]})" ).warn unless @opt.act[:quiet][:set]==:on + 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 - 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 + if not @title \ + or not defined? @title.main \ + or @title.main !~/[\S]/ + if @fns =~/\.ssm$/ \ + and @opt.inspect =~/P/ + #@title=Md.new('Text Insert',@opt,@env).title + else + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'WARNING: Document Title missing', + 'please provide @title:' + ).warn unless @opt.act[:quiet][:set]==:on 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/ + if @author !~/[\S]/ + if @fns =~/\.ssm$/ \ + and @opt.inspect =~/P/ + #@creator=SiSU_Param::Md.new('Text Insert',@opt,@env).creator + else + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'WARNING: Document Author missing', + 'please provide @creator: :author:' + ).warn unless @opt.act[:quiet][:set]==:on + end end - if doc_struct[:part] > 2 \ - and @lv[2].inspect !~/Part/ \ - and @lv[1].nil? - @lv1=/^(Part|PART)\b/ + @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 + @lv0 ||=/^0~/ + @lv1 ||=/^1~/ + @lv2 ||=/^2~/ + @lv3 ||=/^3~/ + @lv4 ||=/^4~/ + @lv5 ||=/^5~/ + @lv6 ||=/^6~/ + @data=nil #else whole file's contents are stored in md pstore & is not required to be... big waste actually + @file=SiSU_Env::FileOp.new(self) #watch + Store.new(self,@env).store #% pstore + self + rescue end - @lnk=@lnk.compact if @lnk - @lv0 ||=/^0~/ - @lv1 ||=/^1~/ - @lv2 ||=/^2~/ - @lv3 ||=/^3~/ - @lv4 ||=/^4~/ - @lv5 ||=/^5~/ - @lv6 ||=/^6~/ - @data=nil #else whole file's contents are stored in md pstore & is not required to be... big waste actually - @file=SiSU_Env::FileOp.new(self) #watch - Store.new(self,@env).store #% pstore - self end private class Store -- cgit v1.2.3