annotate Meerwald/gen_bruyn_sig.c @ 4:9cf6ec970448 v0.5

mention filter param.
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 14 Aug 2007 21:13:11 +0200
parents be303a3f5ea8
children f83ef905a63d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 #include "wm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include "signature.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 #include "bruyn_common.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 char *progname;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 void usage(void) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 fprintf(stderr, "usage: %s [-b n] [-k] [-n n] [-o file] [-pP n] [-q n] [-s file] [-S n] [-tT n] file\n\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 fprintf(stderr, "\t-b n\t\tblock size (default 8)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 fprintf(stderr, "\t-h\t\tprint usage\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 fprintf(stderr, "\t-k\t\tdisable block skipping\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-n n\t\twatermark bit length\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 fprintf(stderr, "\t-o file\t\toutput file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 fprintf(stderr, "\t-p n\t\tpattern type for zone 1 (default 1, 1.." NPATTERN_USAGE ")\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 fprintf(stderr, "\t-P n\t\tpattern type for zone 2 (default 2, 1.." NPATTERN_USAGE ")\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 fprintf(stderr, "\t-q n\t\tsignature strength (default 7.0)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 fprintf(stderr, "\t-s file\t\tuse signature file's embedding information\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 fprintf(stderr, "\t-S n\t\tseed\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 fprintf(stderr, "\t-t n\t\tthreshold for noise (default " THRESHOLD_NOISE_USAGE ")\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 fprintf(stderr, "\t-T n\t\tthreshold for slope (default " THRESHOLD_SLOPE_USAGE ")\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 char signature_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 int b = 8;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 int n = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 int nb;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 int s = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 int p1 = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 int p2 = 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 double t1 = THRESHOLD_NOISE;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 double t2 = THRESHOLD_SLOPE;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 double q = 7.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 int skipping = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 wm_init();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 while ((c = getopt(argc, argv, "b:h?n:o:p:P:q:s:S:t:T:k")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 case 'b':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 b = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 if (b <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 fprintf(stderr, "%s: block size %d out of range\n", progname, b);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 case 'k':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 skipping = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 case 'n':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 n = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 if (n < 1 || n > 1000) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 if ((out = fopen(optarg, "wb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 case 'p':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 p1 = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 if (p1 <= 0 || p1 > NPATTERN) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 fprintf(stderr, "%s: pattern type out of range\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 case 'P':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 p2 = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 if (p2 <= 0 || p2 > NPATTERN) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 fprintf(stderr, "%s: pattern type out of range\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 case 'q':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 q = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 if (q <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 fprintf(stderr, "%s: signature strength factor %f out of range\n", progname, q);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 case 't':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 t1 = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 if (t1 <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 fprintf(stderr, "%s: noise threshold %f out of range\n", progname, t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 case 'T':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 t2 = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 if (t2 <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 fprintf(stderr, "%s: slope threshold %f out of range\n", progname, t2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 case 'S':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 s = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 if (b % 2 > 0 || b <= 2) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 fprintf(stderr, "%s: block size has to be even and greater than 2\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 if (argc == 1 && *argv[0] != '-')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 if ((in = fopen(argv[0], "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 strcpy(input_name, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 // read signature file and set options
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 // command line options override signature file options
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 char line[128];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 if (strspn(line, "BRSG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 if (n == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 fscanf(sig, "%d\n", &n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 if (skipping == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 fscanf(sig, "%d\n", &skipping);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 if (p1 == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 fscanf(sig, "%d\n", &p1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 if (p2 == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 fscanf(sig, "%d\n", &p2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 if (q == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 fscanf(sig, "%lf\n", &q);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 if (t1 == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 fscanf(sig, "%lf\n", &t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 if (t2 == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 fscanf(sig, "%lf\n", &t2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 if (b == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 fscanf(sig, "%d\n", &b);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 fclose(sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 if (s)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 srandom(s);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 srandom(time(NULL) * getpid());
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 if (n > 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 nb = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 if (nb < i) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 if (fscanf(in, "%128[^\n\r]", signature) == EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 nb = strlen(signature);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 n = NBYTESTOBITS(nb);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 fprintf(stderr, "%s: got %d signature bits\n", progname, n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 fprintf(out, "BRSG\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 fprintf(out, "%d\n", n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 fprintf(out, "%d\n", skipping);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 fprintf(out, "%d\n", p1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219 fprintf(out, "%d\n", p2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 fprintf(out, "%f\n", q);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 fprintf(out, "%f\n", t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 fprintf(out, "%f\n", t2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 fprintf(out, "%d\n", b);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 fprintf(out, "%d\n", random());
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225 fwrite(signature, sizeof(char), nb, out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226 fprintf(out, "\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.