From 8e092e0f3acc154f60f296419d1fab4d59f65e53 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 15 Oct 2007 19:22:03 +0100 Subject: regex matching of images, (and rearrangement of conditionals) --- lib/sisu/v0/composite.rb | 7 +-- lib/sisu/v0/param.rb | 104 +++++++++++++++++++++++++++++++------------- lib/sisu/v0/remote.rb | 8 ++-- lib/sisu/v0/sisupod_make.rb | 23 ++++++---- 4 files changed, 97 insertions(+), 45 deletions(-) diff --git a/lib/sisu/v0/composite.rb b/lib/sisu/v0/composite.rb index 4768522a..ebad049e 100644 --- a/lib/sisu/v0/composite.rb +++ b/lib/sisu/v0/composite.rb @@ -148,8 +148,8 @@ module SiSU_Assemble end def insertion(fni,insert_array) file={ :prepared=>[],:images=>[] } - rgx_image=/([a-zA-Z0-9._-]+?\.(?:png|jpg|gif))/ - #file[:prepared] << "#% Date " << "\n" + rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ + #rgx_image=/([a-zA-Z0-9._-]+?\.(?:png|jpg|gif))/ file[:prepared] << "\n% |#{fni}|@|^|>>ok\n" @code_flag=false insert_array.each do |i| @@ -202,7 +202,8 @@ module SiSU_Assemble @@imager[image_uri] ||=[] @@imager[image_uri] << file[:images] file[:prepared] - elsif loadfile =~ /\.ss[ti]$/ and FileTest.file?(loadfile) + elsif loadfile =~ /\.ss[ti]$/ \ + and FileTest.file?(loadfile) insert_array=IO.readlines(loadfile,'') file=insertion(loadfile,insert_array) file[:prepared] diff --git a/lib/sisu/v0/param.rb b/lib/sisu/v0/param.rb index fec253d0..8a95942a 100644 --- a/lib/sisu/v0/param.rb +++ b/lib/sisu/v0/param.rb @@ -88,7 +88,8 @@ module SiSU_Param @@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 @@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' retrieve_store=PStore.new(@pstorefile) @@ -127,7 +128,7 @@ module SiSU_Param @markup=@markup_instruction #use @markup_instruction @doc,@fn,@make_italic,@make_bold,@tag_hash,@ec={},{},{},{},{},{},{} @flv,@lang,@seg_names,@tags,@tag_array,@tag_a,@ec[:image],@ec[:audio],@ec[:multimedia]=Array.new(9){[]} - @rgx_image=/\{\s*(\S+?\.(?:png|jpg|gif))/ + @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ @rgx_audio=/\{\s*(\S+?\.(?:mp3|ogg))/ @rgx_mm=/\{\s*(\S+?\.(?:ogg|mpeg))/ #expand and distinguish ogg begin @@ -153,7 +154,8 @@ module SiSU_Param @prog=SiSU_Env::Info_settings.new @sys=SiSU_Env::System_call.new @env=SiSU_Env::Info_env.new(@fns) #watch - if @prog.wc and @sys.wc + 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 @@ -226,9 +228,12 @@ module SiSU_Param end 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 + 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 + 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 @@ -248,7 +253,8 @@ module SiSU_Param end @code_flag=false fns_array.each do |para| #% Scan document - if para !~/^\%+\s/ and para =~/= 0.38) or (para=~/^1~/ and @markup_version < 0.38) + 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(/(

|

