[comp.windows.x] Making xman handle nroff overstriking

clyde@ut-emx.UUCP (Head UNIX Hacquer) (11/16/88)

Below is a patch to xman which allows it to handle nroff overstriking.
We keep our 'cat' manual pages in a form for line printer output, so we
have overstriking in them.  Xman botches overstrikes very badly.  With this
mod, it will handle them properly (well, it works for our manual pages).

With the overstrike handling enabled, xman will occasionally output the
line after the page header in bold face.  I don't know just why this happens,
but turning off the BOLDEN_HEADER define prevents it from happening.
If your 'cat' form manual pages don't have overstrikes in their title lines,
then turn on BOLDEN_HEADER.  The variety of manual page macros and nroff
options used in man programs make the task of reading a 'cat' file and
doing font changes a pain.  

*** clients/xman/pages.c.orig	Fri Nov 11 15:07:24 1988
--- clients/xman/pages.c	Fri Nov 11 15:12:22 1988
***************
*** 267,276
   * We put chars into buf until either a font change or newline
   * occurs (at which time we flush it to the screen.)
   */
  
    for(first = FALSE,buf[0] = '\0',bufp = buf,col=INDENT;;) {
      if (current_line % NLINES == 3 && !IS_HELP(w) )
        first = TRUE;
  
      switch(*c) {
  

--- 267,277 -----
   * We put chars into buf until either a font change or newline
   * occurs (at which time we flush it to the screen.)
   */
  
    for(first = FALSE,buf[0] = '\0',bufp = buf,col=INDENT;;) {
+ #ifdef	BOLDEN_HEADER
      if (current_line % NLINES == 3 && !IS_HELP(w) )
        first = TRUE;
+ #endif
  
      switch(*c) {
***************
*** 340,349
  
      case '\033':		/* ignore esc sequences for now */
        c++;			/* should always be esc-x */
        break;
  
     case '_':			/* look for underlining [italicize] */
        c++;
        if(*c != BACKSPACE) {
  
  	/* oops real underscore, fall through to default. */

--- 342,399 -----
  
      case '\033':		/* ignore esc sequences for now */
        c++;			/* should always be esc-x */
        break;
  
+     case BACKSPACE:		/* Backspacing for nroff bolding */
+       if (c[-1] == c[1]) {	/* overstriking one char */
+  	    *--bufp = '\0';	/* Zap 1st instance of char to bolden */
+  	    if (bufp > &buf[0]) {
+ 		if (italicflag) {
+  	           XDrawString(disp,window,italic_gc,col,y_loc,buf,strlen(buf));
+  	           col += XTextWidth(fonts.italic,buf,strlen(buf));
+ 		}
+ 		else {
+  	           XDrawString(disp,window,normal_gc,col,y_loc,buf,strlen(buf));
+  	           col += XTextWidth(fonts.normal,buf,strlen(buf));
+ 		}
+  	        bufp = buf;
+  	    }
+ 	    /*
+ 	     * It is painful writing one bold char at a time but
+ 	     * it is the only safe way to do it.  We trust that the library
+ 	     * buffers these one-char draw requests and sends one large
+ 	     * request packet.
+ 	     */
+  	     *bufp = c[1];
+  	     XDrawString(disp,window,bold_gc,col,y_loc,bufp,1);
+  	     col += XTextWidth(fonts.bold,bufp,1);
+  	     *bufp = '\0';
+ 
+  	    /*
+  	     *     Nroff bolding looks like:
+  	     *	 	     C\bC\bC\bCN...
+  	     * c points to ----^      ^
+  	     * it needs to point to --^
+  	     */
+  	    while (*c == BACKSPACE && c[-1] == c[1])
+  	    	c += 2;
+  	    c--;		/* Back up to previous char */
+       }
+       else {
+  	    if ((c[-1] == 'o' && c[1] == '+')		/*  Nroff bullet */
+  	     || (c[-1] == '+' && c[1] == 'o')) {	/*  Nroff bullet */
+  			/* I would prefer to put a 'bullet' char here */
+  		*bufp++ = 'o';
+ 		c++;
+  	    }
+  	    else {		/* 'real' backspace - back up output ptr */
+  		bufp--;
+  	   }
+       }
+       break;
+  
     case '_':			/* look for underlining [italicize] */
        c++;
        if(*c != BACKSPACE) {
  
  	/* oops real underscore, fall through to default. */
-- 
Shouter-To-Dead-Parrots @ Univ. of Texas Computation Center; Austin, Texas  
	clyde@emx.utexas.edu; ...!cs.utexas.edu!ut-emx!clyde

"You really have to take a broad perspective when giving pat answers
 to other people's problems."  - Eyebeam