|
|
1.1 root 1: #include <curses.h>
2: #include <signal.h>
3:
4: #ifdef DEBUGfoo
5: #undef LINES
6: #define LINES 5
7: #endif
8:
9: main(argc, argv)
10: char **argv;
11: {
12: FILE *fd;
13: char linebuf[512];
14: int line;
15: int done();
16:
17: if (argc < 2) {
18: (void) fprintf(stderr, "Usage: show file\n");
19: exit(1);
20: }
21: fd = fopen(argv[1], "r");
22: if (fd == NULL) {
23: perror(argv[1]);
24: exit(2);
25: }
26: (void) signal(SIGINT, done); /* die gracefully */
27:
28: initscr(); /* initialize curses */
29: noecho(); /* turn off tty echo */
30: cbreak(); /* enter cbreak mode */
31: nonl(); /* allow more optimizations */
32: idlok(stdscr, TRUE); /* allow insert/delete line */
33:
34: for (;;) { /* for each screen full */
35: (void) move(0, 0);
36: /* werase(stdscr); */
37: for (line=0; line<LINES; line++) {
38: if (fgets(linebuf, sizeof linebuf, fd) == NULL) {
39: clrtobot();
40: done();
41: }
42: (void) mvprintw(line, 0, "%s", linebuf);
43: }
44: (void) refresh(); /* sync screen */
45: if(getch() == 'q') /* wait for user to read it */
46: done();
47: }
48: }
49:
50: /*
51: * Clean up and exit.
52: */
53: done()
54: {
55: (void) move(LINES-1,0); /* to lower left corner */
56: clrtoeol(); /* clear bottom line */
57: (void) refresh(); /* flush out everything */
58: endwin(); /* curses cleanup */
59: exit(0);
60: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.