annotate Meerwald/gen_xie2_sig.c @ 22:d8551fb39a5e default tip

Added tag v0.6 for changeset 1c4ccd635a68
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Sat, 28 Jan 2023 23:57:51 +0100
parents 4987db85cfae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 #include "wm.h"
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include "signature.h"
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4 char *progname;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 void usage(void) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 fprintf(stderr, "usage: %s [-a n] [-e n] [-f n] [-F file] [-l n] [-n n] [-o file] [-s file] [-S n] [-v n] file\n\n", progname);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 fprintf(stderr, "\t-a n\t\tembedding strength (default 0.5)\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 fprintf(stderr, "\t-e n\t\twavelet filtering method (default 2)\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 fprintf(stderr, "\t-f n\t\tfilter number (default 1)\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 fprintf(stderr, "\t-F file\t\tfilter definition file (default 'filter.dat')\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-h\t\tprint usage\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 fprintf(stderr, "\t-l n\t\tembedding level (default 5)\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 fprintf(stderr, "\t-n n\t\twatermark bit length\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 fprintf(stderr, "\t-o file\t\toutput file\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 fprintf(stderr, "\t-q n\t\tquantization level\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 fprintf(stderr, "\t-s file\t\tuse signature file's embedding information\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 fprintf(stderr, "\t-S n\t\tseed\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 fprintf(stderr, "\t-v n\t\tverbosity level\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 exit(0);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 int main(int argc, char *argv[]) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 FILE *in = stdin;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 FILE *out = stdout;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 FILE *sig = NULL;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 char output_name[MAXPATHLEN] = "(stdout)";
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 char input_name[MAXPATHLEN] = "(stdin)";
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 char signature_name[MAXPATHLEN];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 int verbose = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 int c;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 int i;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 double a = 0.5;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 int q = 4;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 int l = 5;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 int n = 0, nb;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 int s = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 int e = 2;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 int f = 1;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 char F[MAXPATHLEN] = "filter.dat";
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 progname = argv[0];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 wm_init();
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 while ((c = getopt(argc, argv, "a:e:f:F:h?l:n:o:s:S:v:q:")) != EOF) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 switch (c) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 case 'a':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 a = atof(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 if (a <= 0.0) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 fprintf(stderr, "%s: embedding strength %f out of range\n", progname, a);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 case 'e':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 e = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 if (e < 0) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, e);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 case 'q':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 q = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 case 'f':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 f = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 if (f <= 0) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 fprintf(stderr, "%s: filter number %d out of range\n", progname, f);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 case 'F':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 strcpy(F, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 case 'h':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 case '?':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 usage();
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 case 'l':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 l = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 if (l < 1) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 fprintf(stderr, "%s: embedding level out of range\n", progname);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 case 'n':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 n = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 if (n < 1 || n > 1000) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 case 'o':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 if ((out = fopen(optarg, "wb")) == NULL) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 strcpy(output_name, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 case 's':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 if ((sig = fopen(optarg, "r")) == NULL) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 strcpy(signature_name, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 case 'S':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 s = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 case 'v':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 verbose = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 if (verbose < 0) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 fprintf(stderr, "%s: verbosity level %d out of range", progname, verbose);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 argc -= optind;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 argv += optind;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 if (argc > 1) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 usage();
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
128 if (argc == 1 && *argv[0] != '-') {
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 if ((in = fopen(argv[0], "rb")) == NULL) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
135 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
136
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 if (sig) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 char line[32];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 fgets(line, sizeof(line), sig);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 if (strspn(line, "XE2SG") >= 5) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 if (n == 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 fscanf(sig, "%d\n", &n);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 fscanf(sig, "%*d\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 if (a == 0.0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 fscanf(sig, "%lf\n", &a);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
148 fscanf(sig, "%*f\n");
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 if (e < 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 fscanf(sig, "%d\n", &e);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 fscanf(sig, "%*d\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 if (f == 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 fscanf(sig, "%d\n", &f);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 fscanf(sig, "%*d\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 if (!strcmp(F, ""))
15
ad1d224896c5 fix scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 8
diff changeset
158 fscanf(sig, "%[^\n\r]\n", F);
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 fscanf(sig, "%*[^\n\r]\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 if (q == 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 fscanf(sig, "%d\n", &q);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 fscanf(sig, "%*d\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 if (l == 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 fscanf(sig, "%d\n", &l);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 fscanf(sig, "%*d\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 else {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 }
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
174 fclose(sig);
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 if (s)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 srandom(s);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 srandom(time(NULL) * getpid());
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 if (n > 0) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 nb = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 if (nb < i) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 else {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 if (fscanf(in, "%128[^\n\r]", signature) == EOF) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 nb = strlen(signature);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 n = NBYTESTOBITS(nb);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 fprintf(stderr, "%s: got %d signature bits\n", progname, n);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 fprintf(out, "XE2SG\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 fprintf(out, "%d\n", n);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 fprintf(out, "%f\n", a);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 fprintf(out, "%d\n", e);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 fprintf(out, "%d\n", f);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 fprintf(out, "%s\n", F);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 fprintf(out, "%d\n", q);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 fprintf(out, "%d\n", l);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
207 fprintf(out, "%ld\n", random());
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 fwrite(signature, sizeof(char), nb, out);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 fprintf(out, "\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 fclose(out);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 exit(0);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 }

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