*BSD News Article 21797


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!doc.ic.ac.uk!uknet!mcsun!sun4nl!tuegate.tue.nl!rw7.urc.tue.nl!wmbfmk
From: wmbfmk@rw7.urc.tue.nl (Marc van Kempen)
Newsgroups: comp.os.386bsd.questions
Subject: Termcapdefinitions and fcntl()
Date: 3 Oct 1993 20:51:53 +0100
Organization: Eindhoven University of Technology, The Netherlands
Lines: 59
Distribution: world
Message-ID: <wmbfmk.749677476@rw7.urc.tue.nl>
NNTP-Posting-Host: rw7.urc.tue.nl


Hi,

I have been working on a list-a-like program for unix. I have recently
been trying to use the termcapdefinition to recognize some special keys.
Which are:
- left arrow
- right arrow
- up arrow
- down arrow
- Page down
- Page up
- Home 
- End
Before I just hardcoded the vt100 keys into the program, which obviously is
not the portable thing to do. However now I run into two problems:

1. The method I use right now is a form of busy waiting. I use 
   fcntl(0, F_SETFL, O_NDELAY);
   to determine from standard input if there's a key available.
   If any of you knows a better way of doing it please let me know, I'll 
   include the code fragment here:

        arg = fcntl(0, F_GETFL, arg);           /* save original filedescriptor settings */

        escseqp = escseq;                       /* remember to set fcntl(0, F_SETFL, O_NDELAY) */
        ch = 0;
        fcntl(0, F_SETFL, O_NDELAY);
        ch = ReadCh();                          /* get the first character */
        while (ch == -1) ch = ReadCh();
        while (ch != -1) {
                if (ch != -1) *escseqp++ = ch;
                ch = ReadCh();                  /* read characters while they are available */
        }
        escseqp = '\0';                         /* terminate the esc-sequence string */
        fcntl(0, F_SETFL, arg);                 /* restore original filedescriptor settings */

    Obviously this hoses the processor.

2. What termcap entries should I use for the keys mentioned above? Actually 
   the arrowkeys don't seem to be that big a problem, but the kN and kP 
   fields don't seem to be filled in for all the definitions, specifically
   my xterm definition. What fields should I use for the HOME and END keys?


I use a NetBSD 0.9 system. It does seem to work with the console,
except for the HOME and END, for which I don't know the fields.

BTW
If there's any interest I could make it publicly available. You can use
it to look at several types of files, including the contents of
zipfiles. I plan on adding tar files and gzipped tarfiles.
This is all possible by selecting the filenames from a list of names,
using the cursor (This is why I want those definitions).

Thanks for any answers,

Marc van Kempen
(wmbfmk@urc.tue.nl)