Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | // vim:cindent:ts=8:et:sw=4: |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * This file is meant to be used with |#define CSS_REPORT_PARSE_ERRORS| |
michael@0 | 9 | * in mozilla/content/html/style/src/nsCSSScanner.h uncommented, and the |
michael@0 | 10 | * |#ifdef DEBUG| block in nsCSSScanner::OutputError (in |
michael@0 | 11 | * nsCSSScanner.cpp in the same directory) used (even if not a debug |
michael@0 | 12 | * build). |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | #include "nsXPCOM.h" |
michael@0 | 16 | #include "nsCOMPtr.h" |
michael@0 | 17 | |
michael@0 | 18 | #include "nsIFile.h" |
michael@0 | 19 | #include "nsNetUtil.h" |
michael@0 | 20 | |
michael@0 | 21 | #include "nsContentCID.h" |
michael@0 | 22 | #include "mozilla/css/Loader.h" |
michael@0 | 23 | #include "nsCSSStyleSheet.h" |
michael@0 | 24 | |
michael@0 | 25 | static already_AddRefed<nsIURI> |
michael@0 | 26 | FileToURI(const char *aFilename, nsresult *aRv = 0) |
michael@0 | 27 | { |
michael@0 | 28 | nsCOMPtr<nsIFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, aRv)); |
michael@0 | 29 | NS_ENSURE_TRUE(lf, nullptr); |
michael@0 | 30 | // XXX Handle relative paths somehow. |
michael@0 | 31 | lf->InitWithNativePath(nsDependentCString(aFilename)); |
michael@0 | 32 | |
michael@0 | 33 | nsIURI *uri = nullptr; |
michael@0 | 34 | nsresult rv = NS_NewFileURI(&uri, lf); |
michael@0 | 35 | if (aRv) |
michael@0 | 36 | *aRv = rv; |
michael@0 | 37 | return uri; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | static int |
michael@0 | 41 | ParseCSSFile(nsIURI *aSheetURI) |
michael@0 | 42 | { |
michael@0 | 43 | nsRefPtr<mozilla::css::Loader> = new mozilla::css::Loader(); |
michael@0 | 44 | nsRefPtr<nsCSSStyleSheet> sheet; |
michael@0 | 45 | loader->LoadSheetSync(aSheetURI, getter_AddRefs(sheet)); |
michael@0 | 46 | NS_ASSERTION(sheet, "sheet load failed"); |
michael@0 | 47 | /* This can happen if the file can't be found (e.g. you |
michael@0 | 48 | * ask for a relative path and xpcom/io rejects it) |
michael@0 | 49 | */ |
michael@0 | 50 | if (!sheet) |
michael@0 | 51 | return -1; |
michael@0 | 52 | bool complete; |
michael@0 | 53 | sheet->GetComplete(complete); |
michael@0 | 54 | NS_ASSERTION(complete, "synchronous load did not complete"); |
michael@0 | 55 | if (!complete) |
michael@0 | 56 | return -2; |
michael@0 | 57 | return 0; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | int main(int argc, char** argv) |
michael@0 | 61 | { |
michael@0 | 62 | if (argc < 2) { |
michael@0 | 63 | fprintf(stderr, "%s [FILE]...\n", argv[0]); |
michael@0 | 64 | } |
michael@0 | 65 | nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); |
michael@0 | 66 | if (NS_FAILED(rv)) |
michael@0 | 67 | return (int)rv; |
michael@0 | 68 | |
michael@0 | 69 | int res = 0; |
michael@0 | 70 | for (int i = 1; i < argc; ++i) { |
michael@0 | 71 | const char *filename = argv[i]; |
michael@0 | 72 | |
michael@0 | 73 | printf("\nParsing %s.\n", filename); |
michael@0 | 74 | |
michael@0 | 75 | nsCOMPtr<nsIURI> uri = FileToURI(filename, &rv); |
michael@0 | 76 | if (rv == NS_ERROR_OUT_OF_MEMORY) { |
michael@0 | 77 | fprintf(stderr, "Out of memory.\n"); |
michael@0 | 78 | return 1; |
michael@0 | 79 | } |
michael@0 | 80 | if (uri) |
michael@0 | 81 | res = ParseCSSFile(uri); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | NS_ShutdownXPCOM(nullptr); |
michael@0 | 85 | |
michael@0 | 86 | return res; |
michael@0 | 87 | } |