diff options
author | Ralph Amissah <ralph.amissah@gmail.com> | 2007-05-22 02:06:46 +0100 |
---|---|---|
committer | Ralph Amissah <ralph.amissah@gmail.com> | 2007-05-22 02:06:46 +0100 |
commit | 65477054fd798728bf186aa2938727ddddbe86a5 (patch) | |
tree | 612da47b57ad4c4157f495dcf10710d32cdc6ead /lib/sisu/0.52/texinfo.rb |
Imported upstream version 0.52.7upstream/0.52.7sisu_0.52.7
Diffstat (limited to 'lib/sisu/0.52/texinfo.rb')
-rw-r--r-- | lib/sisu/0.52/texinfo.rb | 408 |
1 files changed, 408 insertions, 0 deletions
diff --git a/lib/sisu/0.52/texinfo.rb b/lib/sisu/0.52/texinfo.rb new file mode 100644 index 00000000..ca62710b --- /dev/null +++ b/lib/sisu/0.52/texinfo.rb @@ -0,0 +1,408 @@ +=begin + * Name: SiSU information Structuring Universe - Structured information, Serialized Units + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download.html + + * Description: texinfo processing + + * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Ralph Amissah + + * License: GPL 2 or later + + Summary of GPL 2 + + 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 2 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + http://www.fsf.org/licenses/gpl.html + http://www.gnu.org/copyleft/gpl.html + http://www.jus.uio.no/sisu/gpl2.fsf + + SiSU was first released to the public on January 4th 2005 + + SiSU uses: + + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + © Ralph Amissah 1997, current 2007. + All Rights Reserved. + + * Ralph Amissah: ralph@amissah.com + ralph.amissah@gmail.com +=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 /\.[_-]?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}" + #@@copyright="\n #{@@tex_backslash*2}[3]\\ \\linebreak \\copyright \\ #{@md.copyright_tex}" if @md.copyright_tex #appears to be redundant ! remove 2004w19 + if @md.markup.to_s !~ /url_png/ + 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='' + end + #@@filename_texinfo.close if @@filename_texinfo + @@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| + para.gsub!(/&/,'<=and>') + # DEBUG 2003w16 this is a kludge, because i could not get parameters + # from param, Sort out ... revert to more elegant solution + if para =~ /<!Th?¡\s+c/ + @@flag['tables']='y' # KLUDGE get from param + end + para.gsub!(/<:p[bn]>/,'') + 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 =~ /<!e\s+/ # watch + para.gsub!(/\s*\\~\\\{(\d+)\s+(.+?)<#@dp>\\\}\\~/m,' @footnote{ \2} ') + 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']=1 + @@counting=1 + end + if para =~ /<:verse>/ + @@flag['poem']=1 + end + if @@flag['code']==1 + if @@flag['code']==1 and para =~ /<:code[-_](?:end|close)>/ #watch change not tested 200501 + @@flag['code']=0 + end + if @@flag['code']==1 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']==1 + line.gsub!(/^\s*(.+)/m, "\\noindent \\marginpar\[left-text\]{\\begin{tiny}#{@@counting}\\end{tiny}}\\1\\") + @@counting+=1 if @@flag['code']==1 + else line.gsub!(/(.+)/m,'\noindent\1\') + end + end + end + end + def tables + data=@data + @tex_file=[] + @@tableheader=0 + data.each do |para| + if para =~ /¡|<!T/i + do_mono=TexInfoFormat::Texinfo.new(para,@md) + para=do_mono.longtable # using longtable latex package + end + @tex_file << para + end + end + def markup + data=@data + @tex_file=[] + md={} + @tex_file << TexInfoFormat::Texinfo.new('',@md).head + mono=TexInfoFormat::Texinfo.new(@md.title,@md) + @tex_file << mono.topnode + texinfo_menu=[] + n_menu,n_submenu=0,0 + @submenu,@subsubmenu={},{} + data.each do |para| + if para =~ /^[1-3]\\+~\S*(.+?)\s*$/ + toc=TexInfoFormat::Texinfo.new($1,@md) + texinfo_menu << toc.menu + end + if 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*$/ + @subsubmenu[n_submenu] << toc.menu + end + 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 /^<!i1!>/ + # mono.indent1 + # when /^<!i2!>/ + # mono.indent2 + # when /<!:\s+/ + # mono.graphics + # when /^\s*<!image\s+/ + # mono.image + # when /\}image/ + # mono.png + # when /\}http/ + # mono.http + else + if para !~/\S/ + para=nil + else + para.gsub!(/<\\~(\d+);\w\d+;\w\d+><#@dp:#@dp>/,'~[\1]') + #para.gsub!(/[1-3]\\\\\{\\\\\{\\\\\{\s+/, '') + #para.gsub!(/[1-3]\\\\\{\s+/, '') + para=para + end + #para.gsub!(/^\s+$/mi, "") + 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*<!h-.+?-!>/ and para !~ /<:\d-endnotes>/ + header=para[/<!h-(.+?)-!>/m, 1].gsub!(/-/m,'.') + para.gsub!(/^(?:[1-6]\\+(?:~\S+)|<:([12356]|4-.+?-)>)\s*<!h-.+?-!>/, + "\\1 #{header} ") + end + elsif para =~ /<!h!>|<!h\d!>|<!h.+?!>|<!!h.+?!>/ + if para =~ /<!h-.+?-!>/ + para.gsub!(/<!h-(.+?)-!>/,'\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 !~ /<EOF>/ + 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 =~/\.[_-]?sst$/ + m=/(.+?)\.[_-]?sst$/.match(@md.fns) + fnb,sfx=m[1],m[2] + pwd=Dir.pwd + case sfx + when /[_-]?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__ + |