michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: michael@0: #include "nsXPCOM.h" michael@0: #include "nsINIParser.h" michael@0: #include "nsIFile.h" michael@0: michael@0: static bool michael@0: StringCB(const char *aKey, const char *aValue, void* aClosure) michael@0: { michael@0: printf("%s=%s\n", aKey, aValue); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: static bool michael@0: SectionCB(const char *aSection, void* aClosure) michael@0: { michael@0: nsINIParser *ini = reinterpret_cast(aClosure); michael@0: michael@0: printf("[%s]\n", aSection); michael@0: michael@0: ini->GetStrings(aSection, StringCB, nullptr); michael@0: michael@0: printf("\n"); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: if (argc < 2) { michael@0: fprintf(stderr, "Usage: %s \n", argv[0]); michael@0: return 255; michael@0: } michael@0: michael@0: nsCOMPtr lf; michael@0: michael@0: nsresult rv = NS_NewNativeLocalFile(nsDependentCString(argv[1]), michael@0: true, michael@0: getter_AddRefs(lf)); michael@0: if (NS_FAILED(rv)) { michael@0: fprintf(stderr, "Error: NS_NewNativeLocalFile failed\n"); michael@0: return 1; michael@0: } michael@0: michael@0: nsINIParser ini; michael@0: rv = ini.Init(lf); michael@0: if (NS_FAILED(rv)) { michael@0: fprintf(stderr, "Error: Init failed."); michael@0: return 2; michael@0: } michael@0: michael@0: ini.GetSections(SectionCB, &ini); michael@0: michael@0: return 0; michael@0: } michael@0: