-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresume_in.c
120 lines (90 loc) · 2.32 KB
/
resume_in.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <stdio.h>
#include <string.h>
#include "error.h"
#include "global.h"
#include "input.h"
#include "key.h"
#include "scan.h"
#include "stecker.h"
#include "resume_in.h"
char *getline_resume(char *dest, int n, FILE *fp)
{
char *x;
if ((x = fgets(dest, n, fp)) == NULL)
return NULL;
if ((x = strchr(dest, '\n')) != NULL)
*x = '\0';
if ((x = strchr(dest, '\r')) != NULL)
*x = '\0';
return dest;
}
/* sets state according to 00hc.resume */
int set_state( Key *from, Key *to, Key *ckey_res, Key *gkey_res, int *sw_mode,
int *max_pass, int *firstpass, int *max_score )
{
FILE *fp;
char *kf, *kt, *kc, *kg, *x;
char line1[NLINE1];
char line2[NLINE2];
int model;
int eq;
if ((fp = fopen("00hc.resume", "r")) == NULL)
err_open_fatal("00hc.resume");
if (getline_resume(line1, NLINE1, fp) == NULL)
return 0;
if (getline_resume(line2, NLINE2, fp) == NULL)
return 0;
eq = 0; x = line1;
while((x = strchr(x, '=')) != NULL) {
*x++ = '\0';
eq++;
}
if (eq != 7) return 0;
eq = 0; x = line2;
while((x = strchr(x, '=')) != NULL) {
*x++ = '\0';
eq++;
}
if (eq != 3) return 0;
/* line 1 */
x = line1;
if ((model = get_model(x)) == -1) return 0;
while (*x++) ;
kf = x;
while (*x++) ;
kt = x;
while (*x++) ;
kc = x;
while (*x++) ;
if ((*sw_mode = get_sw_mode(x)) == -1) return 0;
while (*x++) ;
if ((*max_pass = scan_posint(x)) == -1 ) return 0;
while (*x++) ;
if ((*firstpass = get_firstpass(x)) == -1) return 0;
while (*x++) ;
if ((*max_score = scan_posint(x)) == -1 ) return 0;
if (!set_range(from, to, kf, kt, model)) return 0;
if (!set_key(ckey_res, kc, model, 0)) return 0;
if (keycmp(from, ckey_res) == 1) return 0;
if (keycmp(ckey_res, to) == 1) return 0;
/* line2 */
x = line2;
if ((model != get_model(x))) return 0;
while (*x++) ;
kg = x;
if (!set_key(gkey_res, kg, model, 0)) return 0;
while (*x++) ;
if (!set_stecker(gkey_res, x)) return 0;
get_stecker(gkey_res);
while (*x++) ;
if ((gkey_res->score = scan_posint(x)) == -1 ) return 0;
fclose(fp);
return 1;
}
/*
* This file is part of enigma-suite-0.76, which is distributed under the terms
* of the General Public License (GPL), version 2. See doc/COPYING for details.
*
* Copyright (C) 2005 Stefan Krah
*
*/