summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/match_parens
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-04-26 00:12:58 +0000
committerKarl Berry <karl@freefriends.org>2014-04-26 00:12:58 +0000
commit06d6ec80f4e865544af67659307bb85d366df78b (patch)
treea5db66f1bbd7ea495072185da730216774a6b7de /Master/texmf-dist/scripts/match_parens
parent5bef9e75133397ad5aa2a39e3b887a3e2e697314 (diff)
match_parens (25apr14)
git-svn-id: svn://tug.org/texlive/trunk@33682 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/match_parens')
-rwxr-xr-xMaster/texmf-dist/scripts/match_parens/match_parens111
1 files changed, 62 insertions, 49 deletions
diff --git a/Master/texmf-dist/scripts/match_parens/match_parens b/Master/texmf-dist/scripts/match_parens/match_parens
index 42286fa1141..67f8ebe8f58 100755
--- a/Master/texmf-dist/scripts/match_parens/match_parens
+++ b/Master/texmf-dist/scripts/match_parens/match_parens
@@ -1,15 +1,16 @@
#!/usr/bin/env ruby
+# encoding: utf-8
-=begin rdoc
+ MYNAME = File.basename($0)
+Version = '1.41'
-== match_parens - find mismatches of parentheses, braces, (angle) brackets, in texts
+<<'DOC'
+= match_parens - find mismatches of parentheses, braces, (angle) brackets, in texts
-=== Synopsis
-
- match_parens [_filename_]
-
-=== Description
+= Synopsis
+match_parens [filename]
+= Description
Mismatches of parentheses, braces, (angle) brackets, especially in TeX
sources which may be rich in those, may be difficult to trace. This little
script helps you by writing your text to standard output, after adding a
@@ -17,23 +18,21 @@ left margin to your text, which will normally be almost empty, but will
clearly show any mismatches. (Just try me on myself to see that the
parenthesis starting this sentence will not appear to be matched at the end
of the file. If you look at me in the vim editor, then select this
-paragraph and try the command :!%
+paragraph and try the command |:!%|.
The exit value of the script is 0 when there are no mismatches, 1 otherwise.
Angle brackets are only looked for inside HTML text, where HTML is
-supposed to start with <html>, =begin rdoc, or <<RDOC and to end with
-</html>, =end or RDOC
-
-=== Examples
-Suppose we have two files, _good_ and _bad_, containing these texts:
+supposed to start with |<html>| or |=begin rdoc| and to end with
+|</html>| or |=end|.
+= Examples
+Suppose we have two files, |good| and |bad|, containing these texts:
good: bad:
This is a (simple) test This is a (simple test
without mismatches containing mismatches
then here are some usage examples. First a simple test on these files:
-
$ match_parens good
1 This is a (simple) test
2 without mismatches
@@ -46,44 +45,57 @@ then here are some usage examples. First a simple test on these files:
1
Just report if there are mismatches:
-
$ match_parens good >/dev/null && echo fine || echo problems
fine
$ match_parens bad >/dev/null && echo fine || echo problems
problems
Report all tex files with mismatches in the current directory:
-
$ for i in *.tex; do match_parens $i >/dev/null || echo $i; done
Matches must be in correct order:
-
$ echo -e "This is a ([simple)] test\n" | match_parens
1 ([)] This is a ([simple)] test
2 ([)]
-
-=== Copyright
-
-Copyright (C) 2009 Wybo Dekker (<tt>wybo@dekkerdocumenten.nl</tt>)
-
-This program is free software: you can redistribute it and/or modify it
-under the terms of the {GNU General Public License}[http://www.gnu.org/licenses/]
-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}[http://www.gnu.org/licenses/] for more details.
-
-$Id: match_parens,v 1.10 2012/02/20 13:28:52 wybo Exp $
-=end
-
-private
- s, n, html, notparens =
-'', '0', false, '^{}[]()'
-
-RELEASE = 1.4
+= Bugs
+Conversion of ``...'' to “...” should only be done in latex files
+
+= See also
+matchparens: the Bash version, which is 10+ times slower
+
+= Changes
+Changes with respect to version 1.4:
+- clearer output
+- added --help and --version options
+- documentation adapted to gendoc
+
+= Author and copyright
+Author Wybo Dekker
+Email U{Wybo@dekkerdocumenten.nl}{wybo@dekkerdocumenten.nl}
+License Released under the U{www.gnu.org/copyleft/gpl.html}{GNU General Public License}
+DOC
+
+require 'optparse'
+
+ARGV.options do |opt|
+ opt.banner = "#{MYNAME} - find mismatches of parentheses, braces, (angle) brackets, in texts\n"
+ opt.on('-V','--version',
+ 'print version and exit') do
+ puts Version
+ exit
+ end
+ opt.on('-h','--help',
+ 'print this help and exit') do
+ puts opt.to_s.sub(/^ *-I\n/,'')
+ exit
+ end
+ opt.on('-I') do system("instscript -zp #{MYNAME}"); exit; end
+ opt.parse!
+end
+ s=''
+ n=0
+ html=false
+ parens='{}[]()“”'
arg = ARGV[0] || ''
unless arg.empty?
@@ -91,19 +103,20 @@ unless arg.empty?
test(?r,arg) or raise("file #{arg} is not readable")
end
while x = gets()
- if html && (x=~/^(RDOC|[# ]*=end)/ || x=~/<\/html>/i)
+ x = x.gsub(/``/,'“').gsub(/''/,'”')
+
+ if html && (x=~/^([# ]*=end)/ || x=~/<\/html>/i)
html = false
- notparens = '^{}[]()'
- elsif !html && (x=~/^(<<RDOC|[# ]*=begin rdoc)/ || x=~/<html>/i)
+ parens = '{}[]()'
+ elsif !html && (x=~/^([# ]*=begin rdoc)/ || x=~/<html>/i)
html = true
- notparens = '^{}[]()<>'
+ parens = '{}[]()“”<>'
end
+
# remove {x} where x in []{}()<>, copy all parens to s
- s << x.sub(/^<<RDOC/,'').
- gsub(/\{[\[\]{}()<>]\}/,'').
- tr(notparens,'')
+ s << x.gsub(/“\{[\[\]{}()<>]\}”/,'').tr('^'+parens,'')
# remove matches from inside
- while s.gsub!(/\{\}|\(\)|\[\]|<>/,'') do end
- puts ["%7d" % [n.next!],s,x].join("\t")
+ while s.gsub!(/\{\}|\(\)|\[\]|<>|“”/,'') do end
+ puts "%4d | %-10s | %s" % [n+=1,s.slice(0..9),x]
end
exit s.empty? ? 0 : 1