2012-05-21 11:12:37 +00: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 06:53:57 +00:00
|
|
|
|
2005-08-15 18:29:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-08 18:17:49 +00:00
|
|
|
#include "nsXPCOM.h"
|
2005-08-15 18:29:55 +00:00
|
|
|
#include "nsINIParser.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2003-04-02 06:53:57 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2005-08-15 18:29:55 +00:00
|
|
|
StringCB(const char *aKey, const char *aValue, void* aClosure)
|
2003-04-02 06:53:57 +00:00
|
|
|
{
|
2005-08-15 18:29:55 +00:00
|
|
|
printf("%s=%s\n", aKey, aValue);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-04-02 06:53:57 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2005-08-15 18:29:55 +00:00
|
|
|
SectionCB(const char *aSection, void* aClosure)
|
2003-04-02 06:53:57 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsINIParser *ini = reinterpret_cast<nsINIParser*>(aClosure);
|
2005-08-15 18:29:55 +00:00
|
|
|
|
|
|
|
printf("[%s]\n", aSection);
|
2003-04-02 06:53:57 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
ini->GetStrings(aSection, StringCB, nullptr);
|
2003-04-02 06:53:57 +00:00
|
|
|
|
2005-08-15 18:29:55 +00:00
|
|
|
printf("\n");
|
2003-04-02 06:53:57 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-04-02 06:53:57 +00:00
|
|
|
}
|
2005-08-15 18:29:55 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "Usage: %s <ini-file>\n", argv[0]);
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> lf;
|
2005-08-15 18:29:55 +00:00
|
|
|
|
|
|
|
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(argv[1]),
|
2011-10-17 14:59:28 +00:00
|
|
|
true,
|
2005-08-15 18:29:55 +00: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;
|
|
|
|
}
|
|
|
|
|