无缓冲的I / ANSI C 0 [英] Unbuffered I/O in ANSI C

查看:116
本文介绍了无缓冲的I / ANSI C 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关教育和编程习惯的缘故,我想编写一个简单的库,可以处理原始键盘输入,并输出到实时的终端。

For the sake of education, and programming practice, I'd like to write a simple library that can handle raw keyboard input, and output to the terminal in 'real time'.

我想坚持使用ANSI C尽可能多的,我只是不知道从哪里开始这样的事情。我已经做了一些谷歌搜索,结果99%的人使用图书馆,或者是C ++。

I'd like to stick with ansi C as much as possible, I just have no idea where to start something like this. I've done several google searches, and 99% of the results use libraries, or are for C++.

我真的很想得到它在窗口工作,然后将其移植到OSX,当我有时间。

I'd really like to get it working in windows, then port it to OSX when I have the time.

推荐答案

标准C尽可能的坚持是一个好主意,但是你不打算与你采取的任务只使用标准C的机制,走得很远获得从在一时间终端的一个字符是特定固有的平台。对于POSIX系统(MacOS X系统),看 < termios.h> 头。旧的系统使用一个巨大的各种头和系统调用来实现类似的效果。你必须决定你是否打算做任何特殊字符处理,记住的东西像'行删除可以在该行的末尾出现和ZAP输入所有字符为止。

Sticking with Standard C as much as possible is a good idea, but you are not going to get very far with your adopted task using just Standard C. The mechanisms to obtain characters from the terminal one at a time are inherently platform specific. For POSIX systems (MacOS X), look at the <termios.h> header. Older systems use a vast variety of headers and system calls to achieve similar effects. You'll have to decide whether you are going to do any special character handling, remembering that things like 'line kill' can appear at the end of the line and zap all the characters entered so far.

对于Windows,你需要深入到WIN32 API - 那里将是在Unix和Windows之间的code基本上没有共性,至少在你把'端'为字符逐字符模式。一旦你得到了一个机制来读取单个字符,您可以管理通用code - 大概

For Windows, you'll need to delve into the WIN32 API - there is going to be essentially no commonality in the code between Unix and Windows, at least where you put the 'terminal' into character-by-character mode. Once you've got a mechanism to read single characters, you can manage common code - probably.

此外,你需要担心的人物和键pressed之间的差异。例如,进入'我'在MacOS X,你键入<大骨节病>选项-U 和<大骨节病>我。这三个关键presses。

Also, you'll need to worry about the differences between characters and the keys pressed. For example, to enter 'ï' on MacOS X, you type option-u and i. That's three key presses.

这篇关于无缓冲的I / ANSI C 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