home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_01 / 8n01095a < prev    next >
Text File  |  1990-02-19  |  2KB  |  106 lines

  1. *****Listing 2*****
  2.  
  3. /*
  4.  *    Bold.c - filters nroff output for terminal display
  5.  *         displays bold in SO, underlines, expanded font
  6.  *    copyright 1987 Ronald Florence
  7.  */
  8.  
  9. #include    <stdio.h>
  10.  
  11. #define UL        01
  12. #define BOLD        02
  13. #define ULSTOP        04
  14. #define Bold()        tputs(so, 1, prch), att |= BOLD
  15. #define Stopbold()    tputs(se, 1, prch), att &= ~BOLD
  16. #define Uline()        tputs(us, 1, prch), att |= UL
  17. #define Stopuline()    tputs(ue, 1, prch), att &= ~(UL|ULSTOP)
  18.  
  19. prch(c)
  20.      register char c;
  21. {
  22.   putchar(c);
  23. }
  24.  
  25. char    *so, *se, *us, *ue;
  26.  
  27. main()
  28. {
  29.   static  char    sbuf[256]; 
  30.   char    tbuf[1024], *fill = sbuf, *tgetstr(), *getenv();
  31.   register    a, c;
  32.   int    i, att = 0;
  33.  
  34.   if (tgetent(tbuf, getenv("TERM")) == 1 && tgetnum("sg") < 1) 
  35.     {
  36.       so = tgetstr("so", &fill);
  37.       se = tgetstr("se", &fill);
  38.       us = tgetstr("us", &fill);
  39.       ue = tgetstr("ue", &fill);
  40.     }
  41.   a = getchar();
  42.   while ((c = getchar()) != EOF) 
  43.     {
  44.       if (a == '_') 
  45.     {
  46.       if (c == '_' && (att & UL) == 0) 
  47.         Uline();
  48.       else if (c == '\b')    /* nroff italics */ 
  49.         {        
  50.           if ((a = getchar()) == EOF)
  51.         a = 0;
  52.           c = getchar();
  53.           if ((att & UL) == 0)
  54.         Uline();
  55.         }
  56.       if (c != '_' && (att & UL)) 
  57.                 /* c is the last underline */
  58.         att |= ULSTOP;
  59.     }
  60.       else if (c == '\b')
  61.     {
  62.       if ((c = getchar()) != a) 
  63.         {            /* Not a bold: print the character
  64.                    and pass the \b to be printed. */
  65.           putout(a);
  66.           a = '\b';
  67.         }
  68.       else 
  69.         {
  70.           if ((att & BOLD) == 0) 
  71.         Bold();
  72.           for (i = 0; i < 5; i++)
  73.         if ((c = getchar()) != a && c != '\b') 
  74.           break;
  75.         }
  76.     }
  77.       else if (att & BOLD) 
  78.     Stopbold();
  79.       putout(a);
  80.       if (att & ULSTOP) 
  81.     Stopuline();
  82.       a = c;
  83.     }
  84. }
  85.  
  86.  
  87. putout(c)
  88.      register    char    c;
  89. {
  90.   static int    expanded;
  91.  
  92.   if (c == 07)            /* ^G signals expanded font */
  93.     {
  94.       expanded++;
  95.       return(0);
  96.     }
  97.   putchar(c);
  98.   if (expanded) 
  99.     {
  100.       if (c == '\n')
  101.     expanded = 0;
  102.       else
  103.     putchar(' ');
  104.     }
  105. }
  106.