|
|
)/,'') @@ -580,15 +596,25 @@ module SiSU_Param if para =~/table\{|/i; @flag_tables=true end end - if (@markup_version >= 0.38 and para =~/^:?A~/) or (@markup_version < 0.38 and para =~/^1~/) + if (@markup_version >= 0.38 and para =~/^:?A~/) \ + or (@markup_version < 0.38 and para =~/^1~/) @set_heading_top=true end - if (@markup_version >= 0.38 and para =~/^1~/) or (@markup_version < 0.38 and para =~/^4~/) + if (@markup_version >= 0.38 and para =~/^1~/) \ + or (@markup_version < 0.38 and para =~/^4~/) m=nil - if @markup_version >= 0.38 and para =~/^1~(\S+)\s+(.+)$/; m,t=$1,$2 - elsif @markup_version < 0.38 and para =~/^4~(\S+)\s+(.+)$/; m,t=$1,$2 - elsif @markup_version >= 0.38 and para =~/^1~\s+(.+)$/; t=$1 - elsif @markup_version < 0.38 and para =~/^4~\s+(.+)$/; t=$1 + if @markup_version >= 0.38 \ + and para =~/^1~(\S+)\s+(.+)$/ + m,t=$1,$2 + elsif @markup_version < 0.38 \ + and para =~/^4~(\S+)\s+(.+)$/ + m,t=$1,$2 + elsif @markup_version >= 0.38 \ + and para =~/^1~\s+(.+)$/ + t=$1 + elsif @markup_version < 0.38 \ + and para =~/^4~\s+(.+)$/ + t=$1 end unless @heading_seg_first_flag # extract first segment name @heading_seg_first=t @@ -597,7 +623,10 @@ module SiSU_Param if m # list all segment names @seg_names << m @set_heading_seg=true - @seg_autoname_safe=false if m=~/^\d{1,3}/ and m !~/^0/ + if m=~/^\d{1,3}/ \ + and m !~/^0/ + @seg_autoname_safe=false + end end end @ec[:image] << para.scan(@rgx_image).uniq if para =~@rgx_image #embedded content @@ -650,7 +679,8 @@ module SiSU_Param @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 + 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 if @sys.openssl !=false @@ -672,7 +702,8 @@ module SiSU_Param end @dc_publisher ||= "#@@publisher (this copy)" fn_set_lang=SiSU_Env::Standardise_language.new.file_to_language(@fns) - unless @dc_language[:code] and @dc_language[:name] + unless @dc_language[:code] \ + and @dc_language[:name] lang=@env.i18n.language #default language settings for directory by name, or in sysrc.yml @dc_language[:code] ||= lang.code @dc_language[:name] ||= lang.title @@ -694,13 +725,15 @@ module SiSU_Param @lang.uniq! @fn=SiSU_Env::Env_call.new(@fns).lang(fn_set_lang[:c]) @dc_identifier="#{@env.url.root}/#@fnb/#{@fn[:toc]}" #DC note constructed dc identifier - if @en[:note] > 0 and @en[:sum] > 0 + 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 + 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') @@ -718,7 +751,9 @@ module SiSU_Param if @title.nil? title_trigger=nil fns_array.each do |para| - if para !~/0~|@\S+:[+-]?\s/ and para =~/\S/ and title_trigger.nil? + if para !~/0~|@\S+:[+-]?\s/ \ + and para =~/\S/ \ + and title_trigger.nil? @title=para[/(\S.+)/m,1] @html_title=@title.gsub(/(

|

|
|
)/,'') @title.chomp!("\n") @@ -760,7 +795,9 @@ module SiSU_Param 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 + 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/ @@ -770,13 +807,18 @@ module SiSU_Param 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 + 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? + if doc_struct[:part] > 2 \ + and @lv[2].nil? @lv2=/^(?:Part|PART)\b/ end - if doc_struct[:part] > 2 and @lv[2].to_s !~/Part/ and @lv[1].nil? + if doc_struct[:part] > 2 \ + and @lv[2].to_s !~/Part/ \ + and @lv[1].nil? @lv1=/^(Part|PART)\b/ end end diff --git a/lib/sisu/v0/remote.rb b/lib/sisu/v0/remote.rb index 2a45e3cb..efa49dc0 100644 --- a/lib/sisu/v0/remote.rb +++ b/lib/sisu/v0/remote.rb @@ -113,7 +113,7 @@ module SiSU_Remote require 'open-uri' require 'pp' require "#{SiSU_lib}/composite" - @rgx_image=/\{\s*(\S+?\.(?:png|jpg|gif))/ + @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ @rgx_skin=/(?:0~|@)skin:?\s+(\S+)/ #@rgx_skin=/^0~skin\s+(\S+)/ threads=[] for requested_page in @get_s @@ -133,10 +133,12 @@ module SiSU_Remote images << r.scan(@rgx_image).uniq if r =~@rgx_image downloaded_file << r end - if skin and skin.length > 0 + if skin \ + and skin.length > 0 SiSU_Assemble::Remote_image.new.download_doc_skin(skin) end - if images and images.length > 1 + if images \ + and images.length > 1 images.flatten!.uniq! @msg,@msgs='downloading images:', [ images.join(',') ] @tell.call.warn unless @opt.cmd =~/q/ diff --git a/lib/sisu/v0/sisupod_make.rb b/lib/sisu/v0/sisupod_make.rb index 392aee7d..277358c4 100644 --- a/lib/sisu/v0/sisupod_make.rb +++ b/lib/sisu/v0/sisupod_make.rb @@ -158,7 +158,7 @@ module SiSU_Doc end def sisupod_build #see also sisupod in sysenv @rgx_rb_image=/["'](\S+?\.(?:png|jpg|gif))["']/ - @rgx_image=/\{\s*(\S+?\.(?:png|jpg|gif))/ + @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ @rgx_skin=/^(?:@skin:|0~skin)\s+(\S+)/ @rgx_doc_import=/^%\s\s*\|(\S+?\.ss[ti])\|@\|\^\|>>ok/ use_file=if @opt.fns =~/(?:\.ssm|\.ssm\.sst)$/; "#{@env.path.composite_file}/#{@opt.fnb}.ssm.sst" @@ -170,12 +170,14 @@ module SiSU_Doc if f !~/^%\s/ skin << f.scan(@rgx_skin).uniq.flatten if f =~@rgx_skin images << f.scan(@rgx_image).uniq if f =~@rgx_image - elsif f =~/^%\s/ and @opt.fns =~/\.ssm\.sst$/ + elsif f =~/^%\s/ \ + and @opt.fns =~/\.ssm\.sst$/ doc_import << f.scan(@rgx_doc_import).uniq if f =~@rgx_doc_import end end docskin=nil - if skin and skin.length > 0 + if skin \ + and skin.length > 0 docskin=skin.pop.flatten.join skin_source=select(docskin) else @@ -187,8 +189,10 @@ module SiSU_Doc docskin=[docskin_with_path.gsub(/.+?\/(skin_\S+?)\.rb/,'\1')] docskin='skin_sisupod' end - if skin_source and docskin #imperfect, revisit - unless skin_source[:name].nil? or skin_source[:name].empty? + if skin_source \ + and docskin #imperfect, revisit + unless skin_source[:name].nil? \ + or skin_source[:name].empty? cp_r(skin_source[:name],"#{docskin_place}/#{docskin}.rb") skinfile_array=IO.readlines(skin_source[:name],'') para_images=[] @@ -202,7 +206,8 @@ module SiSU_Doc end #1. mapping in doc dir? #2. need images used by skin, scan skin?? - if images and images.length > 1 + if images \ + and images.length > 1 images.flatten!.uniq! image_path_pwd='_sisu/image' path_pod_conf="#{@env.path.processing}/sisupod/_sisu" @@ -228,12 +233,14 @@ module SiSU_Doc end end x=@env.document_language_versions_found #check multiple document language versions (param not used) - if doc_import.flatten.length > 0 and @opt.fns =~/\.ssm\.sst$/ + if doc_import.flatten.length > 0 \ + and @opt.fns =~/\.ssm\.sst$/ doc_import.flatten.each do |f| cp_r("#{@env.path.pwd}/#{f}","#{@env.path.processing}/sisupod/#{f}") end end - if x[:f] and x[:f].length > 1 #store multiple document language versions, sisupod + if x[:f] \ + and x[:f].length > 1 #store multiple document language versions, sisupod x[:f].each do |f| cp_r("#{@env.path.pwd}/#{f}","#{@env.path.processing}/sisupod/#{f}") end -- cgit v1.2.3