From e8f71e4fd89237edcbcbdc0195dca0e5e5c651c0 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 21 Nov 2009 11:15:39 -0500 Subject: [PATCH] mangling the simple attr example (8.) --- basics/simple_attr.c | 83 ++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/basics/simple_attr.c b/basics/simple_attr.c index 5b4b9ed..b6ef1b3 100644 --- a/basics/simple_attr.c +++ b/basics/simple_attr.c @@ -1,54 +1,47 @@ -/* pager functionality by Joseph Spainhour" */ #include #include int main(int argc, char *argv[]) { - int ch, prev, row, col; - prev = EOF; - FILE *fp; - int y, x; + int ch, prev, row, col; + prev = EOF; + FILE *fp; + int y, x; - if(argc != 2) - { - printf("Usage: %s \n", argv[0]); - exit(1); - } - fp = fopen(argv[1], "r"); - if(fp == NULL) - { - perror("Cannot open input file"); - exit(1); - } - initscr(); /* Start curses mode */ - getmaxyx(stdscr, row, col); /* find the boundaries of the screeen */ - while((ch = fgetc(fp)) != EOF) /* read the file till we reach the end */ - { - getyx(stdscr, y, x); /* get the current curser position */ - 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(); - clear(); /* clear the screen */ - move(0, 0); /* start at the beginning of the screen */ + if (argc != 2) { + printf("Usage: %s \n", argv[0]); + exit(1); } - if(prev == '/' && ch == '*') /* If it is / and * then only - * switch bold on */ - { - attron(A_BOLD); /* cut bold on */ - getyx(stdscr, y, x); /* get the current curser position */ - move(y, x - 1); /* back up one space */ - printw("%c%c", '/', ch); /* The actual printing is done here */ + fp = fopen(argv[1], "r"); + if (fp == NULL) { + perror("Cannot open input file"); + exit(1); } - else - printw("%c", ch); - refresh(); - if(prev == '*' && ch == '/') - attroff(A_BOLD); /* Switch it off once we got * - * and then / */ - prev = ch; - } - endwin(); /* End curses mode */ - fclose(fp); - return 0; + initscr(); + getmaxyx(stdscr, row, col); + while ((ch = fgetc(fp)) != EOF) { + getyx(stdscr, y, x); + if (y == (row - 1)) { + printw("<-Press Any Key->"); + getch(); + clear(); + move(0, 0); + } + if (prev == '/' && ch == '*') { + attron(A_BOLD | COLOR_GREEN); + getyx(stdscr, y, x); + move(y, x - 1); + printw("%c%c", '/', ch); + } else { + printw("%c", ch); + refresh(); + if (prev == '*' && ch == '/') { + attroff(A_BOLD | COLOR_GREEN); + prev = ch; + } + } + } + endwin(); + fclose(fp); + return 0; }