###############################################################################
#
# File:         awf-rtf.patch
# RCS:          $Header: $
# Description:  add rtf output to awf
# Author:       Christian Limpach <chris@nice.ch>
# Created:      Fri Apr  7 01:03:20 1995
# Modified:     Fri Apr  7 04:02:47 1995 (Christian Limpach) chris@nice.ch
# Language:     patch
# Package:      N/A
# Status:       Experimental (Do Not Distribute)
#
# (C) Copyright 1995, Christian Limpach, all rights reserved.
# This is free software, and you are welcome to redistribute it
# under certain conditions; see ftp://nice.ethz.ch/users/chris/TERMS
# for details. This software comes with ABSOLUTELY NO WARRANTY.
#
###############################################################################

# awf is available from the comp.sources.unix archives in volume23
# you can also get a copy from
# ftp://nice.ethz.ch/users/chris/Contrib/awf.tar.gz

# Usage: (Examples)
#   awf -man -rtf somefile.1 >somefile.rtf
# or
#   awf -man -rtf somefile.1 | open

# Installation:
#   enter the awf directory and apply this patch:
#   patch -p1 <awf-rtf.patch
#   then install awf: make install
# this will have installed awf in /usr/local/{bin|man|lib}
# to install it somewhere else, you will have to edit some files

diff -c awf/Makefile:1.1.1.1 awf/Makefile:1.3
*** awf/Makefile:1.1.1.1	Fri Apr  7 04:02:53 1995
--- awf/Makefile	Fri Apr  7 04:02:53 1995
***************
*** 1,9 ****
! AWFLIB = /usr/lib/awf	# beware, awf itself knows this
! BIN = /usr/bin
! MAN = /usr/man/man1
! CP = common dev.dumb mac.man mac.ms pass1 pass2.base pass2.man pass2.ms pass3
! DTR = README COPYRIGHT Makefile awf awf.1 awf.1.out common dev.dumb mac.man \
! 	mac.ms pass1 pass2.base pass2.man pass2.ms pass3
  # System V brain damage
  SHELL = /bin/sh
  
--- 1,24 ----
! ###############################################################################
! #
! # File:         Makefile
! # RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/Makefile,v 1.3 1995/04/06 19:31:00 chris Exp $
! # Description:  Makefile to install awf
! # Author:       Henry Spencer <henry@zoo.toronto.edu>
! # Created:      13 July 1990
! # Modified:     Thu Apr  6 21:11:42 1995 (Christian Limpach) chris@nice.ch
! # Language:     Makefile
! # Package:      awf
! # Status:       Released
! #
! ###############################################################################
! 
! AWFLIB = /usr/local/lib/awf	# beware, awf itself knows this
! BIN = /usr/local/bin
! MAN = /usr/local/man/man1
! CP = common dev.dumb dev.rtf mac.man mac.ms \
! 	pass1 pass2.base pass2.man pass2.ms pass3 rtfpass3
! DTR = README COPYRIGHT Makefile awf awf.1 awf.1.out common dev.dumb dev.rtf \
! 	mac.man mac.ms pass1 pass2.base pass2.man pass2.ms pass3 rtfpass3
  # System V brain damage
  SHELL = /bin/sh
  
diff -c awf/awf:1.1.1.1 awf/awf:1.3
*** awf/awf:1.1.1.1	Fri Apr  7 04:02:55 1995
--- awf/awf	Fri Apr  7 04:02:55 1995
***************
*** 1,24 ****
  #! /bin/sh
! PATH=/bin:/usr/bin ; export PATH
  # AWFLIB is where the pieces live
! AWFLIB=${AWFLIB-/usr/lib/awf}
  
! tmp=/tmp/awp$$			# tempfile for building pass 2
  errs=/tmp/awe$$		# error messages (awk can't send to stderr)
  
! case "$1" in
! -ms)	mac=ms	;;
! -man)	mac=man	;;
! *)	echo "$0: must specify -ms or -man" >&2
  	exit 2
! 	;;
! esac
! shift
! 
! dev="$AWFLIB/dev.$TERM"
! if test ! -r $dev
! then
! 	dev="$AWFLIB/dev.dumb"
  fi
  
  trap "rm -f $tmp $errs ; exit 0" 0 1 2
--- 1,67 ----
  #! /bin/sh
