-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitest.c
89 lines (74 loc) · 1.82 KB
/
initest.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
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "iniman.h"
#define VALUE_LEN 512
#define MODE_GET 0
#define MODE_WRITE 1
#define MODE_DEL_ENT 2
#define MODE_DEL_SEC 3
static char buffer[VALUE_LEN];
int main(int argc, char **argv)
{
char *filename, *section, *entry, *value = buffer;
int mode;
if (argc < 2)
{
return -1;
}
if (!strcmp(argv[1], "-de"))
{
if (argc != 5) return -1;
mode = MODE_DEL_ENT;
entry = argv[4];
section = argv[3];
filename = argv[2];
}
if (!strcmp(argv[1], "-ds"))
{
if (argc != 4) return -1;
mode = MODE_DEL_SEC;
section = argv[3];
filename = argv[2];
}
if (!strcmp(argv[1], "-we"))
{
if (argc != 6) return -1;
mode = MODE_WRITE;
value = argv[5];
entry = argv[4];
section = argv[3];
filename = argv[2];
}
if (!strcmp(argv[1], "-ge"))
{
if (argc != 5) return -1;
mode = MODE_GET;
entry = argv[4];
section = argv[3];
filename = argv[2];
}
InitPrivateProfile(NULL);
switch (mode)
{
case MODE_WRITE:
WritePrivateProfileString(section, entry, value, filename);
FlushAllPrivateProfile();
break;
case MODE_GET:
GetPrivateProfileString(section, entry, "", value, VALUE_LEN, filename);
printf("%s\n", value);
break;
case MODE_DEL_ENT:
DeletePrivateProfileEntry(section, entry, filename);
FlushAllPrivateProfile();
break;
case MODE_DEL_SEC:
DeletePrivateProfileSection(section, filename);
FlushAllPrivateProfile();
break;
default:
break;
}
return 0;
}