michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: // vim:cindent:ts=8:et:sw=4: 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: /* michael@0: * This file is meant to be used with |#define CSS_REPORT_PARSE_ERRORS| michael@0: * in mozilla/content/html/style/src/nsCSSScanner.h uncommented, and the michael@0: * |#ifdef DEBUG| block in nsCSSScanner::OutputError (in michael@0: * nsCSSScanner.cpp in the same directory) used (even if not a debug michael@0: * build). michael@0: */ michael@0: michael@0: #include "nsXPCOM.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: #include "nsIFile.h" michael@0: #include "nsNetUtil.h" michael@0: michael@0: #include "nsContentCID.h" michael@0: #include "mozilla/css/Loader.h" michael@0: #include "nsCSSStyleSheet.h" michael@0: michael@0: static already_AddRefed michael@0: FileToURI(const char *aFilename, nsresult *aRv = 0) michael@0: { michael@0: nsCOMPtr lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, aRv)); michael@0: NS_ENSURE_TRUE(lf, nullptr); michael@0: // XXX Handle relative paths somehow. michael@0: lf->InitWithNativePath(nsDependentCString(aFilename)); michael@0: michael@0: nsIURI *uri = nullptr; michael@0: nsresult rv = NS_NewFileURI(&uri, lf); michael@0: if (aRv) michael@0: *aRv = rv; michael@0: return uri; michael@0: } michael@0: michael@0: static int michael@0: ParseCSSFile(nsIURI *aSheetURI) michael@0: { michael@0: nsRefPtr = new mozilla::css::Loader(); michael@0: nsRefPtr sheet; michael@0: loader->LoadSheetSync(aSheetURI, getter_AddRefs(sheet)); michael@0: NS_ASSERTION(sheet, "sheet load failed"); michael@0: /* This can happen if the file can't be found (e.g. you michael@0: * ask for a relative path and xpcom/io rejects it) michael@0: */ michael@0: if (!sheet) michael@0: return -1; michael@0: bool complete; michael@0: sheet->GetComplete(complete); michael@0: NS_ASSERTION(complete, "synchronous load did not complete"); michael@0: if (!complete) michael@0: return -2; michael@0: return 0; michael@0: } michael@0: michael@0: int main(int argc, char** argv) michael@0: { michael@0: if (argc < 2) { michael@0: fprintf(stderr, "%s [FILE]...\n", argv[0]); michael@0: } michael@0: nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); michael@0: if (NS_FAILED(rv)) michael@0: return (int)rv; michael@0: michael@0: int res = 0; michael@0: for (int i = 1; i < argc; ++i) { michael@0: const char *filename = argv[i]; michael@0: michael@0: printf("\nParsing %s.\n", filename); michael@0: michael@0: nsCOMPtr uri = FileToURI(filename, &rv); michael@0: if (rv == NS_ERROR_OUT_OF_MEMORY) { michael@0: fprintf(stderr, "Out of memory.\n"); michael@0: return 1; michael@0: } michael@0: if (uri) michael@0: res = ParseCSSFile(uri); michael@0: } michael@0: michael@0: NS_ShutdownXPCOM(nullptr); michael@0: michael@0: return res; michael@0: }