도와주세요..
터미날 입출력과 관련된 샘플프로그램을 구할수 있을까요.. 비정규모드~(ICANON)에서 백스페이스와 DEL키를 지원할수 있는 프로그램이 요. 백스페이스 입력했을때 입력버퍼조작은 할수 있겠는데, 화면에 보여주 는 부분을 어떻게 할지 모르겠거든요..
#include #include #include #include #include #include #include int Get (char *s, int size, int keymode) { struct termio tdes, tdes_old; long maxwaittime; long stime, etime; char keybuf [256]; char ch; char *cs; int old_ttymode; int old_sockmode; int i; int rlen; int lineflag; int msgflag; int count; int sockfd; count = 0; cs = s; count = strlen (s); cs = s + count; ioctl (0, TCGETA, &tdes_old); ioctl (0, TCGETA, &tdes); old_ttymode = fcntl (0, F_GETFL); if (keymode == 0) { signal (SIGINT, SIG_IGN); signal (SIGTSTP, SIG_IGN); ioctl (0, TCSETA, &tdes); } if (keymode == 1 || keymode == 2 || keymode == 3 || keymode == 4) { tdes.c_lflag &= ~(ICANON | ECHO); tdes.c_lflag &= (ECHO); tdes.c_oflag |= (OPOST); tdes.c_iflag |= IXON; tdes.c_cc[VMIN ] = 1; tdes.c_cc[VTIME] = 0; ioctl (0, TCSETA, &tdes); } time (&stime); memset (keybuf, 0, sizeof (keybuf)); fflush (stdout); while (1) { rlen = read (0, keybuf, 256); for (i = 0; i< rlen; i++) { ch = *(keybuf + i); if (ch == 26 || ch == 13 || ch == 10) { *(cs) = 0; if (keymode != 0) fflush (stdout); ioctl (0, TCSETA, &tdes_old); fcntl (0, F_SETFL, old_ttymode); if (ch == 26) return (1); return (0); } if (ch == 8 && count == 0) goto roop; if (ch == 8 && count != 0) { *cs--='\0'; count--; if (keymode == 1 || keymode == 2 || keymode == 3) { putchar (ch); putchar (' '); putchar (ch); if (keymode != 0) fflush (stdout); } goto roop; } count++; if (count == size) { *(cs) = 0; if (keymode != 0) fflush (stdout); ioctl (0, TCSETA, &tdes_old); fcntl (0, F_SETFL, old_ttymode); if (ch == 26) return (1); return (0); } *cs++ = ch; if (keymode == 1 || keymode == 3 ) putchar (ch); if (keymode == 2) putchar('*'); if (keymode != 0) fflush (stdout); roop } memset (keybuf, 0, sizeof (keybuf)); } } int main (int argc, char *argv []) { char buffer [128 + 1]; memset (buffer, '\0', sizeof (buffer)); Get (buffer, 20, 0); printf ("Buffer = %s\n", buffer); exit (0); }
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
Re: 터미날입출력 샘플프로그램을 구할수있을까요..?
#include
#include
#include
#include
#include
#include
#include
int Get (char *s, int size, int keymode) {
struct termio tdes, tdes_old;
long maxwaittime;
long stime, etime;
char keybuf [256];
char ch;
char *cs;
int old_ttymode;
int old_sockmode;
int i;
int rlen;
int lineflag;
int msgflag;
int count;
int sockfd;
count = 0;
cs = s;
count = strlen (s);
cs = s + count;
ioctl (0, TCGETA, &tdes_old);
ioctl (0, TCGETA, &tdes);
old_ttymode = fcntl (0, F_GETFL);
if (keymode == 0) {
signal (SIGINT, SIG_IGN);
signal (SIGTSTP, SIG_IGN);
ioctl (0, TCSETA, &tdes);
}
if (keymode == 1 || keymode == 2 || keymode == 3 || keymode
== 4) {
tdes.c_lflag &= ~(ICANON | ECHO);
tdes.c_lflag &= (ECHO);
tdes.c_oflag |= (OPOST);
tdes.c_iflag |= IXON;
tdes.c_cc[VMIN ] = 1;
tdes.c_cc[VTIME] = 0;
ioctl (0, TCSETA, &tdes);
}
time (&stime);
memset (keybuf, 0, sizeof (keybuf));
fflush (stdout);
while (1) {
rlen = read (0, keybuf, 256);
for (i = 0; i< rlen; i++) {
ch = *(keybuf + i);
if (ch == 26 || ch == 13 || ch == 10) {
*(cs) = 0;
if (keymode != 0) fflush (stdout);
ioctl (0, TCSETA, &tdes_old);
fcntl (0, F_SETFL, old_ttymode);
if (ch == 26) return (1);
return (0);
}
if (ch == 8 && count == 0) goto roop;
if (ch == 8 && count != 0) {
*cs--='\0';
count--;
if (keymode == 1 || keymode == 2 ||
keymode == 3) {
putchar (ch);
putchar (' ');
putchar (ch);
if (keymode != 0) fflush
(stdout);
}
goto roop;
}
count++;
if (count == size) {
*(cs) = 0;
if (keymode != 0) fflush (stdout);
ioctl (0, TCSETA, &tdes_old);
fcntl (0, F_SETFL, old_ttymode);
if (ch == 26) return (1);
return (0);
}
*cs++ = ch;
if (keymode == 1 || keymode == 3 ) putchar
(ch);
if (keymode == 2) putchar('*');
if (keymode != 0) fflush (stdout);
roop
}
memset (keybuf, 0, sizeof (keybuf));
}
}
int main (int argc, char *argv []) {
char buffer [128 + 1];
memset (buffer, '\0', sizeof (buffer));
Get (buffer, 20, 0);
printf ("Buffer = %s\n", buffer);
exit (0);
}
댓글 달기