how do you append arrays?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 26 01:01:10 PST 2016


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:

The following compiles and seems to work. I've marked my changes with // 
Ali:

/*
    copy-paste code from:
    http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html
*/

import std.stdio;    // Ali
import core.sys.linux.termios;

// struct termios oldterm;
// struct termios newterm;
termios oldterm;    // Ali
termios newterm;    // Ali

void uncook_term() {
     tcgetattr(stdin.fileno, &oldterm);
     newterm = oldterm;

     newterm.c_cflag = /*BAUDRATE | Ali */ CRTSCTS | CS8 | CLOCAL | CREAD;
     newterm.c_iflag = IGNPAR;
     newterm.c_oflag = 0;
     newterm.c_lflag = 0;
     tcflush(stdin.fileno, TCIFLUSH);
     tcsetattr(stdin.fileno, TCSANOW, &newterm);
}

void restore_term() {
     tcsetattr(stdin.fileno, TCSANOW, &oldterm);
}

void main() {
     uncook_term();

     int ch = fgetc(core.stdc.stdio.stdin); //read();  Ali
     while(ch != 'q' && !stdin.eof) {
         write(ch);
         ch = fgetc(core.stdc.stdio.stdin); //read(); Ali
     }

     restore_term();
}

Ali


More information about the Digitalmars-d-learn mailing list