span class=postbodyESC 키를 누르면 종료하게 됩니다.
br /
br /
Escape seq 로 진입하는 경우에 대한 코드는 머리가 복잡하여 좀 고민좀 해봐야 겠네요.
br /
br /
/spantable align=center border=0 cellpadding=3 cellspacing=1 width=90%tbodytr tdspan class=genmedb코드:/b/span/td /tr tr td class=code/*
br /
Copyright (C) Information Equipment co.,LTD.
br /
All rights reserved.
br /
Code by JaeHyuk Cho lt;mailto:minzkn@infoeq.comgt;
br /
CVSTAG=$Header$
br /
*/
br /
br /
#include lt;sys/types.hgt;
br /
#include lt;stdio.hgt;
br /
#include lt;stdlib.hgt;
br /
#include lt;memory.hgt;
br /
#include lt;unistd.hgt;
br /
#include lt;fcntl.hgt;
br /
#include lt;termios.hgt;
br /
br /
int main(void)
br /
{
br /
struct termios s_termios, s_termios_save;
br /
int s_key, s_break, s_read_bytes, s_index;
br /
unsigned char s_buffer[ 128 ];
br /
if(tcgetattr(STDIN_FILENO, (struct termios *)(amp;s_termios)) == 0)
br /
{
br /
nbsp; (void)memcpy((void *)(amp;s_termios_save), (void *)(amp;s_termios), (size_t)sizeof(struct termios));
br /
#if 0 /* blocking */
br /
nbsp; s_termios.c_lflag amp;= ~(ECHO | ICANON | ISIG);
br /
nbsp; s_termios.c_iflag amp;= ~(BRKINT);
br /
#else
br /
nbsp; s_termios.c_lflag |= (ISIG);
br /
nbsp; s_termios.c_lflag amp;= ~(ECHO | ICANON);
br /
nbsp; s_termios.c_iflag |= (BRKINT);
br /
nbsp; s_termios.c_iflag amp;= ~(IGNBRK);
br /
#endif
br /
nbsp; s_termios.c_cc[VMIN] = 1;
br /
nbsp; s_termios.c_cc[VTIME] = 0;
br /
nbsp; if(tcsetattr(STDIN_FILENO, TCSAFLUSH, (struct termios *)(amp;s_termios)) == 0)
br /
nbsp; {
br /
nbsp; nbsp;s_break = 0;
br /
br /
nbsp; nbsp;do
br /
nbsp; nbsp;{
br /
nbsp; nbsp; /* read */
br /
nbsp; nbsp; s_read_bytes = (int)read(STDIN_FILENO, (void *)(amp;s_buffer[0]), (size_t)sizeof(s_buffer));
br /
nbsp; nbsp; if(s_read_bytes lt;= 0)continue;
br /
br /
nbsp; nbsp; /* debug */
br /
nbsp; nbsp; (void)fputs(VT CODE=\, stdout);
br /
nbsp; nbsp; for(s_index = 0;s_index lt; s_read_bytes;s_index++)
br /
nbsp; nbsp; {
br /
nbsp; nbsp; nbsp;if(s_buffer[s_index] == 0x1b)(void)fputs(ESC, stdout);
br /
nbsp; nbsp; nbsp;else if((s_buffer[s_index] gt;= ' ') amp;amp;
(s_buffer[s_index] lt;= 0x7e))(void)fputc((int)s_buffer[s_index],
stdout);
br /
nbsp; nbsp; nbsp;else (void)fprintf(stdout, (%02XH), (int)s_buffer[s_index]);
br /
nbsp; nbsp; }
br /
nbsp; nbsp; (void)fputs(\\n, stdout);
br /
br /
nbsp; nbsp; /* key map */
br /
nbsp; nbsp; if(s_read_bytes == 1)s_key = (int)s_buffer[0];
br /
nbsp; nbsp; else
br /
nbsp; nbsp; { /* escape seq */
br /
nbsp; nbsp; nbsp;s_key = 0;
br /
nbsp; nbsp; }
br /
br /
nbsp; nbsp; /* select */
br /
nbsp; nbsp; switch(s_key)
br /
nbsp; nbsp; {
br /
nbsp; nbsp; nbsp;case 0x0000001b: s_break = 1; break; /* ESC key */
br /
nbsp; nbsp; nbsp;default:
br /
nbsp; nbsp; nbsp; nbsp; nbsp; break;
br /
nbsp; nbsp; }
br /
nbsp; nbsp;}while(s_break == 0);
br /
br /
nbsp; nbsp;/* restore termios */
br /
nbsp; nbsp;if(tcsetattr(STDIN_FILENO, TCSAFLUSH, (struct termios *)(amp;s_termios_save)) == 0)
br /
nbsp; nbsp;{
br /
nbsp; nbsp; (void)fprintf(stdout, leave\n);
br /
nbsp; nbsp;}
br /
nbsp; nbsp;else (void)fprintf(stdout, error: tcsetattr\n);
br /
nbsp; }
br /
nbsp; else (void)fprintf(stdout, error: tcsetattr\n);
br /
}
br /
else (void)fprintf(stdout, error: tcgetattr\n);
br /
return(0);
br /
}
br /
br /
/* End of source *//td/tr/tbody/table
받은 트랙백이 없고,
댓글이 없습니다.

글
댓글을 달아 주세요
댓글 RSS 주소 : http://blog.minzkn.com/rss/comment/99댓글 ATOM 주소 : http://blog.minzkn.com/atom/comment/99