how do you append arrays?
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Feb 26 01:05:22 PST 2016
On 02/26/2016 01:01 AM, Ali Çehreli wrote:
> On 02/26/2016 12:47 AM, asdf wrote:
>
>> Trying to uncook the terminal failed however. It can't recognize struct
>> tag-declarations I think:
I've just found the following code among my collection of D snippets,
which uses a different method and supports Ctrl-D:
import std.stdio : writef, writeln;
import core.stdc.stdio;
import core.sys.posix.termios;
/* The declaration of cfmakeraw, which is missing from standard D
modules. */
extern(C) void cfmakeraw(termios *termios_p);
void main()
{
/* Saving the existing state of tty. */
termios oldState;
tcgetattr(1, &oldState);
/* Ensuring that it will be restored upon exit. */
scope (exit) tcsetattr(1, TCSADRAIN, &oldState);
/* Make a new state and set it to raw mode. */
termios newState;
tcgetattr(1, &newState);
cfmakeraw(&newState);
/* Use the new state in this terminal. */
tcsetattr(1, TCSADRAIN, &newState);
/*
* We are ready to read characters in this raw mode...
*/
/* This is Ctrl-D, the EOF character under Linux. */
enum endOfFile = '\4';
for (char c; c != endOfFile; ) {
c = cast(char)fgetc(stdin);
writef("%02x ", c);
}
writeln();
}
Ali
More information about the Digitalmars-d-learn
mailing list