1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:ts=8:et:sw=4:
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * This file is meant to be used with |#define CSS_REPORT_PARSE_ERRORS|
9 * in mozilla/dom/html/style/src/nsCSSScanner.h uncommented, and the
10 * |#ifdef DEBUG| block in nsCSSScanner::OutputError (in
11 * nsCSSScanner.cpp in the same directory) used (even if not a debug
19 #include "nsNetUtil.h"
21 #include "nsContentCID.h"
22 #include "mozilla/StyleSheetInlines.h"
23 #include "mozilla/css/Loader.h"
25 using namespace mozilla
;
27 static already_AddRefed
<nsIURI
> FileToURI(const char* aFilename
,
29 nsCOMPtr
<nsIFile
> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID
, aRv
));
30 NS_ENSURE_TRUE(lf
, nullptr);
31 // XXX Handle relative paths somehow.
32 lf
->InitWithNativePath(nsDependentCString(aFilename
));
34 nsIURI
* uri
= nullptr;
35 nsresult rv
= NS_NewFileURI(&uri
, lf
);
40 static int ParseCSSFile(nsIURI
* aSheetURI
) {
41 RefPtr
<mozilla::css::Loader
> = new mozilla::css::Loader();
42 RefPtr
<CSSStyleSheet
> sheet
;
43 loader
->LoadSheetSync(aSheetURI
, getter_AddRefs(sheet
));
44 NS_ASSERTION(sheet
, "sheet load failed");
45 /* This can happen if the file can't be found (e.g. you
46 * ask for a relative path and xpcom/io rejects it)
48 if (!sheet
) return -1;
50 sheet
->GetComplete(complete
);
51 NS_ASSERTION(complete
, "synchronous load did not complete");
52 if (!complete
) return -2;
56 int main(int argc
, char** argv
) {
58 fprintf(stderr
, "%s [FILE]...\n", argv
[0]);
60 nsresult rv
= NS_InitXPCOM(nullptr, nullptr, nullptr);
61 if (NS_FAILED(rv
)) return (int)rv
;
64 for (int i
= 1; i
< argc
; ++i
) {
65 const char* filename
= argv
[i
];
67 printf("\nParsing %s.\n", filename
);
69 nsCOMPtr
<nsIURI
> uri
= FileToURI(filename
, &rv
);
70 if (rv
== NS_ERROR_OUT_OF_MEMORY
) {
71 fprintf(stderr
, "Out of memory.\n");
74 if (uri
) res
= ParseCSSFile(uri
);
77 NS_ShutdownXPCOM(nullptr);