![버튼 누름에 반응하는 프로그램을 만드는 방법(예: "q"에 "more") [닫기]](https://linux55.com/image/76387/%EB%B2%84%ED%8A%BC%20%EB%88%84%EB%A6%84%EC%97%90%20%EB%B0%98%EC%9D%91%ED%95%98%EB%8A%94%20%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EC%9D%84%20%EB%A7%8C%EB%93%9C%EB%8A%94%20%EB%B0%A9%EB%B2%95(%EC%98%88%3A%20%22q%22%EC%97%90%20%22more%22)%20%5B%EB%8B%AB%EA%B8%B0%5D.png)
pg\more\less 유틸리티가 어떻게 작동하는지 이해하려고 합니다. 예를 들어 cat somebigfile | 이제 더 많은 대화형 모드가 있습니다. 그의 fd 테이블은 다음과 같습니다: 0(cat에서 파이프 읽기) 1(stdout) 2(stderr)
3 fd에서 /dev/tty를 열고 거기에서 명령을 읽을 수 있습니다. 그러나 Enter 키를 누르지 않고도 특정 작업을 수행할 수 있다는 것이 더 중요합니다. 리눅스에서는 ncurses를 사용할 수 있습니다. 이를 Solaris에서 구현하려면 무엇을 알아야 합니까?
답변1
기본 아이디어는 입력에서 문자를 읽는 것입니다().http://bazaar.launchpad.net/~vcs-imports/util-linux-ng/trunk/view/head:/text-utils/more.c#L1908예를 들어 (Google 검색 결과를 통해 찾았습니다.https://stackoverflow.com/questions/9854267/implementing-the-more-unix-utility-command):
int readch(void)
{
unsigned char c;
errno = 0;
if (read(fileno(stderr), &c, 1) <= 0) {
if (errno != EINTR)
end_it(0);
else
c = otty.c_cc[VKILL];
}
return (c);
}