1 04/15/88  "termhl" EXAMPLE
  2 
  3 /*
  4  *        TERMHL.  A terminfo level version of highlight.
  5  */
  6 
  7 #include <curses.h>
  8 #include <term.h>
  9 
 10 #define LF 012
 11 
 12 int ulmode =0;      /* Currently underlining */
 13 
 14 
 15 main(argc, argv)
 16 char **argv;
 17 {
 18           FILE *fd;
 19           int  c, c2;
 20           int outch();
 21 
 22           if (argc > 2) {
 23                     fprintf(stderr, "Usage: termhl [file-name]\n");
 24                     exit(1);
 25           }
 26 
 27 
 28           if(argc == 2) {
 29                     fd = fopen(argv[1], "r");
 30                     if (fd == NULL) {
 31                               perror(argv[1]);
 32                               exit(2);
 33                     }
 34           } else {
 35                     fd = stdin;
 36           }
 37 
 38      setupterm(NULL,1,NULL);
 39 
 40 
 41           for (;;) {
 42                     c = getc(fd);
 43                     if (c==EOF)
 44                        break;
 45                     if (c=='\\') {
 46                        c2 = getc(fd);
 47                        switch (c2) {
 48                               case  'B':
 49                                     if (enter_bold_mode == NULL )
 50                                        tputs (enter_reverse_mode, 1,
 51                                              outch);
 52                                     else
 53                                         tputs (enter_bold_mode, 1,
 54                                               outch);
 55                                     continue;
 56 
 57 
 58                               case  'U':
 59                                     tputs (enter_underline_mode, 1,
 60                                           outch);
 61                                     ulmode = 1;
 62                                     continue;
 63                               case  'N':
 64                                     tputs (exit_attribute_mode, 1,
 65                                           outch);
 66                                     ulmode = 0;
 67                                     continue;
 68                               }
 69                          putch (c);
 70                          putch(c2);
 71                          }
 72                     else
 73 
 74 
 75                               putch(c);
 76           }
 77 
 78           fclose(fd);
 79           fflush(stdout);
 80           resetterm();
 81           exit(0);
 82 }
 83 
 84 
 85 /*
 86  * This function is like putchar.
 87  */
 88 
 89 putch(c)
 90 int c;
 91 {
 92           outch(c);
 93 }
 94 
 95 
 96 /*
 97  * Outchar is a function version of putchar that can be passed to
 98  * tputs as a routine to call.
 99  */
100 outch(c)
101 int c;
102 {
103           putchar(c);
104 }