xpcom/tests/TestINIParser.cpp

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:f3577417289d
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include <string.h>
6
7 #include "nsXPCOM.h"
8 #include "nsINIParser.h"
9 #include "nsIFile.h"
10
11 static bool
12 StringCB(const char *aKey, const char *aValue, void* aClosure)
13 {
14 printf("%s=%s\n", aKey, aValue);
15
16 return true;
17 }
18
19 static bool
20 SectionCB(const char *aSection, void* aClosure)
21 {
22 nsINIParser *ini = reinterpret_cast<nsINIParser*>(aClosure);
23
24 printf("[%s]\n", aSection);
25
26 ini->GetStrings(aSection, StringCB, nullptr);
27
28 printf("\n");
29
30 return true;
31 }
32
33 int main(int argc, char **argv)
34 {
35 if (argc < 2) {
36 fprintf(stderr, "Usage: %s <ini-file>\n", argv[0]);
37 return 255;
38 }
39
40 nsCOMPtr<nsIFile> lf;
41
42 nsresult rv = NS_NewNativeLocalFile(nsDependentCString(argv[1]),
43 true,
44 getter_AddRefs(lf));
45 if (NS_FAILED(rv)) {
46 fprintf(stderr, "Error: NS_NewNativeLocalFile failed\n");
47 return 1;
48 }
49
50 nsINIParser ini;
51 rv = ini.Init(lf);
52 if (NS_FAILED(rv)) {
53 fprintf(stderr, "Error: Init failed.");
54 return 2;
55 }
56
57 ini.GetSections(SectionCB, &ini);
58
59 return 0;
60 }
61

mercurial