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:
		
							parent
							
								
									9f22034ae0
								
							
						
					
					
						commit
						7bd881187d
					
				
					 2 changed files with 91 additions and 18 deletions
				
			
		
							
								
								
									
										15
									
								
								ChangeLog
									
										
									
									
									
								
							
							
						
						
									
										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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										94
									
								
								mdoc2man.rb
									
										
									
									
									
								
							
							
						
						
									
										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 @@ class Mdoc2Man
 | 
			
		|||
    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 @@ class Mdoc2Man
 | 
			
		|||
	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 @@ class Mdoc2Man
 | 
			
		|||
	@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 @@ class Mdoc2Man
 | 
			
		|||
	@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 @@ class Mdoc2Man
 | 
			
		|||
 | 
			
		||||
	@reference = false
 | 
			
		||||
	break
 | 
			
		||||
      when 'An'
 | 
			
		||||
	next
 | 
			
		||||
      when 'Dl'
 | 
			
		||||
	retval << ".nf\n" << '\\&  '
 | 
			
		||||
	dl = true
 | 
			
		||||
	next
 | 
			
		||||
      when 'Ux'
 | 
			
		||||
	retval << "UNIX"
 | 
			
		||||
	next
 | 
			
		||||
| 
						 | 
				
			
			@ -227,14 +265,14 @@ class Mdoc2Man
 | 
			
		|||
	@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 @@ class Mdoc2Man
 | 
			
		|||
	  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 @@ class Mdoc2Man
 | 
			
		|||
	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 @@ class Mdoc2Man
 | 
			
		|||
      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,9 +433,16 @@ class Mdoc2Man
 | 
			
		|||
    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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -394,6 +450,8 @@ class Mdoc2Man
 | 
			
		|||
 | 
			
		||||
    retval << "\n" unless @ext || @extopt || retval.empty? || /\n\z/ =~ retval
 | 
			
		||||
 | 
			
		||||
    retval << ".fi\n" if dl
 | 
			
		||||
 | 
			
		||||
    return retval
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue