Elegxos plhktrou se gcc

Christos Ricudis Christos_Ricudis at p98.f11.n413.z2.fidonet.gr
Tue Sep 30 20:20:32 EEST 1997


Hello Linux-greek-users!

In <LINUX-USERS.GR> Linux-greek-users wrote:

 L> Mhpws kanenas gnwrizei me pia synarthsh mporw na elenxw an
 L> path8hke kapoio plhktro kai poio sth GCC xwris na prepei na 
 L> pathsw to [enter], dokimasa me getchar alla 8elei na pathsw 
 L> to [enter]

Nai giati psaxneis se la8os meros.

To pws pernane oi xarakthres sthn efarmogh einai 8ema toy driver ki oxi ths
efarmoghs. Ayto mperdeyei panta toys developer poy synh8isan sto DOS, mia poy
ekei den yparxoyn drivers me th synh8ismenh ennoia (e, xm, yparxei kai h apopsh
oti den yparxei kan leitoyrgiko systhma me th synh8ismenh ennoia, telos
pantwn). Sto UNIX by default ta ttys einai se cooked mode pragma poy shmainei
oti o driver "sygkentrwnei" to input apo thn eisodo, kanei kapoio preprocessing
(p.x. sbhnei xarakthres otan pathseis to analogo plhktro), kai stelnei ta
dedomena sthn efarmogh grammh-grammh.

Twra. Prepei na peis aploustata ston driver na balei to TTY apo cooked se raw
mode. (kai molis teleiwsei h efarmogh soy na kaneis akribws to anapodo giati
alliws to shell 8a einai axrhsto). O kalyteros tropos einai na xrhsimopoihseis
tis termios synarthseis. Panw katw ayto ginetai ws ekshs (apo mnhmhs sta grafw
gi ayto mh me empisteyesai, rikse mia matia se kana biblio) : 


termios koko,backoko;

if (tcgetattr(0,&koko)==-1) { 
        perror("tcgetattr");
        exit(1);
} 

backoko=koko;

koko.c_lflag &=  ~(ECHO|ICANON);
koko.c_cc[VMIN] = 1; 
koko.c_cc[VTIME] = 0; 

/* epekshghsh : se raw (non ICANON mode) o driver epistrefei sthn read() molis
diabasei c_cc[VMIN] bytes H molis perasoyn c_cc[VTIME] dekata toy second. Ean i
c_cc[VMIN] einai 0 kai i c_cc[VTIME] einai 0, o driver den perimenei, kai h
read() epistrefei amesws. Ean h c_cc[VMIN] einai > 0 tote o driver perimenei
gia panta mexri na dextei N xarakthres */

if (tcsetattr(0,TCSANOW,&koko)==-1) {
        perror("tcsetattr");
        exit(1);
}

..... we do our job ....

if (tcsetattr(0,TCSANOW,&backoko)==-1) {
        perror ("Cannot reset tty. We're screwed. tcsetattr:");
        exit(1);
}

Na pros8esw edw oti POTE, POTE, <blink>POTE</blink>, <em>POTE</em>,
<em><blink>POTE!</em></blink> den prepei na xrhsimopoieite tis low level 
I/O synarthseis poy doyleyoyn me file descriptors (read(), write(), termios)
enalla3 me tis buffered hi-level synarthseis ths libc (printf(), gets()) 
(sta idia kanalia, ennoeitai). An to kanete, einai h pio sigoyrh syntagh gia na
xtypate ton kwlariko sas sto patwma gia bdomades prin katalabete ti den paei
kala. 

Christos Ricudis, leaving the world in a <blink>blinking state
ricudis at paiko.the.forthnet.gr  
--
====================================================================
Gia na mathete pos na xrisimopoiite ton majordomo, stilte e-mail
sto "majordomo at argos.hol.gr" me 1 grammi sto keimeno: help
Ta archives tis listas einai sto http://www.argos.hol.gr/lists
Gia opoiodipote problima stilte  e-mail ston owner-linux-greek-users
====================================================================



More information about the Linux-greek-users mailing list