Permalink
Browse files

* mdoc2man.rb: Properly put nested braces, parentheses and angles.

* mdoc2man.rb: Add support for .An and .Aq/.Ao/.Ac.

* mdoc2man.rb: Add support for .Dl.

* mdoc2man.rb: Make .Pf macro actually work.

* mdoc2man.rb: Properly handle .Os.

* mdoc2man.rb: Correctly omit spaces around punctuation
  characters.


git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 4eafcb1 commit 778b2422c6f0cdd4067dc6623d5cf15f86183000 @knu knu committed Jan 20, 2003
Showing with 91 additions and 18 deletions.
  1. +15 −0 ChangeLog
  2. +76 −18 mdoc2man.rb
View
15 ChangeLog
@@ -1,3 +1,18 @@
+Mon Jan 20 21:02:50 2003 Akinori MUSHA <knu@iDaemons.org>
+
+ * mdoc2man.rb: Properly put nested braces, parentheses and angles.
+
+ * mdoc2man.rb: Add support for .An and .Aq/.Ao/.Ac.
+
+ * mdoc2man.rb: Add support for .Dl.
+
+ * mdoc2man.rb: Make .Pf macro actually work.
+
+ * mdoc2man.rb: Properly handle .Os.
+
+ * mdoc2man.rb: Correctly omit spaces around punctuation
+ characters.
+
Mon Jan 20 19:43:41 2003 Akinori MUSHA <knu@iDaemons.org>
* mdoc2man.rb: Make this work as a library.
View
94 mdoc2man.rb
@@ -43,6 +43,12 @@
###
class Mdoc2Man
+ ANGLE = 1
+ OPTION = 2
+ PAREN = 3
+
+ RE_PUNCT = /^[!"'),\.\/:;>\?\]`]$/
+
def initialize
@name = @date = @id = nil
@refauthors = @reftitle = @refissue = @refdate = @refopt = nil
@@ -80,12 +86,26 @@ def parse_macro(line)
words = line.split
retval = ''
- option = false
- parens = false
+ quote = []
+ dl = false
while word = words.shift
case word
+ when RE_PUNCT
+ while q = quote.pop
+ case q
+ when OPTION
+ retval << ']'
+ when PAREN
+ retval << ')'
+ when ANGLE
+ retval << '>'
+ end
+ end
+ retval << word
+ next
when 'Li', 'Pf'
+ @nospace = 1
next
when 'Xo'
@ext = true
@@ -114,14 +134,14 @@ def parse_macro(line)
retval << '``'
begin
retval << words.shift << ' '
- end until words.empty? || /^[\.,]/ =~ words[0]
+ end until words.empty? || RE_PUNCT =~ words[0]
retval.chomp!(' ')
retval << '\'\''
- @nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0]
+ @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next
when 'Sq', 'Ql'
retval << '`' << words.shift << '\''
- @nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0]
+ @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next
# when 'Ic'
# retval << '\\fB' << words.shift << '\\fP'
@@ -136,6 +156,13 @@ def parse_macro(line)
@extopt = false
retval << ']'
next
+ when 'Ao'
+ @nospace = 1 if @nospace == 0
+ retval << '<'
+ next
+ when 'Ac'
+ retval << '>'
+ next
end
retval << ' ' if @nospace == 0 && !(retval.empty? || /[\n ]\z/ =~ retval)
@@ -146,6 +173,11 @@ def parse_macro(line)
@date = words.join(' ')
return nil
when 'Dt'
+ if words.size >= 2 && words[1] == '""' &&
+ /^(.*)\(([0-9])\)$/ =~ words[0]
+ words[0] = $1
+ words[1] = $2
+ end
@id = words.join(' ')
return nil
when 'Os'
@@ -194,6 +226,12 @@ def parse_macro(line)
@reference = false
break
+ when 'An'
+ next
+ when 'Dl'
+ retval << ".nf\n" << '\\& '
+ dl = true
+ next
when 'Ux'
retval << "UNIX"
next
@@ -227,14 +265,14 @@ def parse_macro(line)
@name ||= name
retval << ".br\n" if @synopsis
retval << "\\fB" << name << "\\fP"
- @nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0]
+ @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next
when 'Nd'
retval << '\\-'
next
when 'Fl'
retval << '\\fB\\-' << words.shift << '\\fP'
- @nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0]
+ @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next
when 'Ar'
retval << '\\fI'
@@ -245,21 +283,27 @@ def parse_macro(line)
while words[0] == '|'
retval << ' ' << words.shift << ' \\fI' << words.shift << '\\fP'
end
- @nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0]
+ @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next
end
when 'Cm'
retval << '\\fB' << words.shift << '\\fP'
- while /^[\.,:)]$/ =~ words[0]
+ while RE_PUNCT =~ words[0]
retval << words.shift
end
next
when 'Op'
- option = true
+ quote << OPTION
@nospace = 1 if @nospace == 0
retval << '['
# words.push(words.pop + ']')
next
+ when 'Aq'
+ quote << ANGLE
+ @nospace = 1 if @nospace == 0
+ retval << '<'
+ # words.push(words.pop + '>')
+ next
when 'Pp'
retval << "\n"
next
@@ -268,14 +312,14 @@ def parse_macro(line)
next
end
- if word == 'Pa' && !option
+ if word == 'Pa' && !quote.include?(OPTION)
retval << '\\fI'
retval << '\\&' if /^\./ =~ words[0]
retval << words.shift << '\\fP'
- while /^[\.,:;)]$/ =~ words[0]
+ while RE_PUNCT =~ words[0]
retval << words.shift
end
- # @nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0]
+ # @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next
end
@@ -289,20 +333,25 @@ def parse_macro(line)
when 'Pq'
retval << '('
@nospace = 1
- parens = true
+ quote << PAREN
next
when 'Sx', 'Sy'
retval << '.B ' << words.join(' ')
break
when 'Ic'
retval << '\\fB'
- until words.empty? || /^[\.,]/ =~ words[0]
+ until words.empty? || RE_PUNCT =~ words[0]
case words[0]
when 'Op'
words.shift
retval << '['
words.push(words.pop + ']')
next
+ when 'Aq'
+ words.shift
+ retval << '<'
+ words.push(words.pop + '>')
+ next
when 'Ar'
words.shift
retval << '\\fI' << words.shift << '\\fP'
@@ -384,16 +433,25 @@ def parse_macro(line)
retval.sub!(/\A\.([^a-zA-Z])/, "\\1")
# retval.chomp!(' ')
- retval << ')' if parens
-
- retval << ']' if option
+ while q = quote.pop
+ case q
+ when OPTION
+ retval << ']'
+ when PAREN
+ retval << ')'
+ when ANGLE
+ retval << '>'
+ end
+ end
# retval << ' ' unless @nospace == 0 || retval.empty? || /\n\z/ =~ retval
retval << ' ' unless !@ext || @extopt || / $/ =~ retval
retval << "\n" unless @ext || @extopt || retval.empty? || /\n\z/ =~ retval
+ retval << ".fi\n" if dl
+
return retval
end

0 comments on commit 778b242

Please sign in to comment.