Unix Programming - [ncurses] cat xxx |more

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2006 > [ncurses] cat xxx |more





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author [ncurses] cat xxx |more
lszk

2006-07-15, 7:19 pm

Code from ncurses howto:

#include <ncurses.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int ch, prev, row, col;
prev = EOF;
FILE *fp;
int y, x;

if(argc != 2)
{
printf("Usage: %s <a c file name>\n", argv[0]);
exit(1);
}
fp = fopen(argv[1], "r");
if(fp == NULL)
{
perror("Cannot open input file");
exit(1);
}
initscr();
getmaxyx(stdscr, row, col);
while((ch = fgetc(fp)) != EOF)
{
getyx(stdscr, y, x);
if(y == (row - 1))
{
printw("<-Press Any Key->");
/// refresh();
getch();
clear();
move(0, 0);
}
if(prev == '/' && ch == '*')
{
attron(A_BOLD);
getyx(stdscr, y, x);
move(y, x - 1);
printw("%c%c", '/', ch);
}
else
printw("%c", ch);
refresh();
if(prev == '*' && ch == '/')
attroff(A_BOLD);

prev = ch;
}
refresh();
getch();
endwin();
fclose(fp);
return 0;
}

Works something like a linux cat. But this program is limited by *term
window size. How can I get something like a linux more?

cat file |more - when the text from file is too long, I can press
enter or space and the *term window is "lengthen" (I can't find better
word ;-)
I think this is understanding ;-]
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com