Dash:
[t2.git] / misc / archive / scrsav.c
blob228a96519410d2fb303200a8f7f7a52595aa3b65
1 /* gcc -Wall -O2 scrsav.c -o scrsav
2 * while : ; do ./scrsav /dev/vcc/a2 /dev/vcc/a3 ; sleep 5 ; done
4 * --- T2-COPYRIGHT-NOTE-BEGIN ---
5 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
6 *
7 * T2 SDE: misc/archive/scrsav.c
8 * Copyright (C) 2004 - 2005 The T2 SDE Project
9 * Copyright (C) 1998 - 2003 ROCK Linux Project
11 * More information can be found in the files COPYING and README.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; version 2 of the License. A copy of the
16 * GNU General Public License can be found in the file COPYING.
17 * --- T2-COPYRIGHT-NOTE-END ---
20 #include <stdio.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <unistd.h>
25 #include <time.h>
26 #include <stdlib.h>
27 #include <endian.h>
29 #ifdef iMAC_CON
30 # define LINES 48
31 # define CHARS 128
32 #else
33 # define LINES 25
34 # define CHARS 80
35 #endif
37 #define BUFSIZE (LINES*CHARS*2)
38 #define LINESIZE (CHARS*2)
40 int main(int argc, char ** argv) {
41 char buffer[BUFSIZE];
42 char miscdata[4];
43 int fd,c,i,j;
45 if (argc != 3) {
46 fprintf(stderr, "Usage: %s <src-vcs> <trg-vcs>\n", argv[0]);
47 fprintf(stderr, "E.g.: %s /dev/vcc/a2 /dev/vcc/a3\n", argv[0]);
48 return 1;
51 fd=open(argv[1], O_RDONLY);
52 if (fd < 0) { perror(argv[1]); return 1; }
53 read(fd, miscdata, 4);
54 read(fd, buffer, BUFSIZE);
55 close(fd);
57 srandom( time(NULL) + getpid() );
59 for (c=0; c<BUFSIZE-1; c+=2) {
60 #if __BYTE_ORDER == __LITTLE_ENDIAN
61 i=c+1; j=c;
62 #else
63 j=c+1; i=c;
64 #endif
65 buffer[i] ^= buffer[j] ^ c ^ random() ;
66 if ( c/LINESIZE+1 != time(NULL) % LINES )
67 buffer[i] &= 0x0f;
70 fd=open(argv[2], O_WRONLY);
71 if (fd < 0) { perror(argv[2]); return 1; }
72 write(fd, miscdata, 4);
73 write(fd, buffer, BUFSIZE);
74 close(fd);
76 return 0;