diff --git a/mozilla/htmlparser/tests/outsinks/Convert.cpp b/mozilla/htmlparser/tests/outsinks/Convert.cpp
index 72b90ea296d..06003d148a0 100644
--- a/mozilla/htmlparser/tests/outsinks/Convert.cpp
+++ b/mozilla/htmlparser/tests/outsinks/Convert.cpp
@@ -20,12 +20,15 @@
* Contributor(s): Akkana Peck.
*/
+#include // for isdigit()
+
#include "nsParserCIID.h"
#include "nsIParser.h"
#include "nsHTMLContentSinkStream.h"
#include "nsHTMLToTXTSinkStream.h"
#include "nsIComponentManager.h"
#include "CNavDTD.h"
+#include "nsXIFDTD.h"
extern "C" void NS_SetupRegistry();
@@ -44,27 +47,26 @@ static NS_DEFINE_IID(kParserCID, NS_PARSER_IID);
// Interface IID's
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
+nsresult
+Compare(nsString& str, nsString& filename)
+{
+ printf("Sorry, don't know how to compare yet\n");
+ char* charstar = str.ToNewUTF8String();
+ printf("Output string is: %s\n-------------------- \n", charstar);
+ delete[] charstar;
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
//----------------------------------------------------------------------
// Convert html on stdin to either plaintext or (if toHTML) html
//----------------------------------------------------------------------
-nsresult HTML2text(int toHTML)
+nsresult
+HTML2text(nsString& inString, nsString& inType, nsString& outType, int wrapCol, nsString& compareAgainst)
{
nsresult rv = NS_OK;
- nsString inString;
nsString outString;
- // Read in the string from the file: very inefficient, but who cares?
- char c;
- while ((c = getchar()) != EOF)
- inString += c;
-
-#if 0
- printf("Input string is: %s\n-------------------- \n",
- inString.ToNewCString());
- printf("------------------------------------\n");
-#endif
-
// Create a parser
nsIParser* parser;
rv = nsComponentManager::CreateInstance(kParserCID, nsnull,
@@ -78,11 +80,11 @@ nsresult HTML2text(int toHTML)
nsIHTMLContentSink* sink = nsnull;
// Create the appropriate output sink
- if (toHTML)
+ if (outType == "text/html")
rv = NS_New_HTML_ContentSinkStream(&sink, &outString, 0);
else // default to plaintext
- rv = NS_New_HTMLToTXT_SinkStream(&sink, &outString, 72, 2);
+ rv = NS_New_HTMLToTXT_SinkStream(&sink, &outString, wrapCol, 2);
if (NS_FAILED(rv))
{
@@ -92,7 +94,10 @@ nsresult HTML2text(int toHTML)
parser->SetContentSink(sink);
nsIDTD* dtd = nsnull;
- rv = NS_NewNavHTMLDTD(&dtd);
+ if (inType == "text/xif")
+ rv = NS_NewXIFDTD(&dtd);
+ else
+ rv = NS_NewNavHTMLDTD(&dtd);
if (NS_FAILED(rv))
{
printf("Couldn't create new HTML DTD: 0x%x\n", rv);
@@ -101,32 +106,138 @@ nsresult HTML2text(int toHTML)
parser->RegisterDTD(dtd);
- rv = parser->Parse(inString, 0, "text/html", PR_FALSE, PR_TRUE);
+ char* inTypeStr = inType.ToNewCString();
+ rv = parser->Parse(inString, 0, inTypeStr, PR_FALSE, PR_TRUE);
+ delete[] inTypeStr;
if (NS_FAILED(rv))
{
printf("Parse() failed! 0x%x\n", rv);
return rv;
}
- printf("Output string is: %s\n-------------------- \n",
- outString.ToNewCString());
-
NS_IF_RELEASE(dtd);
NS_IF_RELEASE(sink);
NS_RELEASE(parser);
- return rv;
+ if (compareAgainst.Length() > 0)
+ return Compare(outString, compareAgainst);
+
+ char* charstar = outString.ToNewUTF8String();
+ printf("Output string is:\n--------------------\n%s\n--------------------\n",
+ charstar);
+ delete[] charstar;
+
+ return NS_OK;
}
//----------------------------------------------------------------------
int main(int argc, char** argv)
{
+ nsString inType ("text/html");
+ nsString outType ("text/plain");
+ int wrapCol = 72;
+ nsString compareAgainst;
+
+
+ // Skip over progname arg:
+ const char* progname = argv[0];
+ --argc; ++argv;
+
+ // Process flags
+ while (argc > 0 && argv[0][0] == '-')
+ {
+ switch (argv[0][1])
+ {
+ case 'h':
+ printf("\
+Usage: %s [-i intype] [-o outtype] [-w wrapcol] [-c comparison_file] infile\n\
+\tIn/out types are mime types (e.g. text/html)\n\
+\tcomparison_file is a file against which to compare the output\n\
+\t (not yet implemented\n\
+\tDefaults are -i text/html -o text/plain -w 72 [stdin]\n",
+ progname);
+ exit(0);
+
+ case 'i':
+ if (argv[0][2] != '\0')
+ inType = argv[0]+2;
+ else {
+ inType = argv[1];
+ --argc;
+ ++argv;
+ }
+ break;
+
+ case 'o':
+ if (argv[0][2] != '\0')
+ outType = argv[0]+2;
+ else {
+ outType = argv[1];
+ --argc;
+ ++argv;
+ }
+ break;
+
+ case 'w':
+ if (isdigit(argv[0][2]))
+ wrapCol = atoi(argv[0]+2);
+ else {
+ wrapCol = atoi(argv[1]);
+ --argc;
+ ++argv;
+ }
+ break;
+
+ case 'c':
+ if (argv[0][2] != '\0')
+ compareAgainst = argv[0]+2;
+ else {
+ compareAgainst = argv[1];
+ --argc;
+ ++argv;
+ }
+ break;
+ }
+ ++argv;
+ --argc;
+ }
+
+ FILE* file = 0;
+ if (argc > 0) // read from a file
+ {
+ // Open the file in a Unix-centric way,
+ // until I find out how to use nsFileSpec:
+ file = fopen(argv[0], "r");
+ if (!file)
+ {
+ fprintf(stderr, "Can't open file %s", argv[0]);
+ perror(" ");
+ exit(1);
+ }
+ }
+ else file = stdin;
+
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, 0);
NS_SetupRegistry();
- if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h')
- HTML2text(1);
- else
- HTML2text(0);
+ // Read in the string: very inefficient, but who cares?
+ nsString inString;
+ char c;
+ while ((c = getc(file)) != EOF)
+ inString += c;
+
+ if (file != stdin)
+ fclose(file);
+
+#if 0
+ printf("Input string is: %s\n-------------------- \n",
+ inString.ToNewCString());
+ printf("------------------------------------\n");
+#endif
+
+ printf("inType = '%s', outType = '%s'\n", inType.ToNewCString(), outType.ToNewCString());
+ HTML2text(inString, inType, outType, wrapCol, compareAgainst);
+
+ return 0;
}
diff --git a/mozilla/htmlparser/tests/outsinks/Makefile.in b/mozilla/htmlparser/tests/outsinks/Makefile.in
index 3f7f1d1afca..a1512361d5d 100644
--- a/mozilla/htmlparser/tests/outsinks/Makefile.in
+++ b/mozilla/htmlparser/tests/outsinks/Makefile.in
@@ -22,7 +22,7 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
-PROGRAM = outtest
+PROGRAM = TestOutput
CPPSRCS = \
Convert.cpp \
@@ -35,5 +35,14 @@ LIBS = \
$(NSPR_LIBS) \
$(NULL)
+TEST_FILES = \
+ plainwrap.html \
+ entityxif.xif \
+ $(NULL)
+
include $(topsrcdir)/config/rules.mk
+install::
+ $(INSTALL) -m 555 $(PROGRAM) $(DIST)/bin
+ $(INSTALL) $(TEST_FILES) $(DIST)/bin/OutTestData
+
diff --git a/mozilla/htmlparser/tests/outsinks/entityxif.xif b/mozilla/htmlparser/tests/outsinks/entityxif.xif
new file mode 100644
index 00000000000..ee8843e01a7
--- /dev/null
+++ b/mozilla/htmlparser/tests/outsinks/entityxif.xif
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+ -- The contents of this file are subject to the Netscape Public
+ -- License Version 1.1 (the "License"); you may not use this file
+ -- except in compliance with the License. You may obtain a copy of
+ -- the License at http://www.mozilla.org/NPL/
+ --
+ -- Software distributed under the License is distributed on an "AS
+ -- IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ -- implied. See the License for the specific language governing
+ -- rights and limitations under the License.
+ --
+ -- The Original Code is Mozilla Communicator client code, released
+ -- March 31, 1998.
+ --
+ -- The Initial Developer of the Original Code is Netscape
+ -- Communications Corporation. Portions created by Netscape are
+ -- Copyright (C) 1998-1999 Netscape Communications Corporation. All
+ -- Rights Reserved.
+ --
+ -- Contributor(s):
+
+
+
+
+
+
+
+http://www.hotbot.com/?MT=Search+Engines
+SM=MC
+DV=0
+LG=any
+DC=10
+DE=2
+BT=H
+Search.x=31
+Search.y=7r
+
+
+
+
+
+
diff --git a/mozilla/htmlparser/tests/outsinks/makefile.win b/mozilla/htmlparser/tests/outsinks/makefile.win
index d9dcb56750f..cb8fa42cb01 100644
--- a/mozilla/htmlparser/tests/outsinks/makefile.win
+++ b/mozilla/htmlparser/tests/outsinks/makefile.win
@@ -1,4 +1,4 @@
-!#!nmake
+#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
diff --git a/mozilla/htmlparser/tests/outsinks/plainwrap.html b/mozilla/htmlparser/tests/outsinks/plainwrap.html
new file mode 100644
index 00000000000..ee5dfff7a61
--- /dev/null
+++ b/mozilla/htmlparser/tests/outsinks/plainwrap.html
@@ -0,0 +1,39 @@
+
+
+Ender Plain Text Test Page
+
+
+
+
+80 char width (for reference only)
+---------|---------|---------|---------|---------|---------|---------|---------|
+Welcome to the Gecko Plaintext Editor.
+This message has the wrapping set to 72 columns using a style sheet.
+Typed text will wrap to the current wrap setting. You can view or set the wrap settings by typing various characters, as such:
+- alt-C: print the current wrap column setting.
+- alt-]: increase the wrap setting by 5
+- alt-[: decrease the wrap setting by 5
+- ctrl-\: wrap to window width (wrapcolumn = -1)
+- alt-\: turn off wrapping (wrapcolumn = 0)
+
+
diff --git a/mozilla/htmlparser/tests/outsinks/quotes.html b/mozilla/htmlparser/tests/outsinks/quotes.html
new file mode 100644
index 00000000000..8ecf5975099
--- /dev/null
+++ b/mozilla/htmlparser/tests/outsinks/quotes.html
@@ -0,0 +1,5 @@
+
+
+This is a page with "double quotes" and <angle brackets>.
+
+
diff --git a/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp b/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp
index 72b90ea296d..06003d148a0 100644
--- a/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp
+++ b/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp
@@ -20,12 +20,15 @@
* Contributor(s): Akkana Peck.
*/
+#include // for isdigit()
+
#include "nsParserCIID.h"
#include "nsIParser.h"
#include "nsHTMLContentSinkStream.h"
#include "nsHTMLToTXTSinkStream.h"
#include "nsIComponentManager.h"
#include "CNavDTD.h"
+#include "nsXIFDTD.h"
extern "C" void NS_SetupRegistry();
@@ -44,27 +47,26 @@ static NS_DEFINE_IID(kParserCID, NS_PARSER_IID);
// Interface IID's
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
+nsresult
+Compare(nsString& str, nsString& filename)
+{
+ printf("Sorry, don't know how to compare yet\n");
+ char* charstar = str.ToNewUTF8String();
+ printf("Output string is: %s\n-------------------- \n", charstar);
+ delete[] charstar;
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
//----------------------------------------------------------------------
// Convert html on stdin to either plaintext or (if toHTML) html
//----------------------------------------------------------------------
-nsresult HTML2text(int toHTML)
+nsresult
+HTML2text(nsString& inString, nsString& inType, nsString& outType, int wrapCol, nsString& compareAgainst)
{
nsresult rv = NS_OK;
- nsString inString;
nsString outString;
- // Read in the string from the file: very inefficient, but who cares?
- char c;
- while ((c = getchar()) != EOF)
- inString += c;
-
-#if 0
- printf("Input string is: %s\n-------------------- \n",
- inString.ToNewCString());
- printf("------------------------------------\n");
-#endif
-
// Create a parser
nsIParser* parser;
rv = nsComponentManager::CreateInstance(kParserCID, nsnull,
@@ -78,11 +80,11 @@ nsresult HTML2text(int toHTML)
nsIHTMLContentSink* sink = nsnull;
// Create the appropriate output sink
- if (toHTML)
+ if (outType == "text/html")
rv = NS_New_HTML_ContentSinkStream(&sink, &outString, 0);
else // default to plaintext
- rv = NS_New_HTMLToTXT_SinkStream(&sink, &outString, 72, 2);
+ rv = NS_New_HTMLToTXT_SinkStream(&sink, &outString, wrapCol, 2);
if (NS_FAILED(rv))
{
@@ -92,7 +94,10 @@ nsresult HTML2text(int toHTML)
parser->SetContentSink(sink);
nsIDTD* dtd = nsnull;
- rv = NS_NewNavHTMLDTD(&dtd);
+ if (inType == "text/xif")
+ rv = NS_NewXIFDTD(&dtd);
+ else
+ rv = NS_NewNavHTMLDTD(&dtd);
if (NS_FAILED(rv))
{
printf("Couldn't create new HTML DTD: 0x%x\n", rv);
@@ -101,32 +106,138 @@ nsresult HTML2text(int toHTML)
parser->RegisterDTD(dtd);
- rv = parser->Parse(inString, 0, "text/html", PR_FALSE, PR_TRUE);
+ char* inTypeStr = inType.ToNewCString();
+ rv = parser->Parse(inString, 0, inTypeStr, PR_FALSE, PR_TRUE);
+ delete[] inTypeStr;
if (NS_FAILED(rv))
{
printf("Parse() failed! 0x%x\n", rv);
return rv;
}
- printf("Output string is: %s\n-------------------- \n",
- outString.ToNewCString());
-
NS_IF_RELEASE(dtd);
NS_IF_RELEASE(sink);
NS_RELEASE(parser);
- return rv;
+ if (compareAgainst.Length() > 0)
+ return Compare(outString, compareAgainst);
+
+ char* charstar = outString.ToNewUTF8String();
+ printf("Output string is:\n--------------------\n%s\n--------------------\n",
+ charstar);
+ delete[] charstar;
+
+ return NS_OK;
}
//----------------------------------------------------------------------
int main(int argc, char** argv)
{
+ nsString inType ("text/html");
+ nsString outType ("text/plain");
+ int wrapCol = 72;
+ nsString compareAgainst;
+
+
+ // Skip over progname arg:
+ const char* progname = argv[0];
+ --argc; ++argv;
+
+ // Process flags
+ while (argc > 0 && argv[0][0] == '-')
+ {
+ switch (argv[0][1])
+ {
+ case 'h':
+ printf("\
+Usage: %s [-i intype] [-o outtype] [-w wrapcol] [-c comparison_file] infile\n\
+\tIn/out types are mime types (e.g. text/html)\n\
+\tcomparison_file is a file against which to compare the output\n\
+\t (not yet implemented\n\
+\tDefaults are -i text/html -o text/plain -w 72 [stdin]\n",
+ progname);
+ exit(0);
+
+ case 'i':
+ if (argv[0][2] != '\0')
+ inType = argv[0]+2;
+ else {
+ inType = argv[1];
+ --argc;
+ ++argv;
+ }
+ break;
+
+ case 'o':
+ if (argv[0][2] != '\0')
+ outType = argv[0]+2;
+ else {
+ outType = argv[1];
+ --argc;
+ ++argv;
+ }
+ break;
+
+ case 'w':
+ if (isdigit(argv[0][2]))
+ wrapCol = atoi(argv[0]+2);
+ else {
+ wrapCol = atoi(argv[1]);
+ --argc;
+ ++argv;
+ }
+ break;
+
+ case 'c':
+ if (argv[0][2] != '\0')
+ compareAgainst = argv[0]+2;
+ else {
+ compareAgainst = argv[1];
+ --argc;
+ ++argv;
+ }
+ break;
+ }
+ ++argv;
+ --argc;
+ }
+
+ FILE* file = 0;
+ if (argc > 0) // read from a file
+ {
+ // Open the file in a Unix-centric way,
+ // until I find out how to use nsFileSpec:
+ file = fopen(argv[0], "r");
+ if (!file)
+ {
+ fprintf(stderr, "Can't open file %s", argv[0]);
+ perror(" ");
+ exit(1);
+ }
+ }
+ else file = stdin;
+
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, 0);
NS_SetupRegistry();
- if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h')
- HTML2text(1);
- else
- HTML2text(0);
+ // Read in the string: very inefficient, but who cares?
+ nsString inString;
+ char c;
+ while ((c = getc(file)) != EOF)
+ inString += c;
+
+ if (file != stdin)
+ fclose(file);
+
+#if 0
+ printf("Input string is: %s\n-------------------- \n",
+ inString.ToNewCString());
+ printf("------------------------------------\n");
+#endif
+
+ printf("inType = '%s', outType = '%s'\n", inType.ToNewCString(), outType.ToNewCString());
+ HTML2text(inString, inType, outType, wrapCol, compareAgainst);
+
+ return 0;
}
diff --git a/mozilla/parser/htmlparser/tests/outsinks/Makefile.in b/mozilla/parser/htmlparser/tests/outsinks/Makefile.in
index 3f7f1d1afca..a1512361d5d 100644
--- a/mozilla/parser/htmlparser/tests/outsinks/Makefile.in
+++ b/mozilla/parser/htmlparser/tests/outsinks/Makefile.in
@@ -22,7 +22,7 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
-PROGRAM = outtest
+PROGRAM = TestOutput
CPPSRCS = \
Convert.cpp \
@@ -35,5 +35,14 @@ LIBS = \
$(NSPR_LIBS) \
$(NULL)
+TEST_FILES = \
+ plainwrap.html \
+ entityxif.xif \
+ $(NULL)
+
include $(topsrcdir)/config/rules.mk
+install::
+ $(INSTALL) -m 555 $(PROGRAM) $(DIST)/bin
+ $(INSTALL) $(TEST_FILES) $(DIST)/bin/OutTestData
+
diff --git a/mozilla/parser/htmlparser/tests/outsinks/entityxif.xif b/mozilla/parser/htmlparser/tests/outsinks/entityxif.xif
new file mode 100644
index 00000000000..ee8843e01a7
--- /dev/null
+++ b/mozilla/parser/htmlparser/tests/outsinks/entityxif.xif
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+ -- The contents of this file are subject to the Netscape Public
+ -- License Version 1.1 (the "License"); you may not use this file
+ -- except in compliance with the License. You may obtain a copy of
+ -- the License at http://www.mozilla.org/NPL/
+ --
+ -- Software distributed under the License is distributed on an "AS
+ -- IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ -- implied. See the License for the specific language governing
+ -- rights and limitations under the License.
+ --
+ -- The Original Code is Mozilla Communicator client code, released
+ -- March 31, 1998.
+ --
+ -- The Initial Developer of the Original Code is Netscape
+ -- Communications Corporation. Portions created by Netscape are
+ -- Copyright (C) 1998-1999 Netscape Communications Corporation. All
+ -- Rights Reserved.
+ --
+ -- Contributor(s):
+
+
+
+
+
+
+
+http://www.hotbot.com/?MT=Search+Engines
+SM=MC
+DV=0
+LG=any
+DC=10
+DE=2
+BT=H
+Search.x=31
+Search.y=7r
+
+
+
+
+
+
diff --git a/mozilla/parser/htmlparser/tests/outsinks/makefile.win b/mozilla/parser/htmlparser/tests/outsinks/makefile.win
index d9dcb56750f..cb8fa42cb01 100644
--- a/mozilla/parser/htmlparser/tests/outsinks/makefile.win
+++ b/mozilla/parser/htmlparser/tests/outsinks/makefile.win
@@ -1,4 +1,4 @@
-!#!nmake
+#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
diff --git a/mozilla/parser/htmlparser/tests/outsinks/plainwrap.html b/mozilla/parser/htmlparser/tests/outsinks/plainwrap.html
new file mode 100644
index 00000000000..ee5dfff7a61
--- /dev/null
+++ b/mozilla/parser/htmlparser/tests/outsinks/plainwrap.html
@@ -0,0 +1,39 @@
+
+
+Ender Plain Text Test Page
+
+
+
+
+80 char width (for reference only)
+---------|---------|---------|---------|---------|---------|---------|---------|
+Welcome to the Gecko Plaintext Editor.
+This message has the wrapping set to 72 columns using a style sheet.
+Typed text will wrap to the current wrap setting. You can view or set the wrap settings by typing various characters, as such:
+- alt-C: print the current wrap column setting.
+- alt-]: increase the wrap setting by 5
+- alt-[: decrease the wrap setting by 5
+- ctrl-\: wrap to window width (wrapcolumn = -1)
+- alt-\: turn off wrapping (wrapcolumn = 0)
+
+
diff --git a/mozilla/parser/htmlparser/tests/outsinks/quotes.html b/mozilla/parser/htmlparser/tests/outsinks/quotes.html
new file mode 100644
index 00000000000..8ecf5975099
--- /dev/null
+++ b/mozilla/parser/htmlparser/tests/outsinks/quotes.html
@@ -0,0 +1,5 @@
+
+
+This is a page with "double quotes" and <angle brackets>.
+
+