mangling the simple attr example (8.)
This commit is contained in:
parent
579ad3c15e
commit
e8f71e4fd8
@ -1,4 +1,3 @@
|
|||||||
/* pager functionality by Joseph Spainhour" <spainhou@bellsouth.net> */
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -9,46 +8,40 @@ 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(); /* Start curses mode */
|
initscr();
|
||||||
getmaxyx(stdscr, row, col); /* find the boundaries of the screeen */
|
getmaxyx(stdscr, row, col);
|
||||||
while((ch = fgetc(fp)) != EOF) /* read the file till we reach the end */
|
while ((ch = fgetc(fp)) != EOF) {
|
||||||
{
|
getyx(stdscr, y, x);
|
||||||
getyx(stdscr, y, x); /* get the current curser position */
|
if (y == (row - 1)) {
|
||||||
if(y == (row - 1)) /* are we are at the end of the screen */
|
printw("<-Press Any Key->");
|
||||||
{
|
|
||||||
printw("<-Press Any Key->"); /* tell the user to press a key */
|
|
||||||
getch();
|
getch();
|
||||||
clear(); /* clear the screen */
|
clear();
|
||||||
move(0, 0); /* start at the beginning of the screen */
|
move(0, 0);
|
||||||
}
|
}
|
||||||
if(prev == '/' && ch == '*') /* If it is / and * then only
|
if (prev == '/' && ch == '*') {
|
||||||
* switch bold on */
|
attron(A_BOLD | COLOR_GREEN);
|
||||||
{
|
getyx(stdscr, y, x);
|
||||||
attron(A_BOLD); /* cut bold on */
|
move(y, x - 1);
|
||||||
getyx(stdscr, y, x); /* get the current curser position */
|
printw("%c%c", '/', ch);
|
||||||
move(y, x - 1); /* back up one space */
|
} else {
|
||||||
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); /* Switch it off once we got *
|
attroff(A_BOLD | COLOR_GREEN);
|
||||||
* and then / */
|
|
||||||
prev = ch;
|
prev = ch;
|
||||||
}
|
}
|
||||||
endwin(); /* End curses mode */
|
}
|
||||||
|
}
|
||||||
|
endwin();
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user