-
Notifications
You must be signed in to change notification settings - Fork 3
/
settings.cpp
60 lines (48 loc) · 970 Bytes
/
settings.cpp
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
// read psi46test.ini into CSettings
#include "settings.h"
bool CSettings::read_int( int &value, int min, int max )
{
char s[200];
if( fgets( s, 198, f ) == NULL )
return false;
if( s == NULL )
return false;
int v;
if( sscanf( s, "%i", &v ) != 1 )
return false;
if( v < min || max < v )
return false;
value = v;
return true;
}
bool CSettings::read_string( char string[], int size )
{
char s[256];
if( fgets( s, 254, f ) == NULL )
return false;
if( s == NULL )
return false;
int i = 0;
int n = size - 1;
while( s[i] != 0 && s[i] != ' ' && i < n ) {
string[i] = s[i];
i++;
}
s[i] = 0;
return true;
}
bool CSettings::read( const char filename[] )
{
bool ok = false;
f = fopen( filename, "rt" );
if( !f )
return false;
if( !read_string( port_tb, 20 ) )
goto read_error;
if( !read_string( path, 254 ) )
goto read_error;
ok = true;
read_error:
fclose( f );
return ok;
}