Curses, Curses (ye little kleinhund Snoopy! :-)
Orville R. Weyrich
orville at weyrich.UUCP
Sat Jun 22 19:14:57 AEST 1991
I have a problem with "curses" on my Microport System V/386 system (rev. 3).
[If it is significant, I have DOS MERGE installed on the system, as well as
"fas" version 2.07.
I decided to write my own "more" program using curses. It works fine when
invoked from a tty line at 9600 baud (remote computer running KERMIT emulating
a VT102).
It works fine when invoked from a tty line at 1200 baud (remote computer
is a CP/M machine running a custom-made emulator program, with a custom made
terminfo entry).
It DOES NOT work fine when invoked at my console. It appears to be loosing
characters.
Consider for example my test file (the "x" is in column 80, the "y" is in
column 81 of the input, whould be placed at column 1 of the next line by
my "pager" program):
==========too short =======
==============================just right ======================================x
=======================================longer =================================xy
=========================================humongous ============================xy===========
the end.
As I said, it comes out fine on my remote terminals. On the console it comes
out as
=too short =======
=just right =x=longer =xy==============================
=humongous =x============================
the end.
It does essentially the same thing regardless of whether I use the AT386
terminfo entry supplied with the system or a modified version which has
delays introduced (I put $<100> at the end of the curses functions
rep, nel, cup, il1, il, ich, cr, cud, cud1, hpa).
I attach below the program which I wrote. I compile it using the Green Hills
C compiler.
Does anyone have any idea what could be the problem?
Thanks in advance.
Orville.
-------------------------------------- ******************************
Orville R. Weyrich, Jr., Ph.D. Certified Systems Professional
Internet: orville%weyrich at uunet.uu.net Weyrich Computer Consulting
Voice: (602) 391-0821 POB 5782, Scottsdale, AZ 85261
Fax: (602) 391-0023 (Yes! I'm available)
-------------------------------------- ******************************
Source code follows:
#include <stdio.h>
#include <curses.h>
#include <signal.h>
/* ========================= file function headers ========================== */
void main(); /* Pager program entry point. */
void start_up(); /* Program initialization code. */
int wrap_up(); /* Program termination code. */
void process_file(); /* Displays specified file on screen. */
int get_key(); /* Prompt for key press and wait */
void display_line(); /* Display a line with proper wrap. */
int get_line(); /* Gets a line without nl terminator. */
/* Line is null-terminated. */
/* Returns EOF if no more characters, */
/* else returns line length. */
/* ========================== file function code ============================ */
void main /* pager program entry point */
( arg_c, /* count of command line arguments */
arg_v ) /* array of argument string value pointers */
int arg_c;
char * arg_v[];
{
char * file_name; /* input file name string */
int arg_i; /* argument index counter */
int ignore; /* function return value ignored */
start_up();
for ( arg_i = 1; arg_i < arg_c ; arg_i++ )
{
if ( arg_v[ arg_i ][0] == '-' )
{
printw( "DASH\n" );
}
else
{
file_name = arg_v[ arg_i ];
process_file( file_name );
}
}
ignore = wrap_up();
}
void start_up() /* Program initialization code. */
{
signal( SIGINT, wrap_up ); /* terminate upon interrupt */
initscr(); /* curses */
raw(); /* curses */
noecho(); /* curses */
nonl(); /* curses */
}
int wrap_up() /* Program termination code. */
{
signal( SIGINT, SIG_IGN ); /* ignore interrupts */
move( LINES-1, 0 ); /* curses */
clrtoeol(); /* curses */
refresh(); /* curses */
nl(); /* curses */
echo(); /* curses */
noraw(); /* curses */
endwin(); /* curses */
exit( 0 );
}
void process_file /* Displays specified file on screen. */
( file_name ) /* File spec to be for file to display. */
char * file_name;
{
FILE * in_file; /* Input file pointer. */
char line_buf[81]; /* Current line to display. */
int leng; /* Current line length. */
int ans; /* Key pressed by user. */
int line_pos; /* Cursor line number on this screen. */
int ignore; /* Return value from function ignored. */
clear(); /* curses */
move( 0, 0 ); /* curses */
standout(); /* curses */
printw( "================= %s ==================\n", file_name );
standend(); /* curses */
in_file = fopen( file_name, "r" );
if ( in_file != NULL )
{
line_pos = 2;
while ( (leng=get_line( line_buf, in_file )) != EOF )
{
move( line_pos++, 0 ); /* curses */
display_line( line_buf );
if ( line_pos >= LINES-2 )
{
ans = get_key();
line_pos = 2;
move( line_pos, 0 ); /* curses */
clrtobot(); /* curses */
}
}
ans = get_key();
ignore = fclose( in_file );
}
/* else ignore the request */
}
int get_key() /* Prompt for key press and wait */
{
move( LINES-1, 0 ); /* curses */
standout(); /* curses */
printw( "============ press any key ============" );
standend(); /* curses */
refresh(); /* curses */
return getch(); /* curses */
}
void display_line /* Display a line with proper wrap. */
( line_buf ) /* Line to display. */
char line_buf[];
{
printw( "%s", line_buf );
}
int get_line /* Gets a line without nl terminator. */
( line_buf, /* Null-terminated line. */
in_file ) /* Input file pointer. */
char line_buf[81];
FILE * in_file;
{
int leng = 0; /* Line length so far. */
int ch; /* input char or EOF */
while ( leng < 81
&& (ch=fgetc( in_file )) != '\n'
&& ch != EOF )
{
line_buf[ leng++ ] = ch;
}
line_buf[ leng ] = '\0';
if ( ch == EOF )
{
return EOF;
}
else
{
return leng;
}
}
More information about the Comp.unix.sysv386
mailing list