%20.png)
pg\more\less ユーティリティがどのように動作するかを理解しようとしています。たとえば、cat somebigfile | more です。More は現在対話モードです。彼の fd テーブルは次のとおりです: 0 (cat からパイプを読み取り) 1 (stdout) 2 (stderr)
3 つの fd で /dev/tty を開いて、そこからコマンドを読み取ることができます。しかし、Enter キーを押さずにいくつかのアクションを実行できるものもあります。Linux では ncurses を使用できます。Solaris でこれを実現するには、何を実現する必要がありますか?
答え1
基本的な考え方は、入力から1文字をread()することです。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);
}