1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@3373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2003-01-20 12:10:40 +00:00
parent 9f22034ae0
commit 7bd881187d
2 changed files with 91 additions and 18 deletions

View file

@ -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> Mon Jan 20 19:43:41 2003 Akinori MUSHA <knu@iDaemons.org>
* mdoc2man.rb: Make this work as a library. * mdoc2man.rb: Make this work as a library.

View file

@ -43,6 +43,12 @@
### ###
class Mdoc2Man class Mdoc2Man
ANGLE = 1
OPTION = 2
PAREN = 3
RE_PUNCT = /^[!"'),\.\/:;>\?\]`]$/
def initialize def initialize
@name = @date = @id = nil @name = @date = @id = nil
@refauthors = @reftitle = @refissue = @refdate = @refopt = nil @refauthors = @reftitle = @refissue = @refdate = @refopt = nil
@ -80,12 +86,26 @@ class Mdoc2Man
words = line.split words = line.split
retval = '' retval = ''
option = false quote = []
parens = false dl = false
while word = words.shift while word = words.shift
case word 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' when 'Li', 'Pf'
@nospace = 1
next next
when 'Xo' when 'Xo'
@ext = true @ext = true
@ -114,14 +134,14 @@ class Mdoc2Man
retval << '``' retval << '``'
begin begin
retval << words.shift << ' ' retval << words.shift << ' '
end until words.empty? || /^[\.,]/ =~ words[0] end until words.empty? || RE_PUNCT =~ words[0]
retval.chomp!(' ') retval.chomp!(' ')
retval << '\'\'' retval << '\'\''
@nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0] @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next next
when 'Sq', 'Ql' when 'Sq', 'Ql'
retval << '`' << words.shift << '\'' retval << '`' << words.shift << '\''
@nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0] @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next next
# when 'Ic' # when 'Ic'
# retval << '\\fB' << words.shift << '\\fP' # retval << '\\fB' << words.shift << '\\fP'
@ -136,6 +156,13 @@ class Mdoc2Man
@extopt = false @extopt = false
retval << ']' retval << ']'
next next
when 'Ao'
@nospace = 1 if @nospace == 0
retval << '<'
next
when 'Ac'
retval << '>'
next
end end
retval << ' ' if @nospace == 0 && !(retval.empty? || /[\n ]\z/ =~ retval) retval << ' ' if @nospace == 0 && !(retval.empty? || /[\n ]\z/ =~ retval)
@ -146,6 +173,11 @@ class Mdoc2Man
@date = words.join(' ') @date = words.join(' ')
return nil return nil
when 'Dt' when 'Dt'
if words.size >= 2 && words[1] == '""' &&
/^(.*)\(([0-9])\)$/ =~ words[0]
words[0] = $1
words[1] = $2
end
@id = words.join(' ') @id = words.join(' ')
return nil return nil
when 'Os' when 'Os'
@ -194,6 +226,12 @@ class Mdoc2Man
@reference = false @reference = false
break break
when 'An'
next
when 'Dl'
retval << ".nf\n" << '\\& '
dl = true
next
when 'Ux' when 'Ux'
retval << "UNIX" retval << "UNIX"
next next
@ -227,14 +265,14 @@ class Mdoc2Man
@name ||= name @name ||= name
retval << ".br\n" if @synopsis retval << ".br\n" if @synopsis
retval << "\\fB" << name << "\\fP" retval << "\\fB" << name << "\\fP"
@nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0] @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next next
when 'Nd' when 'Nd'
retval << '\\-' retval << '\\-'
next next
when 'Fl' when 'Fl'
retval << '\\fB\\-' << words.shift << '\\fP' retval << '\\fB\\-' << words.shift << '\\fP'
@nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0] @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next next
when 'Ar' when 'Ar'
retval << '\\fI' retval << '\\fI'
@ -245,21 +283,27 @@ class Mdoc2Man
while words[0] == '|' while words[0] == '|'
retval << ' ' << words.shift << ' \\fI' << words.shift << '\\fP' retval << ' ' << words.shift << ' \\fI' << words.shift << '\\fP'
end end
@nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0] @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next next
end end
when 'Cm' when 'Cm'
retval << '\\fB' << words.shift << '\\fP' retval << '\\fB' << words.shift << '\\fP'
while /^[\.,:)]$/ =~ words[0] while RE_PUNCT =~ words[0]
retval << words.shift retval << words.shift
end end
next next
when 'Op' when 'Op'
option = true quote << OPTION
@nospace = 1 if @nospace == 0 @nospace = 1 if @nospace == 0
retval << '[' retval << '['
# words.push(words.pop + ']') # words.push(words.pop + ']')
next next
when 'Aq'
quote << ANGLE
@nospace = 1 if @nospace == 0
retval << '<'
# words.push(words.pop + '>')
next
when 'Pp' when 'Pp'
retval << "\n" retval << "\n"
next next
@ -268,14 +312,14 @@ class Mdoc2Man
next next
end end
if word == 'Pa' && !option if word == 'Pa' && !quote.include?(OPTION)
retval << '\\fI' retval << '\\fI'
retval << '\\&' if /^\./ =~ words[0] retval << '\\&' if /^\./ =~ words[0]
retval << words.shift << '\\fP' retval << words.shift << '\\fP'
while /^[\.,:;)]$/ =~ words[0] while RE_PUNCT =~ words[0]
retval << words.shift retval << words.shift
end end
# @nospace = 1 if @nospace == 0 && /^[\.,]/ =~ words[0] # @nospace = 1 if @nospace == 0 && RE_PUNCT =~ words[0]
next next
end end
@ -289,20 +333,25 @@ class Mdoc2Man
when 'Pq' when 'Pq'
retval << '(' retval << '('
@nospace = 1 @nospace = 1
parens = true quote << PAREN
next next
when 'Sx', 'Sy' when 'Sx', 'Sy'
retval << '.B ' << words.join(' ') retval << '.B ' << words.join(' ')
break break
when 'Ic' when 'Ic'
retval << '\\fB' retval << '\\fB'
until words.empty? || /^[\.,]/ =~ words[0] until words.empty? || RE_PUNCT =~ words[0]
case words[0] case words[0]
when 'Op' when 'Op'
words.shift words.shift
retval << '[' retval << '['
words.push(words.pop + ']') words.push(words.pop + ']')
next next
when 'Aq'
words.shift
retval << '<'
words.push(words.pop + '>')
next
when 'Ar' when 'Ar'
words.shift words.shift
retval << '\\fI' << words.shift << '\\fP' retval << '\\fI' << words.shift << '\\fP'
@ -384,9 +433,16 @@ class Mdoc2Man
retval.sub!(/\A\.([^a-zA-Z])/, "\\1") retval.sub!(/\A\.([^a-zA-Z])/, "\\1")
# retval.chomp!(' ') # retval.chomp!(' ')
retval << ')' if parens while q = quote.pop
case q
retval << ']' if option when OPTION
retval << ']'
when PAREN
retval << ')'
when ANGLE
retval << '>'
end
end
# retval << ' ' unless @nospace == 0 || retval.empty? || /\n\z/ =~ retval # retval << ' ' unless @nospace == 0 || retval.empty? || /\n\z/ =~ retval
@ -394,6 +450,8 @@ class Mdoc2Man
retval << "\n" unless @ext || @extopt || retval.empty? || /\n\z/ =~ retval retval << "\n" unless @ext || @extopt || retval.empty? || /\n\z/ =~ retval
retval << ".fi\n" if dl
return retval return retval
end end