From: Serdar KOYLU (skoylu@altavista.com)
Date: Sun 14 Jan 2001 - 16:51:55 EET
Selamlar..
On Sun, 14 January 2001, olcay ors wrote:
>
> TEKRAR DIR
>
>
> ASAGIDA ARAMA ILE BULDUGUM DOSDAKI
> getche() ve kbhit()
> KOMUTLARININ LINUX DAKI ALT PROGRAM OLARAK
> KARSILIKLARI FAYDASI OLURSA SEVINIRIM
> SAYGILAR
> BASARILAR
> SEVGILER
> SIZI SEVIYORUM
>
> OLCAY ORS
>
>
> -- start of code snippet
> #include <stdio.h>
> #include <termios.h>
>
> static struct termios orig, new;
> static int peek = -1;
>
> int main()
> {
> int ch =0;
>
> tcgetattr(0, &orig);
> new = orig;
> new.c_lflag &= ~ICANON;
> new.c_lflag &= ~ECHO;
> new.c_lflag &= ~ISIG;
> new.c_cc[VMIN] = 1;
> new.c_cc[VTIME] = 0;
> tcsetattr(0, TCSANOW, &new);
>
> while(ch != 'q') {
> printf("looping\n");
> sleep(1);
> if(kbhit()) {
> ch = readch();
> printf("you hit %c\n",ch);
> }
> }
>
> tcsetattr(0,TCSANOW, &orig);
> exit(0);
>
> }
>
>
> int kbhit()
> {
>
> char ch;
> int nread;
>
> if(peek != -1) return 1;
> new.c_cc[VMIN]=0;
> tcsetattr(0, TCSANOW, &new);
> nread = read(0,&ch,1);
> new.c_cc[VMIN]=1;
> tcsetattr(0, TCSANOW, &new);
>
> if(nread == 1) {
> peek = ch;
> return 1;
> }
>
> return 0;
> }
>
> int readch()
> {
>
> char ch;
>
> if(peek != -1) {
> ch = peek;
> peek = -1;
> return ch;
> }
>
> read(0,&ch,1);
> return ch;
> }
> -- end of code snippet
>
> Hope this helps!
>
>
>
>
>
Guzel bir calisma ve bizlerle paylasmak istemeniz de asil bir davranis. Cok tesekkurler. Bu noktada hemen, Linux.org.tr'de belirtilen bir programcilik listesi var, bunun akibetini sormak isterim. Bu tur mesajlari o listeye de tasiyip iyi kotu programcilik birikimlerimizden istifade etsek.
Bu arada programciliga yeni baslayan arkadaslar icin, oncelikle artik DOS zihniyetinden kurtulmalari gerektigini hatirlatmak isterim. UNIX ve haliyle LINUX portable bir sistemdir, klavye, ekran gibi cihazlar yoktur.. Bu nedenle bu tur klavye okuma veya ekran yazma rutinlerinde oncelikle dusuk duzey API ile iletisim kuran girdi/cikti fonksiyonlarini tanimlamalari isabetli olur. Boylece hem tasinabilirlik hemde pipe, socket gibi daha gelismis arabirimlerle irtibat kurma icin daha yeterli altyapi hazirlanmis olur. kbhit() Belki console icin uygun olabilir ama, pipe gorevlerinde bir hayli zayif kalabilir.
DOS UNIX ve CP/M'in bir mixi olarak ancak pek az UNIX fonksiyonuna oykunebilir. Ayrica UNIX uzerindeki polling, threading ve redirect fonksiyonlari ne DOS, Ne windows ne de NT ile (%100) simule edilebilir. Bu fonksiyonlar sayesinde paralel processing gibi olagan disi uygulamalar kolayca mumkun olmaktadir. Zaten Linux'un gucude buradan gelir.. Squidin redirect fonksiyonu ve CGI sistemini bir inceleyin, bu gucun nelere kadir olabilecegine birazcik sahit olursunuz..
Saygi ve sevgiler..
Find the best deals on the web at AltaVista Shopping!
http://www.shopping.altavista.com
Listeden cikmak icin:
unsub linux
mesajini listeci@bilkent.edu.tr adresine gonderiniz.
Lutfen Listeci icin MIME / HTML / Turkce Aksan kullanmayin.
Listeci arayuzu: http://listweb.bilkent.edu.tr/yardim/bilkent/linux.html
Liste arsivinin adresi: http://listweb.bilkent.edu.tr/