xpcom/tests/TestINIParser.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 #include <string.h>
     7 #include "nsXPCOM.h"
     8 #include "nsINIParser.h"
     9 #include "nsIFile.h"
    11 static bool
    12 StringCB(const char *aKey, const char *aValue, void* aClosure)
    13 {
    14   printf("%s=%s\n", aKey, aValue);
    16   return true;
    17 }
    19 static bool
    20 SectionCB(const char *aSection, void* aClosure)
    21 {
    22   nsINIParser *ini = reinterpret_cast<nsINIParser*>(aClosure);
    24   printf("[%s]\n", aSection);
    26   ini->GetStrings(aSection, StringCB, nullptr);
    28   printf("\n");
    30   return true;
    31 }
    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   }
    40   nsCOMPtr<nsIFile> lf;
    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   }
    50   nsINIParser ini;
    51   rv = ini.Init(lf);
    52   if (NS_FAILED(rv)) {
    53     fprintf(stderr, "Error: Init failed.");
    54     return 2;
    55   }
    57   ini.GetSections(SectionCB, &ini);
    59   return 0;
    60 }

mercurial