box-o-sand/basics/simple_attr.c

48 lines
1.0 KiB
C
Raw Normal View History

2009-11-19 00:01:16 +00:00
#include <ncurses.h>
#include <stdlib.h>
int main(int argc, char *argv[])
2009-11-19 00:38:43 +00:00
{
2009-11-21 16:15:39 +00:00
int ch, prev, row, col;
prev = EOF;
FILE *fp;
int y, x;
2009-11-19 00:01:16 +00:00
2009-11-21 16:15:39 +00:00
if (argc != 2) {
printf("Usage: %s <a c file name>\n", argv[0]);
exit(1);
2009-11-19 00:01:16 +00:00
}
2009-11-21 16:15:39 +00:00
fp = fopen(argv[1], "r");
if (fp == NULL) {
perror("Cannot open input file");
exit(1);
2009-11-19 00:01:16 +00:00
}
2009-11-21 16:15:39 +00:00
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;
2009-11-19 00:01:16 +00:00
}