X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=dart%2Fttyread.c;fp=dart%2Fttyread.c;h=0000000000000000000000000000000000000000;hp=65f0203ac9d008bf34783d3b6eeb17b60bbe471f;hb=8e8f26d01ab21db191f62f2732808dcb75e8a74f;hpb=050398149d26f27a0b19971cbcea990574d73a57 diff --git a/dart/ttyread.c b/dart/ttyread.c deleted file mode 100644 index 65f0203..0000000 --- a/dart/ttyread.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ttyread - * - * - * Copyright (C) 2011 Christian Pointner - * - * This file is part of ttyread. - * - * ttyread is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * ttyread is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ttyread. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -int setup_tty(int fd) -{ - struct termios tmio; - - int ret = tcgetattr(fd, &tmio); - if(ret) { - perror("tcgetattr()"); - return ret; - } - - ret = cfsetospeed(&tmio, B57600); - if(ret) { - perror("cfsetospeed()"); - return ret; - } - - ret = cfsetispeed(&tmio, B57600); - if(ret) { - perror("cfsetispeed()"); - return ret; - } - - tmio.c_lflag &= ~ECHO; - tmio.c_lflag |= CLOCAL; - - tmio.c_iflag &= ~ICRNL; - tmio.c_iflag &= ~IGNCR; - tmio.c_iflag |= IGNBRK | BRKINT; - - tmio.c_cflag |= CLOCAL; - - ret = tcsetattr(fd, TCSANOW, &tmio); - if(ret) { - perror("tcsetattr()"); - return ret; - } - - ret = tcflush(fd, TCIFLUSH); - if(ret) { - perror("tcflush()"); - return ret; - } - - fd_set fds; - struct timeval tv; - FD_ZERO(&fds); - FD_SET(fd, &fds); - tv.tv_sec = 0; - tv.tv_usec = 50000; - for(;;) { - ret = select(fd+1, &fds, NULL, NULL, &tv); - if(ret > 0) { - char buffer[100]; - ret = read(fd, buffer, sizeof(buffer)); - } - else - break; - } - - return 0; -} - -int main(int argc, char* argv[]) -{ - if(argc < 2) { - fprintf(stderr, "Please specify a path to the tty\n"); - return 1; - } - - int fd = open(argv[1], O_RDONLY | O_NONBLOCK | O_NOCTTY); - if(fd < 0) { - perror("open()"); - return 2; - } - - if(setup_tty(fd)) return 3; - - fd_set rfds, efds; - char buf[100]; - for(;;) { - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - FD_ZERO(&efds); - FD_SET(1, &efds); - - int s = select(fd+1, &rfds, NULL, &efds, NULL); - if(s < 0) { - perror("select()"); - return s; - } - if(FD_ISSET(1, &efds)) return 0; - if(!FD_ISSET(fd, &rfds)) continue; - - ssize_t r = read(fd, buf, sizeof(buf)); - if(r <= 0) { - perror("read()"); - return r; - } - - ssize_t i; - for(i=0; i < r;) { - ssize_t w = write(1, &(buf[i]), r - i); - if(w < 0) { - perror("write()"); - return w; - } - i+=w; - } - } - - return 0; -}