Revert "mangling the simple attr example (8.)"

This reverts commit e8f71e4fd8.
cat-town
Dan Buch 15 years ago
parent e8f71e4fd8
commit 92c130fcd5

@ -1,3 +1,4 @@
/* pager functionality by Joseph Spainhour" <spainhou@bellsouth.net> */
#include <ncurses.h> #include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
@ -8,40 +9,46 @@ int main(int argc, char *argv[])
FILE *fp; FILE *fp;
int y, x; int y, x;
if (argc != 2) { if(argc != 2)
{
printf("Usage: %s <a c file name>\n", argv[0]); printf("Usage: %s <a c file name>\n", argv[0]);
exit(1); exit(1);
} }
fp = fopen(argv[1], "r"); fp = fopen(argv[1], "r");
if (fp == NULL) { if(fp == NULL)
{
perror("Cannot open input file"); perror("Cannot open input file");
exit(1); exit(1);
} }
initscr(); initscr(); /* Start curses mode */
getmaxyx(stdscr, row, col); getmaxyx(stdscr, row, col); /* find the boundaries of the screeen */
while ((ch = fgetc(fp)) != EOF) { while((ch = fgetc(fp)) != EOF) /* read the file till we reach the end */
getyx(stdscr, y, x); {
if (y == (row - 1)) { getyx(stdscr, y, x); /* get the current curser position */
printw("<-Press Any Key->"); if(y == (row - 1)) /* are we are at the end of the screen */
{
printw("<-Press Any Key->"); /* tell the user to press a key */
getch(); getch();
clear(); clear(); /* clear the screen */
move(0, 0); move(0, 0); /* start at the beginning of the screen */
} }
if (prev == '/' && ch == '*') { if(prev == '/' && ch == '*') /* If it is / and * then only
attron(A_BOLD | COLOR_GREEN); * switch bold on */
getyx(stdscr, y, x); {
move(y, x - 1); attron(A_BOLD); /* cut bold on */
printw("%c%c", '/', ch); getyx(stdscr, y, x); /* get the current curser position */
} else { move(y, x - 1); /* back up one space */
printw("%c%c", '/', ch); /* The actual printing is done here */
}
else
printw("%c", ch); printw("%c", ch);
refresh(); refresh();
if (prev == '*' && ch == '/') { if(prev == '*' && ch == '/')
attroff(A_BOLD | COLOR_GREEN); attroff(A_BOLD); /* Switch it off once we got *
* and then / */
prev = ch; prev = ch;
} }
} endwin(); /* End curses mode */
}
endwin();
fclose(fp); fclose(fp);
return 0; return 0;
} }

Loading…
Cancel
Save