2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-04-02 10:53:57 +04:00
|
|
|
|
2005-08-15 22:29:55 +04:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
#include "nsXPCOM.h"
|
2005-08-15 22:29:55 +04:00
|
|
|
#include "nsINIParser.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2003-04-02 10:53:57 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2005-08-15 22:29:55 +04:00
|
|
|
StringCB(const char *aKey, const char *aValue, void* aClosure)
|
2003-04-02 10:53:57 +04:00
|
|
|
{
|
2005-08-15 22:29:55 +04:00
|
|
|
printf("%s=%s\n", aKey, aValue);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2003-04-02 10:53:57 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2005-08-15 22:29:55 +04:00
|
|
|
SectionCB(const char *aSection, void* aClosure)
|
2003-04-02 10:53:57 +04:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsINIParser *ini = reinterpret_cast<nsINIParser*>(aClosure);
|
2005-08-15 22:29:55 +04:00
|
|
|
|
|
|
|
printf("[%s]\n", aSection);
|
2003-04-02 10:53:57 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
ini->GetStrings(aSection, StringCB, nullptr);
|
2003-04-02 10:53:57 +04:00
|
|
|
|
2005-08-15 22:29:55 +04:00
|
|
|
printf("\n");
|
2003-04-02 10:53:57 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2003-04-02 10:53:57 +04:00
|
|
|
}
|
2005-08-15 22:29:55 +04:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "Usage: %s <ini-file>\n", argv[0]);
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> lf;
|
2005-08-15 22:29:55 +04:00
|
|
|
|
|
|
|
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(argv[1]),
|
2011-10-17 18:59:28 +04:00
|
|
|
true,
|
2005-08-15 22:29:55 +04:00
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
fprintf(stderr, "Error: NS_NewNativeLocalFile failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINIParser ini;
|
|
|
|
rv = ini.Init(lf);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
fprintf(stderr, "Error: Init failed.");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ini.GetSections(SectionCB, &ini);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|