-
Notifications
You must be signed in to change notification settings - Fork 2
/
getentry.c
101 lines (98 loc) · 2.02 KB
/
getentry.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
/*
* TwinSock - "Troy's Windows Sockets"
*
* Copyright (C) 1995 Troy Rollo <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the license in the file LICENSE.TXT included
* with the TwinSock distribution.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifdef _Windows
#include <windows.h>
#else
#include <stdio.h>
#include <ctype.h>
#endif
int
GetTwinSockSetting( char *pchSection,
char *pchItem,
char *pchDefault,
char *pchBuffer,
int nChars)
{
#ifdef _Windows
return GetPrivateProfileString( pchSection,
pchItem,
pchDefault,
pchBuffer,
nChars,
"TWINSOCK.INI");
#else
static FILE *fpIni = 0;
static int iDone = 0;
char achBuffer[1024];
int iInSection = 0;
char *c;
if (!iDone)
{
strcpy(achBuffer, getenv("HOME"));
strcat(achBuffer, "/.twinsock");
fpIni = fopen(achBuffer, "r");
iDone = 1;
}
if (!fpIni)
{
strcpy(pchBuffer, pchDefault);
return strlen(pchDefault);
}
rewind(fpIni);
while (fgets(achBuffer, 1024, fpIni))
{
if (*achBuffer == ';' || *achBuffer == '\n')
continue;
if (*achBuffer == '[')
{
c = achBuffer + 1;
while (isspace(*c))
c++;
if (strncmp(c, pchSection, strlen(pchSection)))
{
iInSection = 0;
continue;
}
c += strlen(pchSection);
while (isspace(*c))
c++;
if (*c != ']')
{
iInSection = 0;
continue;
}
iInSection = 1;
continue;
}
if (!iInSection)
continue;
if (strncmp(achBuffer, pchItem, strlen(pchItem)))
continue;
c = achBuffer + strlen(pchItem);
while (isspace(*c))
c++;
if (*c++ != '=')
continue;
while (isspace(*c))
c++;
c[strlen(c)] = 0;
strncpy(pchBuffer, c, nChars);
pchBuffer[nChars - 1] = 0;
pchBuffer[strlen(pchBuffer) - 1] = 0;
return strlen(pchBuffer);
}
strcpy(pchBuffer, pchDefault);
return strlen(pchDefault);
#endif
}