Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Wes Nakamura <wknaka@pobox.com>
To: axp-list@redhat.com
Subject: text editor/fcntl/ioctl
Date: Thu, 5 Mar 1998 03:32:11 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.3.96.980305033001.692A-100000@toshi.naka.net> (raw)


Hi,

I'm trying to compile a text editor under linux/alpha.  It compiles and
links fine but doesn't quite work.  The problem is that it takes 4
keystrokes before anything happens.  If I type "1234" nothing happens
until the "4" has been typed, then all 4 characters appear at once.  The
3 characters you type after the first aren't lost, they just aren't
handled until the last is typed.  After that it requires another 4
keystrokes before they're handled.  At first I thought it was a screen
update problem, but it appears not to be. 

I've cut out some code to simplify the problem (see below).  I don't
really understand what's going on in the init function other than some
io device manipulation. 

I've also tried running this under intel linux (the editor runs fine
with no modifications under intel linux).  This sample code exits after
one keystroke on intel whereas the alpha one requires 4.  This is with a
basically clean redhat 5.0 install, 2.0.33 kernel. 

Thanks to anyone who can shed some light on this.
-Wes.

----------

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <termio.h>

struct termio gt;

void dont_panic(char* s) {
    printf("%s: don't panic!\n", s);
    exit(-1);
}

void init(void) { 
    static struct termio    ot;
    static struct termio    nt;

    if (ioctl(0, TCGETA, &ot) < 0) dont_panic("ioctl0");

    gt = ot;
    nt = ot;                /* save entry state             */
    nt.c_cc[VMIN] = 1;      /* one character read is OK     */
    nt.c_cc[VTIME] = 0;     /* Never time out.              */
    nt.c_iflag |= IGNBRK;
    nt.c_iflag &= ~( ICRNL | INLCR | ISTRIP | IXON | IXOFF );
    nt.c_oflag &= ~OPOST;
    nt.c_cflag |= CS8;      /* allow 8th bit on input       */
    nt.c_cflag &= ~PARENB;  /* Don't check parity           */
    nt.c_lflag &= ~( ECHO | ICANON | ISIG );
    
    if (ioctl(0, TCSETAF, &nt) < 0) dont_panic("ioctl1");
}

int main(void) {
    int i;
    char c;
    init();
    if (fcntl(0, F_SETFL, O_APPEND) < 0) dont_panic("fnctl");

    i = read(0, &c, 1);
    if (i < 0) dont_panic("read");
    printf("%c\n", c);

    if (ioctl(0, TCSETAF, &gt) < 0) dont_panic("ioctl2");
    return 0;
}

-EOF-



             reply	other threads:[~1998-03-05 11:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-03-05 11:32 Wes Nakamura [this message]
1998-03-05 14:25 ` text editor/fcntl/ioctl Andreas Johansson
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox