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/param.rb | 104 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 31 deletions(-) (limited to 'lib/sisu/v0/param.rb') 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 -- cgit v1.2.3