annotate Meerwald/gen_bruyn_sig.c @ 23:71dd4b96221b

fix some compiler warning
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Fri, 20 Dec 2024 12:53:41 +0100
parents 4987db85cfae
children
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) {
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
134 fprintf(stderr, "%s: block size has to be even and greater than 2\n", progname);
0
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
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
138 if (argc == 1 && *argv[0] != '-') {
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]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
145 }
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 // read signature file and set options
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 // command line options override signature file options
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 char line[128];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 if (strspn(line, "BRSG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 if (n == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 fscanf(sig, "%d\n", &n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 if (skipping == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 fscanf(sig, "%d\n", &skipping);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 if (p1 == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 fscanf(sig, "%d\n", &p1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 if (p2 == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 fscanf(sig, "%d\n", &p2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 if (q == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 fscanf(sig, "%lf\n", &q);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 8
diff changeset
172 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 if (t1 == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 fscanf(sig, "%lf\n", &t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 8
diff changeset
176 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 if (t2 == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 fscanf(sig, "%lf\n", &t2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 8
diff changeset
180 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 if (b == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 fscanf(sig, "%d\n", &b);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 fclose(sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 if (s)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 srandom(s);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 srandom(time(NULL) * getpid());
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 if (n > 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 nb = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 if (nb < i) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 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
202 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 if (fscanf(in, "%128[^\n\r]", signature) == EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 nb = strlen(signature);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 n = NBYTESTOBITS(nb);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 fprintf(stderr, "%s: got %d signature bits\n", progname, n);
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
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 fprintf(out, "BRSG\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 fprintf(out, "%d\n", n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 fprintf(out, "%d\n", skipping);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219 fprintf(out, "%d\n", p1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 fprintf(out, "%d\n", p2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 fprintf(out, "%f\n", q);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 fprintf(out, "%f\n", t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 fprintf(out, "%f\n", t2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 fprintf(out, "%d\n", b);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
225 fprintf(out, "%ld\n", random());
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226 fwrite(signature, sizeof(char), nb, out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227 fprintf(out, "\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232 }

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