1 04/15/88  "SHOW" EXAMPLE
 2 
 3 /*        SHOW.  This program takes a filename
 4  *        as input and displays it on the screen,
 5  */       similar to the more command.
 6 
 7 #include <curses.h>
 8 #include <signal.h>
 9 
10 char sysline[50]='0';
11 int segno=0;
12 
13 main(argc, argv)
14 int argc;
15 char *argv[];
16 {
17           FILE *fd;
18           char linebuf[BUFSIZ];
19           int line;
20           void done();
21 
22 
23           if (argc != 2)
24              {
25              fprintf (stderr,"Usage: %s file-name\n", argv[0]);
26              exit(1);
27              }
28           if ((fd=fopen(argv[1], "r")) == NULL)
29              {
30              perror(argv[1]);
31              exit(2);
32              }
33 
34           signal(SIGINT, done);
35 
36 
37           initscr();
38           noecho();
39           cbreak();
40           nonl();
41           idlok(stdscr, TRUE);
42 
43           while (1)
44                 {
45                 move (0,0);
46                 for (line=0; line<(LINES-1); line++)
47                     {
48                     if (fgets (linebuf, sizeof linebuf, fd) == NULL)
49                        {
50                        clrtobot();
51                        standout();
52                        mvaddstr(23,0,"EOF reached");
53                        standend();
54                        }
55                      else
56                        {
57                        move (line,0);
58 
59 
60                        clrtoeol();
61                        printw("%s", linebuf);
62                        }
63                      }
64 
65                     move (23,0);
66                     (void) refresh();
67 
68                     if (getch () == 'q'  )
69                        done();
70           }
71 }
72 
73 void done ()
74 
75 
76 {
77   move(LINES-1, 0);
78   erase();
79   refresh();
80   endwin();
81   exit(0);
82 
83 }
84