From a0c28268123aa8f3aa103dcefaa09486626a140a Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 10 Jan 2012 22:29:08 -0500 Subject: v3: modify.rb, prep script for year update, & changing module & class names --- data/doc/sisu/CHANGELOG_v3 | 2 + data/sisu/v3/conf/convert/modify.rb | 511 ++++++++++++++++++++++-------------- 2 files changed, 309 insertions(+), 204 deletions(-) (limited to 'data') diff --git a/data/doc/sisu/CHANGELOG_v3 b/data/doc/sisu/CHANGELOG_v3 index 5a93092c..d48aaad9 100644 --- a/data/doc/sisu/CHANGELOG_v3 +++ b/data/doc/sisu/CHANGELOG_v3 @@ -21,6 +21,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_3.1.11.orig.tar.xz sisu_3.1.11-1.dsc sisu_3.1.11-1.debian.tar.gz + * modify.rb, prep script for year update, & changing module & class names + %% 3.1.10.orig.tar.xz (2011-12-31:52/6) http://git.sisudoc.org/?p=code/sisu.git;a=log;h=refs/tags/sisu_3.1.10 http://git.sisudoc.org/?p=code/sisu.git;a=log;h=refs/tags/debian/sisu_3.1.10-1 diff --git a/data/sisu/v3/conf/convert/modify.rb b/data/sisu/v3/conf/convert/modify.rb index 858ffe08..fab7832d 100644 --- a/data/sisu/v3/conf/convert/modify.rb +++ b/data/sisu/v3/conf/convert/modify.rb @@ -1,66 +1,104 @@ #!/usr/bin/env ruby # encoding: utf-8 =begin + * Name: modify.rb - * Author: Ralph Amissah - * http://www.jus.uio.no/sisu - * http://www.jus.uio.no/sisu/SiSU/download + * Description: A conversion script for canned substitutions, - a fairly generic simple tool that can be used to store other canned conversions, - used here for altering SiSU markup - * Copyright (C) 2004, 2006 Ralph Amissah - * Packaged with: SiSU information Structuring Universe - - Structured information, Serialized Units - * SiSU Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Ralph Amissah + a fairly generic simple tool that can be used to store other canned conversions, + (used here for altering SiSU markup or the SiSU program) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2012, Ralph Amissah, All Rights Reserved. - * License: GPL 3 or later + * License: GPL 3 or later: - Summary of GPL 3 + * Packaged with: SiSU a framework for document structuring, publishing & search - 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. + Copyright (C) Ralph Amissah - 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. + 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. - 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 + 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. - 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/gpl3.fsf + You should have received a copy of the GNU General Public License along with + this program. If not, see . - © Ralph Amissah 1997, current 2006. - All Rights Reserved. + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + - * Ralph Amissah: ralph@amissah.com - ralph.amissah@gmail.com + + + + + * Hompages: + + + + * Download: + + + * Ralph Amissah + + - * Notes: configure rc in ~/.sisu/sisurc.yaml =end module SiSU_Modify - class Convert_markup + class Operations def initialize(cf,files) @cf,@files=cf,files @description="This is a script that contains canned text conversions for reuse" + pwd=Dir.pwd + @mod_inst='modify_instructions.rb' + @modify_instructions_script="#{pwd}/#{@mod_inst}" + if FileTest.file?(@modify_instructions_script) ==true + puts <<-WOK + autoload script: "#{@modify_instructions_script}" + used by "ruby #{__FILE__} --convert" if + "Extracted.new.modify.modules_and_classes" is used + (see "matches_and_replaces") + EDIT this file manually + [to rebuild run: "ruby #{__FILE__} --build-gsub"] + + WOK + else + puts <<-WOK + autoload script does not exist: "#{@modify_instructions_script}" + needed for "ruby #{__FILE__} --convert" if + "Extracted.new.modify.modules_and_classes" is used + (see "matches_and_replaces") + try run: "ruby #{__FILE__} --build-gsub" + + WOK + end + autoload :Extracted, "./#{@mod_inst}" end - def current_match_and_replace #Disable, edit manually - clean_non_regular_characters - #convert_pre_37_to_38_experimental + def matches_and_replaces #edit manually + [ + #Extracted.new.modify.modules_and_classes, + #Extracted.new.modify.modules, + #Extracted.new.modify.classes, + #modify.dates, + #modify.modules, + #modify.classes, + #modify.misc, + ] end def message(text) response='' while response !~/yes/ print %{ #{text} - to continue type "yes" [to exit type "no" or "quit"]: } + To continue type "yes" [to exit type "no" or "quit"]: } response=File.new('/dev/tty').gets.strip exit if response =~/^(?:quit|no)$/ end @@ -68,206 +106,271 @@ module SiSU_Modify def help print < 0 + @files.each do |i| + @new,@matched,@empty1,@empty2=true,false,false,false + file=File.open(i,'r') + cont=file.readlines + file.close + @file=File.new(i,'w') + cont.each do |t| + matches_and_replaces.each do |match_and_replace| + match_and_replace.each do |m,r| + if t =~m + p m.to_s + ' -> ' + r + puts "in: #{t}" + t.gsub!(m,r) if m and r + puts "out: #{t}" + end + end + end + if t=~/^\s*$/; @empty1=true + else @empty1=false + end + @file.puts t unless (@empty1==true and @empty2==true) + if t=~/^\s*$/; @empty2=true + else @empty2=false + end + end + @file.close + end + end end - def markup_version?(i) - file=File.open(i,'r') - cont=file.readlines - file.close - markup_version=nil - cont.each do |y| - if y =~/^:?A~/ - markup_version='0.38' - break + def report_modules_and_classes + @f=nil + @structure={} + @arr={mod: [], cl: []} + @files.each do |f| + @new,@matched,@empty1,@empty2=true,false,false,false + file=File.open(f,'r') + cont=file.readlines + file.close + cont.each do |t| + if f != @f + @f=f + @mod=nil + #puts "---\n#{@f}" + @structure[@f]={} + end + if t =~/^\s*module\s+\S+/ + @mod=t.match(/^\s*module\s+(\S+)/)[1] + #puts ' ' + @mod + @arr[:mod] << @mod + @structure[@f].store(@mod,[]) + #@structure[@f] = {@mod => []} + end + if t =~/^\s*class\s+\S+/ + cl=t.match(/^\s*class\s+(\S+)/)[1] + #puts ' ' + cl + @arr[:cl] << cl + @structure[@f][@mod] << cl + end end - if y =~/^1~/ - markup_version='0.37' - break + end + @structure.sort.each do |fl,modules| + puts "---\n" + fl + modules.sort.each do |mod,classes| + puts ' ' + mod + classes.sort.each do |cl| + puts ' ' + cl + end + end + end + puts '---' + puts 'number of modules: ' + @arr[:mod].length.to_s + ', unique: ' + @arr[:mod].uniq.length.to_s + puts 'number of classes: ' + @arr[:cl].length.to_s + ', unique: ' + @arr[:cl].uniq.length.to_s + end + def build_search_and_replace_method_for_modules_and_classes + @f=nil + @structure={} + @arr={mod: [], cl: []} + @files.each do |f| + @new,@matched,@empty1,@empty2=true,false,false,false + file=File.open(f,'r') + cont=file.readlines + file.close + cont.each do |t| + if f != @f + @f=f + @mod=nil + #puts "---\n#{@f}" + @structure[@f]={} + end + if t =~/^\s*module\s+\S+/ + @mod=t.match(/^\s*module\s+(\S+)/)[1] + #puts ' ' + @mod + @arr[:mod] << @mod + @structure[@f].store(@mod,[]) + #@structure[@f] = {@mod => []} + end + if t =~/^\s*class\s+\S+/ + cl=t.match(/^\s*class\s+(\S+)/)[1] + #puts ' ' + cl + @arr[:cl] << cl + @structure[@f][@mod] << cl + end end - #if y =~/^1{~/ - # markup_version='0.16' - # break - #end - markup_version='0.37' end - markup_version + puts 'number of modules: ' + @arr[:mod].length.to_s + ', unique: ' + @arr[:mod].uniq.length.to_s + puts 'number of classes: ' + @arr[:cl].length.to_s + ', unique: ' + @arr[:cl].uniq.length.to_s + method_modules_and_classes=[] + method_modules_and_classes <<<<-WOK +#module SiSU_MC + class Extracted + def modify + WOK + #% modules_and_classes + method_modules_and_classes <<<<-WOK + def modules_and_classes + [ + WOK + @structure.sort.each do |fl,modules| + method_modules_and_classes << ' '*8 + "##% -- " + fl + modules.sort.each do |mod,classes| + method_modules_and_classes << ' '*8 + '# ' + "[/#{mod}/," + ' '*(67 - mod.length) + "'#{mod}']," + classes.uniq.sort.each do |cl| + method_modules_and_classes << ' '*8 + '# ' + "[/#{cl}/," + ' '*(65 - cl.length) + "'#{cl}']," + end + end + end + method_modules_and_classes <<<<-WOK + ] + end + WOK + #% modules + method_modules_and_classes <<<<-WOK + def modules + [ + WOK + method_modules_and_classes << ' '*8 + '# ' + 'number of modules: ' + @arr[:mod].length.to_s + + ', unique: ' + @arr[:mod].uniq.length.to_s + @arr[:mod].uniq.sort.each do |mod| + method_modules_and_classes << ' '*8 + '# ' + "[/#{mod}/," + ' '*(67 - mod.length) + "'#{mod}']," + end + method_modules_and_classes <<<<-WOK + ] + end + WOK + #% classes + method_modules_and_classes <<<<-WOK + def classes + [ + WOK + method_modules_and_classes << ' '*8 + '# ' + 'number of classes: ' + @arr[:cl].length.to_s + + ', unique: ' + @arr[:cl].uniq.length.to_s + @arr[:cl].uniq.sort.each do |cl| + method_modules_and_classes << ' '*8 + '# ' + "[/#{cl}/," + ' '*(67 - cl.length) + "'#{cl}']," + end + method_modules_and_classes <<<<-WOK + ] + end + WOK + method_modules_and_classes <<<<-WOK + self + end + end +#end + WOK + #method_modules_and_classes.each{|x| puts x} + if FileTest.file?(@modify_instructions_script) ==true + message("WARNING << #{@mod_inst} >> exists (and may have been edited). The existing << #{@mod_inst} >> will be overwritten if you proceed.") + end + instructs=File.new(@modify_instructions_script,'w') + method_modules_and_classes.each do |x| + puts x + instructs.puts x + end + instructs.close end - def conversion - #%% do it --------------------------> + def action if @files and @files.length > 0 p @files mr=nil #%% changes to make m match, r replace --------------------------> if @cf =~/--help/; help else - message("WARNING, proceed at your own risk,\npermanent changes requested for the above named files\n best that you check (manually) what this file is set to do\n conversions set are at the top of the file") - mr=case @cf - when /--convert|default/; current_match_and_replace - when /--(?:(?:37)?to38|rad)/; convert_pre_37_to_38_experimental - when /--(?:(?:38)?to37)/; convert_38_experimental_to_37 + case @cf + when /--convert/; convert + when /--report/; report_modules_and_classes + when /--build-gsub/; build_search_and_replace_method_for_modules_and_classes else help end - end - match_and_replace=mr - #start_processing =/not used in this example/i - end_processing =/END\s+OF\s+FILE/ - @files.each do |i| - @new,@matched,@flag_start,@flag_end,@empty1,@empty2=true,false,false,false,false,false - o="#{i}.bk" #o is for old - file=File.open(i,'r') - cont=file.readlines - file.close - cont.each do |y| - #p y - #p y if y =~/^[1-6]~/ - match_and_replace.each do |m,r| - if y =~m - if @new - @new=false - File.unlink(o) if File.exists?(o) - #system("lv #{i} > #{o}") - File.rename(i,o) - File.unlink(i) if File.exists?(i) - @file=File.new(i,'w') - @matched=true - break - end - end - end - end - if @matched - puts "match in #{i}" - @flag_start=true - cont.each do |y| - if y =~end_processing; @flag_end=true - end - if @flag_start and not @flag_end - match_and_replace.each do |m,r| - if y =~m - p m.to_s + ' -> ' + r - puts "in: #{y}" - y.gsub!(m,r) if m and r - puts "out: #{y}" - end - end - end - #if y =~start_processing: @flag_start=true - #end - #if y =~m1 - #end - if y=~/^\s*$/; @empty1=true - else @empty1=false - end - @file.puts y unless (@empty1==true and @empty2==true) - if y=~/^\s*$/; @empty2=true - else @empty2=false - end - #@file << y + "\n" - end - @file.close - else puts "NO match in #{f}" - end + #act end else puts "this routine makes permanent changes to the contents of the files matched, as instructed within [no matches]" end end end end -#%% files to match for this conversion set -------------------------> -f=$* -p $* +#% files to match for this conversion set -------------------------> +f=$* #; p $* cf=f[0].to_s f.shift match_and_replace=Array.new -#unless cf and cf =~/--/ -# puts < 0; f=Dir.glob("[a-z]*.ss?") #restricted to sisu type files, it need not be +unless f.length > 0 + f=if cf == '--report' \ + or cf == '--build-gsub' + Dir.glob("[a-zA-Z]*.rb") #restrict to ruby files + else + Dir.glob("[a-zA-Z]*") + end + f=f.sort.delete_if { |x| x == __FILE__ or x == 'modify_instructions.rb' } end +SiSU_Modify::Operations.new(cf,f).action +__END__ #f=Dir.glob("{bin,conf,data,lib}/**/*.rb") #sisu development #f=Dir.glob("[^_]/**/*") #all files subdirectories beneath pwd except those starting with _ -SiSU_Modify::Convert_markup.new(cf,f).conversion -__END__ -- cgit v1.2.3