1 04/15/88  "HIGHLIGHT" EXAMPLE
 2 
 3 /*
 4  *        HIGHLIGHT. A program to turn U, B, and
 5  *        N sequences into highlighted
 6  *        output, allowing words to be
 7  *        displayed underlined or in bold.
 8  */
 9 
10 #include <curses.h>
11 
12 
13 main(argc, argv)
14 char **argv;
15 {
16           FILE *fd;
17           int c, c2;
18 
19 
20           if (argc !=2){
21                     fprintf(stderr, "Usage: highlight file0\n");
22                     exit(1);
23           }
24 
25 
26           fd = fopen(argv[1], "r");
27           if (fd == NULL) {
28                     perror(argv[1]);
29                     exit(2);
30           }
31 
32           initscr();
33 
34           scrollok(stdscr, TRUE);
35 
36           for (;;) {
37                     c = getc(fd);
38                     if (c == EOF)
39                               break;
40 
41 
42                     if (c == '\\')
43                        {
44                        c2 = getc(fd);
45                        switch (c2)
46                               {
47                               case 'B':
48                                         attrset(A_BOLD);
49                                         continue;
50                               case'U':
51                                         attrset(A_UNDERLINE);
52                                         continue;
53 
54                               case'N':
55                                         attrset(0);
56 
57 
58                                         continue;
59                               }
60                               addch(c);
61                               addch(c2);
62                         }
63                     else
64                               addch(c);
65                     }
66 
67                     fclose(fd);
68                     refresh();
69                     endwin();
70                     exit(0);
71           }
72