src-filters: Add missing includes, reduce warnings
[h316.git] / pc-tools / src-filters / load.c
1 /* Simple program to load paper tape over serial port. Does that twice and compares. */
2
3 #include <stdio.h>
4 #include <termios.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <signal.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 struct termios orgstate;
13 struct termios workstate;
14
15 #define PORT_FILE "/dev/ttyS0"
16 #define BUFFER_SIZE 1000000
17
18 char * buffer;
19 int sp, ep, count, portfd;
20
21 void sighandler(int sig){
22 sp=0;
23 ep=count-1;
24 close (portfd);
25 // fprintf(stderr,"%i %i\n", sp, ep);
26 if (count>0) {
27 while(buffer[sp]==0) sp++;
28 while(buffer[ep]==0) ep--;
29 }
30
31 write(1,buffer+sp,ep-sp+1);
32 tcdrain(2);
33 fprintf(stderr,"Eingelesen: %i\n",ep-sp+1);
34 tcsetattr(portfd, TCSANOW, &orgstate);
35 close(portfd);
36 exit(0);
37 }
38
39 int main (int argc, char ** argv){
40
41 portfd=open(PORT_FILE, O_RDWR);
42 tcgetattr(portfd, &orgstate);
43 tcgetattr(portfd, &workstate);
44 cfmakeraw(&workstate);
45 // workstate.c_oflag=0;
46 workstate.c_cflag|=CS8+CREAD+CLOCAL+CRTSCTS+CSTOPB ;
47 // workstate.c_lflag=0;
48 cfsetspeed(&workstate, B4800);
49 tcsetattr(portfd, TCSANOW, &workstate);
50 count=0;
51
52 signal(SIGINT, sighandler);
53 buffer=(char *) malloc(BUFFER_SIZE);
54 fprintf(stderr, "Warte auf Daten. Einspielen und dann CTRL-C drücken.\n");
55
56 while(1) {
57 int erg=read(portfd, buffer+count, 1);
58 if (erg>0) count+=erg;
59 }
60
61
62 } //main();
63 // Ende.