Permalink
Browse files

import from latest SVN

  • Loading branch information...
0 parents commit a138fd3d2d65b86be595332d199f167de6d9f0c3 @kmuto committed Jan 16, 2010
Oops, something went wrong.
Oops, something went wrong.
@@ -0,0 +1,161 @@
+#!/usr/bin/env ruby
+#
+# $Id: review-check 3760 2007-12-30 06:13:15Z aamine $
+#
+# Copyright (c) 1999-2007 Minero Aoki
+#
+# This program is free software.
+# You can distribute or modify this program under the terms of
+# the GNU LGPL, Lesser General Public License version 2.1.
+# For details of the GNU LGPL, see the file "COPYING".
+#
+
+require 'pathname'
+
+bindir = Pathname.new(__FILE__).realpath.dirname
+$LOAD_PATH.unshift((bindir + '../lib').realpath)
+
+require 'review/env'
+require 'optparse'
+
+def sigmain
+ Signal.trap(:INT) { exit 1 }
+ Signal.trap(:PIPE, 'IGNORE')
+ main
+rescue Errno::EPIPE
+ exit 0
+end
+
+def main
+ $KCODE = 'EUC' unless defined?(Encoding)
+
+ modes = nil
+ files = ARGV unless ARGV.empty?
+ parser = OptionParser.new
+ parser.on('-a', '--all-chapters', 'Check all chapters.') {
+ files = ReVIEW.env.chaps.map {|ent| ent.path }
+ }
+ parser.on('-s', '--section N', 'Check section N.') {|n|
+ ents = ReVIEW.env.parts[Integer(n) - 1] or
+ raise ReVIEW::ApplicationError, "section #{n} not exist"
+ files = ents.map {|ent| ent.path }
+ }
+ parser.on('--text', 'Check text.') {
+ (modes ||= []).push :text
+ }
+ parser.on('--help', 'print this message and quit.') {
+ puts parser.help
+ exit 0
+ }
+ begin
+ parser.parse!
+ rescue OptionParser::ParseError => err
+ $stderr.puts err.message
+ $stderr.puts parser.help
+ exit 1
+ end
+ unless files
+ $stderr.puts "no input"
+ exit 1
+ end
+ modes ||= [:text]
+
+ modes.each do |mode|
+ case mode
+ when :text
+ check_text files
+ else
+ raise 'must not happen'
+ end
+ end
+end
+
+def check_text(files)
+ re, neg = words_re(ReVIEW.env.reject_file)
+ files.each do |path|
+ File.open(path) {|f|
+ each_paragraph(f) do |para, lineno|
+ s = para.join('')
+ if m = re.match(s)
+ next if m[0] == $ReVIEW_utils_word_ok
+ next if neg and neg =~ s
+ str, offset = find_line(para, re)
+ printf "%s:%d: %s\n", path, lineno + offset, str
+ end
+ end
+ }
+ end
+end
+
+def find_line(lines, re)
+ # single line?
+ lines.each_with_index do |line, idx|
+ return line.gsub(re, '<<<\&>>>'), idx if re =~ line
+ end
+
+ # multiple lines?
+ i = 0
+ while i < lines.size - 1
+ str = lines[i] + lines[i+1]
+ return str.gsub(re, '<<<\&>>>'), i if re =~ str
+ i += 1
+ end
+
+ raise 'must not happen'
+end
+
+def words_re(rc)
+ words = []
+ nega = []
+ File.foreach(rc) do |line|
+ next if line[0,1] == '#'
+ if / !/ =~ line
+ line, n = *line.split(/!/, 2)
+ nega.push n.strip
+ end
+ words.push line.strip
+ end
+ return Regexp.compile(words.join('|')),
+ nega.empty?() ? nil : Regexp.compile(nega.join('|'))
+end
+
+def each_paragraph(f)
+ $ReVIEW_utils_word_ok = nil
+ while line = f.gets
+ case line
+ when /\A\#@ok\((.*)\)/
+ $ReVIEW_utils_word_ok = $1
+ when /\A\#@/
+ ;
+ when %r[\A//caption\{(.*?)//\}]
+ yield [$1], f.filename, f.lineno
+ when %r<\A//\w.*\{\s*\z>
+ while line = f.gets
+ break if %r<//\}> === line
+ end
+ when /\A=/
+ yield [line.slice(/\A=+(?:\[.*?\])?\s+(.*)/, 1).strip], f.lineno
+ when /\A\s*\z/
+ # skip
+ else
+ buf = [line.strip]
+ lineno = f.lineno
+ while line = f.gets
+ break if line.strip.empty?
+ break if %r<\A(?:=|//[\w\}])> =~ line
+ next if %r<\A\#@> =~ line
+ buf.push line.strip
+ end
+ yield buf, lineno
+ $ReVIEW_utils_word_ok = nil
+ end
+ end
+end
+
+def each_paragraph_line(f, &block)
+ each_paragraph(f) do |para, *|
+ para.each(&block)
+ end
+end
+
+sigmain
@@ -0,0 +1,63 @@
+#!/usr/bin/env ruby
+#
+# $Id: review-checkdep 3748 2007-12-24 07:06:06Z aamine $
+#
+# Copyright (c) 1999-2007 Minero Aoki
+#
+# This program is free software.
+# You can distribute or modify this program under the terms of
+# the GNU LGPL, Lesser General Public License version 2.1.
+# For details of the GNU LGPL, see the file "COPYING".
+#
+
+require 'pathname'
+
+bindir = Pathname.new(__FILE__).realpath.dirname
+$LOAD_PATH.unshift((bindir + '../lib').realpath)
+
+PREDEF_FILE = 'PREDEF'
+
+def main
+ @provided = parse_predefined()
+ @unprovided = {}
+ ARGF.each do |line|
+ case line
+ when /\A\#@require\((.*)\)/
+ kw = $1
+ unless @provided.key?(kw)
+ puts "#{location()}: not provided: #{kw}"
+ @unprovided[kw] = location()
+ end
+ when /\A\#@provide\((.*)\)/
+ provide $1
+ else
+ line.scan(/@<kw>\{(.*?)[,\}]/) do
+ provide $1
+ end
+ end
+ end
+end
+
+def provide(kw)
+ @provided[kw] ||= location()
+ if @unprovided[kw]
+ reqpos = @unprovided.delete(kw)
+ puts "#{location()}: provided now: #{kw} (#{reqpos})"
+ end
+end
+
+def parse_predefined
+ result = {}
+ File.foreach(PREDEF_FILE) do |line|
+ result[line.strip] = '(predefined)'
+ end
+ result
+rescue Errno::ENOENT
+ return {}
+end
+
+def location
+ "#{ARGF.filename}:#{ARGF.file.lineno}"
+end
+
+main
@@ -0,0 +1,140 @@
+#!/usr/bin/env ruby
+#
+# $Id: review-compile 4326 2010-01-12 14:10:17Z kmuto $
+#
+# Copyright (c) 1999-2007 Minero Aoki
+#
+# This program is free software.
+# You can distribute or modify this program under the terms of
+# the GNU LGPL, Lesser General Public License version 2.1.
+# For details of the GNU LGPL, see the file "COPYING".
+#
+
+require 'pathname'
+
+bindir = Pathname.new(__FILE__).realpath.dirname
+$LOAD_PATH.unshift((bindir + '../lib').realpath)
+
+require 'review/compiler'
+require 'review/book'
+require 'fileutils'
+require 'optparse'
+
+def main
+ Signal.trap(:INT) { exit 1 }
+ Signal.trap(:PIPE, "IGNORE")
+ _main
+rescue Errno::EPIPE
+ exit 0
+end
+
+def _main
+ $KCODE = 'EUC' unless defined?(Encoding)
+
+ mode = :files
+ basedir = nil
+ if /\Areview2/ =~ File.basename($0)
+ target = File.basename($0, '.rb').sub(/review2/, '')
+ else
+ target = nil
+ end
+ check_only = false
+
+ @@secnolevel = 2 # FIXME: these 4 parameters are only used by IDGBulder.
+ @@tableopt = nil
+ @@nolf = nil
+ @@chapref = nil
+
+ parser = OptionParser.new
+ parser.banner = "Usage: #{File.basename($0)} [--target=FMT]"
+ parser.on('-c', '--check', 'Check manuscript') {
+ check_only = true
+ }
+ parser.on('--level=LVL', 'Section level to append number.') {|lvl|
+ @@secnolevel = lvl.to_i
+ }
+ parser.on('--nolfinxml', 'Do not insert LF in XML.') {
+ @@nolf = true
+ }
+ parser.on('--table=WIDTH', 'Default table width.') {|tbl|
+ @@tableopt = tbl
+ }
+ parser.on('--chapref="before,middle,after"', 'Chapref decoration.') {|cdec|
+ @@chapref = cdec
+ }
+ unless target
+ parser.on('--target=FMT', 'Target format.') {|fmt|
+ target = fmt
+ }
+ end
+ parser.on('-a', '--all', 'Compile all chapters.') {
+ mode = :dir
+ basedir = nil
+ }
+ parser.on('--directory=DIR', 'Compile all chapters in DIR.') {|path|
+ mode = :dir
+ basedir = path
+ }
+ parser.on('--help', 'Prints this message and quit.') {
+ puts parser.help
+ exit 0
+ }
+ begin
+ parser.parse!
+ unless target
+ if check_only
+ target = 'html'
+ else
+ raise OptionParser::ParseError, "no target given"
+ end
+ end
+ rescue OptionParser::ParseError => err
+ error err.message
+ $stderr.puts parser.help
+ exit 1
+ end
+
+ begin
+ compiler = ReVIEW::Compiler.new(load_strategy_class(target, check_only))
+ case mode
+ when :files
+ if ARGV.empty?
+ error 'no input'
+ exit 1
+ end
+ ReVIEW::Chapter.intern_pathes(ARGV).each do |chap|
+ result = compiler.compile(chap)
+ print result unless check_only
+ end
+ when :dir
+ book = basedir ? ReVIEW::Book.load(basedir) : ReVIEW.book
+ book.chapters.each do |chap|
+ str = compiler.compile(chap)
+ write "#{chap.name}#{compiler.strategy.extname}", str unless check_only
+ end
+ else
+ raise "must not happen: #{mode}"
+ end
+ rescue ReVIEW::ApplicationError => err
+ raise if $DEBUG
+ error err.message
+ exit 1
+ end
+end
+
+def error(msg)
+ $stderr.puts "#{File.basename($0, '.*')}: error: #{msg}"
+end
+
+def load_strategy_class(target, strict)
+ require "review/#{target}builder"
+ ReVIEW.const_get("#{target.upcase}Builder").new(strict)
+end
+
+def write(path, str)
+ File.open(path, 'w') {|f|
+ f.puts str
+ }
+end
+
+main
Oops, something went wrong.

0 comments on commit a138fd3

Please sign in to comment.