=begin * Name: SiSU * Description: a framework for document structuring, publishing and search * Author: Ralph Amissah * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Ralph Amissah All Rights Reserved. * License: GPL 3 or later: SiSU, a framework for document structuring, publishing and search Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 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: texinfo processing =end module SiSU_TexInfo require "#{SiSU_lib}/html" require "#{SiSU_lib}/param" include SiSU_Param include SiSU_Viz #include Stamp ... needed removed arbitrarily 2005w05/1 (warnings about undefined flags) require "#{SiSU_lib}/texinfo_format" include TexInfoFormat @tex_file=[] @@tex_backslash="\\\\" @@tabular="{tabular}" @@table_pagebreak_counter,@@tex_endnote_call_counter,@@tex_table_flag,@@tex_counter,@@tex_column,@@tex_columns,@@counting=0,0,0,0,0,0,0 @@column_instruct,@@tex_line_mode,@@tex_word_mode,@@start_table,@@line_mode='','','','','' @@n,@@copyright,@@tableheader=nil,nil,nil @@tex_col_w=[] @@tex_pattern_margin_number="\\\\marginpar.+?\s+" class Source #Songsheet include SiSU_Param include SiSU_Viz include SiSU_TexInfo def initialize(opt) @opt=opt @env=SiSU_Env::Info_env.new(@opt.fns) @st={ 'tex'=>{} } @tex=TexInfoFormat::Texinfo.new @vz=SiSU_Env::Get_init.instance.skin end def directories begin case @opt.fns when /\.(?:-|ssm\.)?sst$/ Dir.mkdir(@env.path.output) unless FileTest.directory?("#{@env.path.output}") Dir.mkdir(@env.path.texi) unless FileTest.directory?(@env.path.tex) @@filename_texinfo=File.new(%{#{@env.path.texi}/#{@opt.fnb}.texinfo},'w+') end rescue; STDERR.puts SiSU_Screen::Ansi.new(@opt.cmd,$!,$@).rescue ensure end end def read songsheet end def songsheet begin tell=SiSU_Screen::Ansi.new(@opt.cmd,'TexInfo') tell.green_title_hi unless @opt.cmd =~/q/ data=IO.readlines(@opt.fns,'') @md=SiSU_Param::Parameters.new(@opt).get puts "\t#{@@cX.grey}TexInfo#{@@cX.off}" my_make=SiSU_Env::Create_file.new(@opt.cmd,@opt.fns) directories @marshalfile=my_make.marshal_meta if FileTest.file?(@marshalfile)==true File.open(@marshalfile) { |f| @@tuned_file=Marshal.load(f)} tell.meta_verse_skipped unless @opt.cmd =~/q/ else tex_array=IO.readlines(@opt.fns,'') SiSU_Metaverse.songsheet(tex_array) end tex_array=@@tuned_file Texinfo_make.new(tex_array,@md).songsheet tex_array='' @@filename_texinfo=nil rescue; STDERR.puts SiSU_Screen::Ansi.new(@opt.cmd,$!,$@).rescue ensure @@filename_texinfo.close if @@filename_texinfo end end end class Texinfo_make include SiSU_Param include TexInfoFormat @@tex_1='(?:.+?)+~' #?? debug @@tabular="{tabular}" @@tex_pattern_margin_number="\\\\marginpar.+?\s+" @@dp=nil def initialize(data,md) @data,@md=data,md #fns @env=SiSU_Env::Info_env.new(@md.fns) @st={ 'tex'=>{} } #@tex=TexInfoFormat::Texinfo.new @vz=SiSU_Env::Get_init.instance.skin @dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern end def songsheet begin @data=pre @data=endnote @data=markup @data=tail output makeinfo rescue; STDERR.puts SiSU_Screen::Ansi.new(@md.cmd,$!,$@).rescue ensure end end def pre @tex_file=[] data=@data data.each do |para| # DEBUG 2003w16 this is a kludge, because i could not get parameters # from param, Sort out ... revert to more elegant solution if para =~ //,'') para.gsub!(/(^|\s)\{(.+?)\}((?:https?|file):\/\/\S+)/,'\1(\2 [linked to:] \3)') do_mono=TexInfoFormat::Texinfo.new(para,@md) @tex_file << do_mono.spec_char end data=@tex_file.delete_if {|x| x =~ /^0(?:\\)+~/m} data=@tex_file # ... end def endnote data=@data @tex_file=[] data.each do |para| # BUG bug -> have problems with endnotes in headers if para =~ /\\~@\{\d+\s+/ #if para =~ /@\}\\~/m,' @footnote{ \1} ') elsif para =~ /\\~@\{\*+\s+/ #if para =~ /@\}\\~/m,' @footnote{ \1} ') end @tex_file << para end @tex_file end def poem data=@data @tex_file=[] @@counting=0 data.each do |para| if para =~ /<:code>/ @@flag['code']=true @@counting=1 end if para =~ /<:verse>/ @@flag['poem']=1 end if @@flag['code'] if @@flag['code'] \ and para =~ /<:code[-_](?:end|close)>/ #watch change not tested 200501 @@flag['code']=false end if @@flag['code'] \ and para =~ /\S/ sub_array=para.dup @@line_mode=sub_array.scan(/.+/) Tune.code_lines(@@line_mode) para=@@line_mode.join end elsif @@flag['poem']==1 if @@flag['poem']==1 \ and para =~ /<:verse[-_](?:end|close)>/ #watch change not tested 200501 @@flag['poem']=0 end if @@flag['poem']==1 \ and para =~ /\S/ sub_array=para.dup @@line_mode=sub_array.scan(/.+/) Tune.code_lines(@@line_mode) para=@@line_mode.join end end @tex_file << para end end def code_lines data=@data data.each do |line| if line =~ /\S/ \ and line !~ /<:(code|verse).+/ if @@flag['code'] line.gsub!(/^\s*(.+)/m, "\\noindent \\marginpar\[left-text\]{\\begin{tiny}#{@@counting}\\end{tiny}}\\1\\") @@counting+=1 if @@flag['code'] else line.gsub!(/(.+)/m,'\noindent\1') end end end end def tables data=@data @tex_file=[] @@tableheader=0 data.each do |para| if para =~ /¡|\s*/,' ') if para =~ /^[1-3]\\+~\S*(.+?)\s*$/ toc=TexInfoFormat::Texinfo.new($1,@md) texinfo_menu << toc.menu elsif para =~ /^[4-6]\\+~(?:\S+)?\s+(.+?)\s*$/ toc=TexInfoFormat::Texinfo.new($1,@md) texinfo_menu << toc.menu case para when /^[4]\\+~\S+\s+(.+?)\s*$/ n_menu+=1 @submenu[n_menu]=[] when /^[5]\\+~\S+\s+(.+?)\s*$/ n_submenu+=1 @subsubmenu[n_menu]=[] @submenu[n_menu] << toc.menu when /^[6]\\+~\S+\s+(.+?)\s*$/ n_submenu+=1 @subsubmenu[n_submenu]=[] @subsubmenu[n_submenu] << toc.menu end else #para.gsub!(/\s*(?:<:?br>|
)\s*/,"\n#@row_break ") para.gsub!(/\s*(?:<:?br>|
)\s*/,"\n\n") end end texinfo_menu.compact! texinfo_menu << "* Dublin Core::" @tex_file << texinfo_menu @tex_file << "* Index::\n" + "@end menu\n\n" + "@c %% 5\n\n" n_menu,n_submenu=0,0 @@do_submenu,@@do_subsubmenu=1,1 data.each do |para| mono=TexInfoFormat::Texinfo.new(para,@md) case para when /^1\\+/; mono.level1 when /^2\\+/; mono.level2 when /^3\\+/; mono.level3 when /^4\\+~/ mono.level4 n_menu+=1 @@do_submenu,@@do_subsubmenu=1,1 when /^5\\+/ n_submenu+=1 @@do_subsubmenu=1 if @@do_submenu==1 menu=TexInfoFormat::Texinfo.new(@submenu[n_menu],@md) para="#{menu.submenu}#{mono.level5}" @@do_submenu=0 else mono.level5 end when /^6\\+/ if @@do_submenu==1 menu=TexInfoFormat::Texinfo.new(@subsubmenu[n_menu],@md) para="#{menu.subsubmenu}#{mono.level6}" @@do_subsubmenu=0 else mono.level6 end # when /^/ # mono.indent1 # when /^/ # mono.indent2 # when /<#@dp:#@dp>$/,'<\1>') #para.gsub!(/<\\~(\d+);\w\d+;\w\d+><#@dp:#@dp>/,'<\1>') #para.gsub!(/<\\~(\d+);\w\d+;\w\d+><#@dp:#@dp>/,'<\1>') para end end #%case with endnotes para.gsub!(/\s*[0-8]\\+(\S+)?\s+/,' ') if para @tex_file << para if para end data=@tex_file end def numbering data=@data data=Texinfo_make.new(data,@md).number_titles #TOGGLE to SWITCH PARAGRAPH NUMBERING (ON & OFF) data=Texinfo_make.new(data,@md).number_paras \ if @md.fns !~ /\.e[pdr]00/ \ and @md.markup !~ /not_to/i end def number_titles data=@data @tex_file=[] input=%{#{@md.markup}}[/(num_top\s*=\s*(\d?))?/m,2] # else default usually 4 # this was a bit of a trick required to pass nil to input if nothing matched... #puts input #input=/(num_top\s*=\s*(\d?))?/m.match(@md[:markup]) [2] # else default usually 4 # this was a bit of a trick required to pass nil to input if nothing matched... #puts input num_top=input.to_i t_no1=0; t_no2=0; t_no3=0; t_no4=0; no1=num_top; no2=(num_top + 1); no3=(num_top + 2); no4=(num_top + 3); data.each do |para| if @md.markup =~ /num_top/i \ and para !~ /0\\+/ if para =~ /^[1-6]\\+(?:~\S+)?\s*/ \ and para !~ /<:\d-endnotes>/ header=para[//m, 1].gsub!(/-/m,'.') para.gsub!(/^(?:[1-6]\\+(?:~\S+)|<:([12356]|4-.+?-)>)\s*/, "\\1 #{header} ") end elsif para =~ /|||/ if para =~ // para.gsub!(//,'\1 ') end end @tex_file << para end data=@tex_file end def number_paras data=@data @tex_file=[] paranumber=0 data.each do |para| if para =~/<\\~(\d+);\w\d+;\w\d+><#@dp:#@dp>/ \ and para !~ // parablock,paranum=/(.+?)<\\~(\d+);\w\d+;\w\d+><#@dp:#@dp>/im.match(para)[1,2] do_duo=TexInfoFormat::DuoTex.new(parablock,paranum) ###is BUG para=do_duo.paraNum if parablock end @tex_file << para end data=@tex_file end def tail data=@data tex=TexInfoFormat::Texinfo.new('',@md) data << tex.dublincore data << tex.tail end def output data=@data data.compact! data.each {|para| (@@filename_texinfo.puts para,"\n") if para} @@filename_texinfo.close end def makeinfo if @md.fns =~/\.(?:-|ssm\.)?sst$/ m=/(.+?)\.([_-]?sst)$/.match(@md.fns) fnb,sfx=m[1],m[2] pwd=Dir.pwd case sfx when /(?:-|ssm\.)?sst$/ @env=SiSU_Env::Info_env.new(@md.fns,@md.cmd) Dir.chdir(@env.path.texi) texinfo=SiSU_Env::System_call.new("#{fnb}.texinfo") texinfo.makeinfo end Dir.chdir(pwd) end end end end __END__