! ###############################################################################
! #
! # File:         awf
! # RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/awf,v 1.3 1995/04/06 19:31:01 chris Exp $
! # Description:  driver/frontend
! # Author:       Henry Spencer <henry@zoo.toronto.edu>
! # Created:      13 July 1990
! # Modified:     Thu Apr  6 21:13:43 1995 (Christian Limpach) chris@nice.ch
! # Language:     Shell-script: sh
! # Package:      awf
! # Status:       Released
! #
! ###############################################################################
! 
! PATH=/bin:/usr/bin:/usr/local/bin ; export PATH
  # AWFLIB is where the pieces live
! AWFLIB=${AWFLIB-/usr/local/lib/awf}
! # AWK is the awk to use (NeXT's and rtfpass3 require gawk)
! AWK=${AWK-/usr/local/bin/gawk}
! # usage message
! USAGE="usage: $0 [-rtf] -man|-ms file"
  
! tmp=/tmp/awp$$		# tempfile for building pass 2
  errs=/tmp/awe$$		# error messages (awk can't send to stderr)
  
! while [ $# -ne 0 ]
! do
! 	case "$1" in
! 	-ms)
! 		mac=ms
! 		;;
! 	-man)
! 		mac=man
! 		;;
! 	-rtf)
! 		rtfmode="yes";
! 		;;
! 	-*)
! 		echo $USAGE >&2
! 		exit 2
! 		;;
! 	*)
! 		break;
! 		;;
! 	esac
! 	shift
! done
! 
! if [ \( $mac"x" = "x" \) -o \( $1"x" = "x" \) ]; then
! 	echo $USAGE >&2
  	exit 2
! fi
! 
! if [ $rtfmode"x" != "x" ]; then
! 	dev="$AWFLIB/dev.rtf"
! 	PASS3=rtfpass3
! else
! 	dev="$AWFLIB/dev.$TERM"
! 	if test ! -r $dev
! 	then
! 		dev="$AWFLIB/dev.dumb"
! 	fi
! 	PASS3=pass3
  fi
  
  trap "rm -f $tmp $errs ; exit 0" 0 1 2
***************
*** 48,54 ****
  		done
  	fi
  	echo ".^e"
! ) | awk -f $AWFLIB/pass1 | awk -f $tmp | awk -f $AWFLIB/pass3
  
  # error messages, if any
  if test -s $errs
--- 91,97 ----
  		done
  	fi
  	echo ".^e"
! ) | $AWK -f $AWFLIB/pass1 | $AWK -f $tmp | $AWK -f $AWFLIB/$PASS3
  
  # error messages, if any
  if test -s $errs
diff -c awf/awf.1:1.1.1.1 awf/awf.1:1.3
*** awf/awf.1:1.1.1.1	Fri Apr  7 04:02:56 1995
--- awf/awf.1	Fri Apr  7 04:02:57 1995
***************
*** 1,3 ****
--- 1,17 ----
+ .\" -*-Nroff-*-
+ .\" ---------------------------------------------------------------------------
+ .\"
+ .\" File:         awf.1
+ .\" RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/awf.1,v 1.3 1995/04/06 19:31:02 chris Exp $
+ .\" Description:  awf manpage
+ .\" Author:       Henry Spencer <henry@zoo.toronto.edu>
+ .\" Created:      13 July 1990
+ .\" Modified:     Thu Apr  6 21:25:27 1995 (Christian Limpach) chris@nice.ch
+ .\" Language:     Nroff
+ .\" Package:      awf
+ .\" Status:       Released
+ .\"
+ .\" ---------------------------------------------------------------------------
  .\" Some of the stuff in this file is a bit contorted, because it's also
  .\" the regression-test input.
  .nr ES 5n
***************
*** 173,179 ****
  to set up resolution, special characters, fonts, etc.,
  and more normal \*(Nr commands to set up page length etc.
  .SH FILES
! All in \fI/usr/lib/awf\fR (this can be overridden by the AWFLIB
  environment variable):
  
  .ta \w'pass2.base'u+((3n-1n)/2u)
--- 187,193 ----
  to set up resolution, special characters, fonts, etc.,
  and more normal \*(Nr commands to set up page length etc.
  .SH FILES
! All in \fI/usr/local/lib/awf\fR (this can be overridden by the AWFLIB
  environment variable):
  
  .ta \w'pass2.base'u+((3n-1n)/2u)
diff -c /dev/null awf/dev.rtf:1.2
*** /dev/null	Fri Apr  7 04:02:57 1995
--- awf/dev.rtf	Fri Apr  7 04:02:58 1995
***************
*** 0 ****
--- 1,174 ----
+ .\" -*-Nroff-*-
+ .\" ---------------------------------------------------------------------------
+ .\"
+ .\" File:         dev.rtf
+ .\" RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/dev.rtf,v 1.2 1995/04/06 19:31:04 chris Exp $
+ .\" Description:  dev dependent file for rtf output
+ .\" Author:       Christian Limpach <chris@nice.ch>
+ .\" Created:      Sun May 29 01:36:37 1994
+ .\" Modified:     Thu Apr  6 21:26:02 1995 (Christian Limpach) chris@nice.ch
+ .\" Language:     Nroff
+ .\" Package:      awf
+ .\" Status:       Released
+ .\"
+ .\" (C) Copyright 1994, Christian Limpach, all rights reserved.
+ .\" This is free software, and you are welcome to redistribute it
+ .\" under certain conditions; see ftp://nice.ethz.ch/users/chris/TERMS
+ .\" for details. This software comes with ABSOLUTELY NO WARRANTY.
+ .\"
+ .\" ---------------------------------------------------------------------------
+ .\" Device-dependent but not macro-set-dependent definitions.
+ .\" --------------------------------
+ .\" overall formatting initialization
+ .\" 12 cpi horizontal exploits 80-column terminal well (6.5i@12 = 78)
+ .^r cpi 12 6
+ .\" call margin adjustment device-dependent for sake of some unusual cases
+ .ad
+ .\" page parameters
+ .pl 11i
+ .ll 6.5i
+ .po 0
+ .\" --------------------------------
+ .\" fonts, and their hyphens, last font change doubled to set up \fP
+ .^f R
+ .ft R
+ .^c hy 1 -
+ .^f I
+ .ft I
+ .^c hy 1 -
+ .^f B
+ .ft B
+ .^c hy 1 -\b-\b-
+ .ft R
+ .ft R
+ .\" --------------------------------
+ .\" definitions of nroff special characters
+ .\" The character definitions here operate on the "better ugly than invisible"
+ .\" principle, and try to approximate the character *somehow*.  They were
+ .\" tuned for a Teletype 40 line printer, but should give vaguely plausible
+ .\" results on any overprinting ASCII device.
+ .\"
+ .\" first, things that nroff considered builtins
+ .^c \ 1 \\
+ .^c e 1 \\
+ .^c ' 1 '
+ .^c ` 1 `
+ .^c - 1 -
+ .\" some things seem to assume that \+ is like \-
+ .^c + 1 +
+ .\" we do not do backslash-space here, it can't be done with .^c, but the
+ .\" other forms of space we can do
+ .^c 0 1 " 
+ .^c | 0
+ .^c ^ 0
+ .^c & 0
+ .\"
+ .\" and more normal characters
+ .\" note, the hyphenation logic knows about em
+ .^c em 2 --
+ .\" hy is a special case, see above
+ .\" .^c bu 1 s\bÅ
+ .^c bu 1 s\b°
+ .^c sq 2 []
+ .^c ru 1 _
+ .^c 12 1 n\bÓ
+ .^c 14 1 n\bÒ
+ .^c 34 1 n\bÔ
+ .^c de 1 '\b`
+ .^c dg 1 -\b!
+ .^c fm 1 '
+ .^c ct 1 /\bc
+ .^c rg 1 s\bÒ
+ .^c co 1 s\bÓ
+ .^c pl 1 +
+ .^c mi 1 -
+ .^c eq 1 =
+ .^c ** 1 *
+ .^c sc 1 j\bf
+ .^c aa 1 '
+ .^c ga 1 `
+ .^c ul 1 _
+ .^c sl 1 /
+ .^c *a 1 <\ba
+ .^c *b 1 ,\bB
+ .^c *g 1 ,\by
+ .^c *d 1 S\bo
+ .^c *e 1 -\bc
+ .^c *z 1 ,\bL
+ .^c *y 1 ,\bn
+ .^c *h 1 -\b0
+ .^c *i 1 ,\bi
+ .^c *k 1 <\bK
+ .^c *l 1 \\\b>
+ .^c *m 1 ,\bu
+ .^c *n 1 ,\bv
+ .^c *c 1 ,\b3
+ .^c *o 1 o
+ .^c *p 1 -\bn
+ .^c *r 1 p
+ .^c *s 1 -\bo
+ .^c ts 1 s
+ .^c *t 1 ~\bt
+ .^c *u 1 u
+ .^c *f 1 /\bo
+ .^c *x 1 /\b\\
+ .^c *q 1 |\bu
+ .^c *w 1 u\bw
+ .^c *G 2 ~\b|~
+ .^c *D 2 _\b/_\b\\
+ .^c *H 1 -\bO
+ .^c *L 2 /\\
+ .^c *C 1 _\b-\b~
+ .^c *P 2 ~\b|~\b|
+ .^c *S 1 ~\b_\b>
+ .^c *U 1 Y
+ .^c *F 1 |\bO
+ .^c *Q 1 |\bU
+ .^c *W 2 _\b(_\b)
+ .^c sr 2 \\/
+ .^c rn 1 ~
+ .^c >= 1 s\b³
+ .^c <= 1 s\b£
+ .^c == 1 s\bº
+ .^c ~= 1 s\b»
+ .^c ap 1 ~
+ .^c != 1 s\b¹
+ .^c -> 1 s\b®
+ .^c <- 1 s\b¬
+ .^c ua 1 s\b­
+ .^c da 1 s\b¯
+ .^c mu 1 x
+ .^c di 1 s\b¸
+ .^c +- 1 s\b±
+ .^c cu 1 U
+ .^c ca 3 (^)
+ .^c sb 2 (_\b~
+ .^c sp 2 _\b~)
+ .^c ib 2 (~\b_\b=
+ .^c ip 2 ~\b_\b=)
+ .^c if 2 oo
+ .^c pd 1 3\bo
+ .^c gr 1 ~\bV
+ .^c no 1 -
+ .^c is 1 '\b,\bI
+ .^c pt 2 oc
+ .^c es 1 /\bO
+ .^c mo 1 -\bC
+ .^c br 1 |
+ .^c dd 1 I\b|
+ .^c rh 1 s\bÞ
+ .^c lh 1 s\bÜ
+ .^c bs 4 (:-)
+ .^c or 1 |
+ .^c ci 1 O
+ .^c lt 1 ~\b(
+ .^c lb 1 _\b(
+ .^c rt 1 ~\b)
+ .^c rb 1 _\b)
+ .^c lk 1 -\b(
+ .^c rk 1 -\b)
+ .^c bv 1 |
+ .^c lf 1 _\b[
+ .^c rf 1 _\b]
+ .^c lc 1 ~\b[
+ .^c rc 1 ~\b]
diff -c awf/mac.man:1.1.1.1 awf/mac.man:1.3
*** awf/mac.man:1.1.1.1	Fri Apr  7 04:03:00 1995
--- awf/mac.man	Fri Apr  7 04:03:00 1995
***************
*** 1,3 ****
--- 1,17 ----
+ .\" -*-Nroff-*-
+ .\" ---------------------------------------------------------------------------
+ .\"
+ .\" File:         mac.man
+ .\" RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/mac.man,v 1.3 1995/04/06 19:31:06 chris Exp $
+ .\" Description:  macro package used for -man formatting
+ .\" Author:       Henry Spencer <henry@zoo.toronto.edu>
+ .\" Created:      13 July 1990
+ .\" Modified:     Thu Apr  6 21:26:46 1995 (Christian Limpach) chris@nice.ch
+ .\" Language:     Nroff
+ .\" Package:      awf
+ .\" Status:       Released
+ .\"
+ .\" ---------------------------------------------------------------------------
  .\"-----------------
  .de TH
  .ds LH "\\$1(\\$2)
***************
*** 37,42 ****
--- 51,66 ----
  .de SH
  .In 6
  .in 0
+ .ft B
+ \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
+ .ft R
+ .nr in 5n
+ .in \\n(inu
+ ..
+ .\"-----------------
+ .de SS
+ .In 6
+ .in 5n
  .ft B
  \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
  .ft R
diff -c awf/pass1:1.1.1.1 awf/pass1:1.3
*** awf/pass1:1.1.1.1	Fri Apr  7 04:03:01 1995
--- awf/pass1	Fri Apr  7 04:03:02 1995
***************
*** 1,3 ****
--- 1,18 ----
+ #!/usr/local/bin/gawk -f
+ ###############################################################################
+ #
+ # File:         pass1
+ # RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/pass1,v 1.3 1995/04/06 19:31:07 chris Exp $
+ # Description:  macro decoder
+ # Author:       Henry Spencer <henry@zoo.toronto.edu>
+ # Created:      13 July 1990
+ # Modified:     Thu Apr  6 21:27:18 1995 (Christian Limpach) chris@nice.ch
+ # Language:     Awk
+ # Package:      awf
+ # Status:       Released
+ #
+ ###############################################################################
+ 
  # first pass:  macro expansion and .if
  # We support macros, conditionals (of three quite limited forms), and macro
  # argument substitution.
***************
*** 18,23 ****
--- 33,52 ----
  	nargstack[sp] = ""	# to make it an array
  	argstack[sp] = ""	# to make it an array
  	condstack[sp] = ""	# to make it an array
+ 	brstack[sp] = ""	# to make it an array
+ 	brpcstack[sp] = ""	# to make it an array
+         bracket = 0             # bracketed conditional
+ 	bracketpc = 0		# bracket precond
+ }
+ bracket == 2 && $0 !~ /^\'br\\}$/ {	# not executed bracketed conditional
+ 	next
+ }
+ bracket && $0 ~ /^\'br\\}$/ {	# end of bracketed conditional
+ 	bracket = 0
+ 	next
+ }
+ /^'/ {				# comment
+ 	next
  }
  /^\.\^#/ {			# filename and line no of next line: .^# no fn
  	nroffset = (NR+1) - $2
***************
*** 98,103 ****
--- 127,135 ----
  			iflen = length(".if n ") + invert
  			if (substr(line, iflen-1, 1) == "n")
  				cond = 1
+ 		} else if (line ~ /^\.el\\{\\$/) {
+ 		        cond = 1 - bracketpc
+ 			iflen = length(".el")
  		} else if (line ~ /^\.el /) {
  			cond = 1 - prevcond
  			iflen = length(".el ")
***************
*** 111,116 ****
--- 143,155 ----
  		if (cond && iflen > 0)		# trim true conditional off
  			line = substr(line, iflen+1)
  
+ 		if (line ~ /\\{\\$/) {
+ 			bracket = 1 + cond
+ 			bracketpc = 1 - cond
+ 			line = "";
+ 			cond = 0;
+ 		}
+ 
  		# do argument substitution, if necessary
  		if (cond && line ~ /\\\$/) {
  			orig = line
***************
*** 150,155 ****
--- 189,196 ----
  			macrostack[sp] = macro
  			nargstack[sp] = nargs
  			condstack[sp] = cond
+ 			brstack[sp] = bracket
+ 			brpcstack[sp] = bracketpc
  			for (i = 1; i <= nargs; i++)
  				argstack[sp ":" i] = args[i]
  
***************
*** 190,195 ****
--- 231,238 ----
  			macro = macrostack[sp]
  			nargs = nargstack[sp]
  			cond = condstack[sp]
+ 			bracket = brstack[sp]
+ 			bracketpc = brpcstack[sp]
  			for (i = 1; i <= nargs; i++)
  				args[i] = argstack[sp ":" i]
  			sp--
diff -c awf/pass2.base:1.1.1.1 awf/pass2.base:1.4
*** awf/pass2.base:1.1.1.1	Fri Apr  7 04:03:03 1995
--- awf/pass2.base	Fri Apr  7 04:03:04 1995
***************
*** 1,3 ****
--- 1,18 ----
+ #!/usr/local/bin/gawk -f
+ ###############################################################################
+ #
+ # File:         pass2.base
+ # RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/pass2.base,v 1.4 1995/04/06 19:31:09 chris Exp $
+ # Description:  main nroff parser
+ # Author:       Henry Spencer <henry@zoo.toronto.edu>
+ # Created:      13 July 1990
+ # Modified:     Thu Apr  6 21:27:47 1995 (Christian Limpach) chris@nice.ch
+ # Language:     Awk
+ # Package:      awf
+ # Status:       Released
+ #
+ ###############################################################################
+ 
  # second pass:  interpretation of directives
  # A macro-set-specific portion gets interpolated into this at the "#include"
  # line.  As a minimum, it must deal with .^b and .^e and with any input traps.
***************
*** 77,83 ****
  			print dobreak, "flush"
  		next
  	}
- 
  	# the hard case, needs a character-by-character scan
  	s = $0 " "		# the space flushes the last word
  	n = 1			# current position in s
--- 92,97 ----
***************
*** 85,90 ****
--- 99,105 ----
  	period = ""		# "." if this word ended a sentence
  	nsp = 0			# count of spaces seen so far
  	tabpos = 0		# which tab position was used last
+ 	outchars = 0		# characters printed to this line
  	while (n <= length(s)) {
  		c = substr(s, n, 1)
  
***************
*** 93,98 ****
--- 108,114 ----
  			if (inword) {		# ends word
  				if (!backc) {
  					print wordlen, word
+ 					outchars += wordlen+1
  					if (usedhyphen)
  						print nobreak, "nohyphen"
  				}
***************
*** 108,115 ****
  				}
  				backc = 0
  				inword = 1
! 				if (nsp > 1)
  					print nobreak, "gap", nsp
  			}
  		}
  
--- 124,133 ----
  				}
  				backc = 0
  				inword = 1
! 				if (nsp > 1) {
  					print nobreak, "gap", nsp
+ 					outchars += nsp
+ 				}
  			}
  		}
  
***************
*** 119,134 ****
  			if (n != length(s))	# not the trailing flusher
  				period = ""
  		} else if (c == "\t") {
! 			# not really right, should be based on input position
! 			# also, one space following tab gets ignored
! 			tabpos++
! 			if (tabpos <= ntabs)
  				print nobreak, "tabto", tabs[tabpos]
  			nsp = 0
  			period = ""
  		} else if (c == "-" && wordlen > 0) {
  			# hyphen within word
  			print wordlen, word, hyphenwidths[font]
  			print nobreak, "userhyphen", hyphens[font], hyphenwidths[font]
  			word = ""
  			wordlen = 0
--- 137,154 ----
  			if (n != length(s))	# not the trailing flusher
  				period = ""
  		} else if (c == "\t") {
! 			tabpos=1
! 			while(tabpos<ntabs && tabs[tabpos]<outchars)
! 				tabpos++
! 			outchars=tabs[tabpos]+1
!                         if (tabpos <= ntabs)
  				print nobreak, "tabto", tabs[tabpos]
  			nsp = 0
  			period = ""
  		} else if (c == "-" && wordlen > 0) {
  			# hyphen within word
  			print wordlen, word, hyphenwidths[font]
+ 			outchars += wordlen+hyphenwidths[font]
  			print nobreak, "userhyphen", hyphens[font], hyphenwidths[font]
  			word = ""
  			wordlen = 0
***************
*** 200,205 ****
--- 220,226 ----
  				# discretionary hyphen
  				if (wordlen > 0) {
  					print wordlen, word, hyphenwidths[font]
+ 					outchars += wordlen+hyphenwidths[font]
  					print nobreak, "hyphen", hyphens[font], hyphenwidths[font]
  					word = ""
  					wordlen = 0
***************
*** 211,221 ****
--- 232,277 ----
  				n += 2
  				emw = charwidths["em"]
  				print wordlen, word, emw
+ 				outchars += wordlen+emw
  				print nobreak, "userhyphen", chars["em"], emw
  				word = ""
  				wordlen = 0
  				period = ""
  				usedhyphen = 1
+ 			} else if (c == "h") {
+ 				# tabs
+ 				n++
+ 				code = substr(s, n)
+ 				if (code ~ /^\'|[-0-9.]+i\'/) {
+ 	       			  if (inword) {		# ends word
+ 				    if (!backc) {
+ 				      print wordlen, word
+ 				      outchars += wordlen+1
+ 				      if (usedhyphen)
+ 					print nobreak, "nohyphen"
+ 				    }
+ 				    inword = 0
+ 				    nsp = 0
+ 			      	  }
+ 				  print nobreak, "tabto", 8*substr(code,3)
+ 				  n+=match(code, "i")
+ 				  nsp = 0
+ 				  period = ""
+ 				} else {
+ 					n--
+ 					# copied from below, what else
+ 					# should we do ?
+ 					# special-character name
+ 					code = c
+ 					if (code == "(") {
+ 						n++
+ 						code = substr(s, n, 2)
+ 						n++
+ 					}
+ 					word = word chars[code]
+ 					wordlen += charwidths[code]
+ 					period = ""
+ 				}
  			} else {
  				# special-character name
  				code = c
diff -c awf/pass3:1.1.1.1 awf/pass3:1.3
*** awf/pass3:1.1.1.1	Fri Apr  7 04:03:06 1995
--- awf/pass3	Fri Apr  7 04:03:06 1995
***************
*** 1,3 ****
--- 1,18 ----
+ #!/usr/local/bin/gawk -f
+ ###############################################################################
+ #
+ # File:         pass3
+ # RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/pass3,v 1.3 1995/04/06 19:31:10 chris Exp $
+ # Description:  text formatter, final step
+ # Author:       Henry Spencer <henry@zoo.toronto.edu>
+ # Created:      13 July 1990
+ # Modified:     Thu Apr  6 21:28:10 1995 (Christian Limpach) chris@nice.ch
+ # Language:     Awk
+ # Package:      awf
+ # Status:       Released
+ #
+ ###############################################################################
+ 
  # third pass:  setting lines and pages
  # The input language of this pass is basically <width, word> pairs, where
  # "word" may have imbedded strangeness (backspaces, etc.) for font changes
***************
*** 267,273 ****
  		# move to tab stop at $3
  		if (thislinelen < 0)
  			thislinelen = 0		# make line exist
! 		n = $3 - thislinelen
  		if (n > 0) {			# must emit some space
  			line = line substr(sps, 1, n)
  			# nothing before a tab is paddable
--- 282,288 ----
  		# move to tab stop at $3
  		if (thislinelen < 0)
  			thislinelen = 0		# make line exist
! 		n = int($3) - thislinelen
  		if (n > 0) {			# must emit some space
  			line = line substr(sps, 1, n)
  			# nothing before a tab is paddable
diff -c /dev/null awf/rtfpass3:1.5
*** /dev/null	Fri Apr  7 04:03:07 1995
--- awf/rtfpass3	Fri Apr  7 04:03:07 1995
***************
*** 0 ****
--- 1,241 ----
+ #!/usr/local/bin/gawk -f
+ ###############################################################################
+ #
+ # File:         rtfpass3
+ # RCS:          $Header: /Excellent/usr/local/lib/cvs/awf/rtfpass3,v 1.5 1995/04/06 22:58:20 chris Exp $
+ # Description:  awf pass3 filter which creates rtf documents
+ # Author:       Christian Limpach <chris@nice.ch>
+ # Created:      Sun May 29 00:36:37 1994
+ # Modified:     Fri Apr  7 00:42:02 1995 (Christian Limpach) chris@nice.ch
+ # Language:     Awk
+ # Package:      awf
+ # Status:       Released
+ #
+ # (C) Copyright 1994, Christian Limpach, all rights reserved.
+ # This is free software, and you are welcome to redistribute it
+ # under certain conditions; see ftp://nice.ethz.ch/users/chris/TERMS
+ # for details. This software comes with ABSOLUTELY NO WARRANTY.
+ #
+ ###############################################################################
+ 
+ # third pass:  setting lines and pages
+ # The input language of this pass is basically <width, word> pairs, where
+ # "word" may have imbedded strangeness (backspaces, etc.) for font changes
+ # and special characters.  Zero width is not special.  A third field may
+ # appear to indicate that this is a fragment of a word that can be
+ # hyphenated; the third field is the width of the hyphen that would have
+ # to be added if the line broke after this fragment.
+ # Negative widths denote special operations.  -3 is an error message, the
+ # second field being the message.  -1 and -2 are control messages to this
+ # pass, the difference being whether a break is implied or not.  The second
+ # field is a message type string; more fields may appear as arguments.  The
+ # semantics of control messages are often -- but not always! -- similar to
+ # those of troff commands.  For example, "linelen" is .ll, but "center" is
+ # not semantically equivalent to .ce -- it is related but more primitive.
+ 
+ BEGIN {
+   # input and output details
+   FS="\t";
+   nobreak=-1;
+   dobreak=-2;
+   message=-3;
+   errs="awf.errs";	# default only, normally changed by "errsto"
+ 
+   # page setup
+   indent=0;
+   currindent=0;
+   tempindent=0;
+   lastindent=-1;
+   forcenextflush=0;
+   lastflushwasempty=0;
+   
+   # line-builder setup
+   line="";
+   preline="";
+   tabpreline="";
+   tabpreword="";
+   nospace=0;
+   linehastext=0;
+   thislinelen=0;
+   linelen=0;
+   preword="";
+ 
+   # many spaces, so we can use substr to get any number we need
+   sps = "                                                     ";
+   sps = sps sps sps sps sps sps sps sps sps sps;
+ 
+   # rtf setup
+   charsize=160;
+   
+   # print rtf header
+   print "{\\rtf0\\ansi{\\fonttbl\\f2\\fswiss Helvetica;\\f1\\ftech " \
+     "Symbol;\\f0\\fnil Times-Roman;}";
+   print "\\paperw12800";
+   print "\\paperh10200";
+   print "\\margl120";
+   print "\\margr500";
+   print "\\pard\\f0\\b0\\i0\\ul0\\fs24\\fc0\\cf0";
+ }
+ 
+ function flush() {
+   if(linehastext || forcenextflush) {
+     if(linehastext) {
+       print "\\pard" preline line "\\";
+       lastflushwasempty=linehastext=0;
+     } else if (!lastflushwasempty) {
+       print "\\";
+       lastflushwasempty++;
+     }
+   }
+   line=preline="";
+   lastindent=-1;
+   thislinelen=linelen=forcenextflush=0;
+ }
+ 
+ function boldon() {
+   if(!bold) {
+     bold++;
+     w=w "\\b ";
+   }
+ }
+ function boldoff() {
+   if(bold) {
+     bold=0;
+     w=w "\\b0 ";
+   }
+ }
+ function italicon() {
+   if(!italic) {
+     italic++;
+     w=w "\\i ";
+   }
+ }
+ function italicoff() {
+   if(italic) {
+     italic=0;
+     w=w "\\i0 ";
+   }
+ }
+ 
+ function unmangle(word) {
+   w=""; bold=0; italic=0;
+   if(length(word)>2) {
+     l2=substr(word, 1, 1);
+     for(i=2; i<=length(word)-1; i++) {
+       l1=l2;
+       l2=substr(word, i, 1);
+       sub(/\\/, "\\\\", l1);
+       if(l2=="") {
+ 	if(l1==substr(word, i+1, 1)) {
+ 	  italicoff();
+ 	  boldon();
+ 	  i+=4;
+ 	  l2=substr(word, i, 1);
+ 	} else if(l1=="_") {
+ 	  boldoff();
+ 	  italicon();
+ 	  l1=substr(word, i+1, 1);
+ 	  i+=2;
+ 	  l2=substr(word, i, 1);
+ 	} else if(l1=="n") {
+ 	  boldoff();
+ 	  italicoff();
+ 	  l1=substr(word, i+1, 1);
+ 	  i+=2;
+ 	  l2=substr(word, i, 1);
+ 	} else if(l1=="s") {
+ 	  boldoff();
+ 	  italicoff();
+ 	  l1="\\f1 " substr(word, i+1, 1) "\\f0 ";
+ 	  i+=2;
+ 	  l2=substr(word, i, 1);
+ 	} else {
+ 	  print "unsupported highlight mode!" > "/dev/stderr";
+ 	  print word > "/dev/stderr";
+ 	}
+       } else {
+ 	boldoff();
+ 	italicoff();
+       }
+       sub("}", "\\}", l1);
+       sub("{", "\\{", l1);
+       w=w l1;
+     }
+   } else {
+     i=2;
+   }
+   boldoff();
+   italicoff();
+   i-=1;
+   while(i<=length(word)) {
+     l1=substr(word, i++, 1);
+     sub(/\\/, "\\\\", l1);
+     sub("}", "\\}", l1);
+     sub("{", "\\{", l1);
+     w=w l1;
+   }
+   return w;
+ }
+ 
+ {
+   if($1>0) {
+     nw=unmangle($2);
+     linelen+=$1*charsize;
+     if(preword || tabpreword)
+       line=line preword tabpreword;
+     if(nospace || !linehastext) {
+       linehastext++;
+       line=line nw;
+       nospace=0;
+     } else {
+       line=line " " nw;
+     }
+     preline=preline tabpreline;
+     tabpreline=tabpreword=preword="";
+     if($3) {
+       nospace++;
+     }
+   } else if ($1==dobreak) {
+     if($2=="indent") {
+       currindent=indent=$3;
+       flush();
+     } else if($2=="tempindent") {
+       preword=preword "\\tx" charsize*currindent " ";
+       currindent=indent+(tempindent=$3);
+     } else if($2=="toindent") {
+       currindent=indent;
+       preword=preword "\t";
+       nospace++;
+     } else if($2=="space") {
+       flush();
+       forcenextflush++;
+       flush();
+     } else if($2=="center") {
+       preline=preline "\\qc";
+     } else {
+       flush();
+     }
+   } else if ($1==nobreak) {
+     if($2=="gap") {
+       # ignore gaps, doesn't look good in rtf files...
+       preword=preword substr(sps, 1, $3-1);
+     } else if($2=="userhyphen") {
+       linelen+=$4*charsize;
+       preword=preword unmangle($3);
+     } else if($2=="tabto") {
+       if(charsize*($3+currindent)>linelen) {
+ 	tabpreline="\\tx" charsize*($3+currindent);
+         tabpreword="\t";
+ 	nospace++;
+       }
+     }
+   }
+   if(lastindent!=currindent) {
+     preword=preword "\\li" charsize*currindent " ";
+     lastindent=currindent;
+   }
+ }
+ END {
+   flush();
+   print "}";
+ }
