Many changes to make output test really useful. Fix Windows makefile. Add some sample test input files

This commit is contained in:
akkana%netscape.com 1999-09-29 20:11:07 +00:00
Родитель 75ecd98021
Коммит afbf4d38c7
12 изменённых файлов: 429 добавлений и 54 удалений

Просмотреть файл

@ -20,12 +20,15 @@
* Contributor(s): Akkana Peck.
*/
#include <ctype.h> // 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;
}

Просмотреть файл

@ -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

Просмотреть файл

Просмотреть файл

@ -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

Просмотреть файл

@ -0,0 +1,39 @@
<html>
<head><!--
-- 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):
-->
<title>Ender Plain Text Test Page</title>
</head>
<body style="white-space: -moz-pre-wrap; width: 72ch; font-family: -moz-fixed; background-color: rgb(255,255,255); ">
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)
</body>
</html>

Просмотреть файл

Просмотреть файл

@ -20,12 +20,15 @@
* Contributor(s): Akkana Peck.
*/
#include <ctype.h> // 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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -0,0 +1,52 @@
<?xml version="1.0"?>
<!DOCTYPE xif>
<encode selection="0"/>
<section>
<section_head>
<document_info charset="ISO-8859-1"/>
</section_head>
<section_body>
<container isa="html">
<container isa="head">
<comment><content>
-- 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):
</content>
</comment>
</container><!--head-->
<container isa="body">
<attr name="style" value="white-space: -moz-pre-wrap; width: 72ch; font-family: -moz-fixed; background-color: rgb(255,255,255); "/>
<leaf isa="br">
</leaf><!--br-->
<content>http://www.hotbot.com/?MT=Search+Engines</content>
<entity value="amp"/><content>SM=MC</content>
<entity value="amp"/><content>DV=0</content>
<entity value="amp"/><content>LG=any</content>
<entity value="amp"/><content>DC=10</content>
<entity value="amp"/><content>DE=2</content>
<entity value="amp"/><content>BT=H</content>
<entity value="amp"/><content>Search.x=31</content>
<entity value="amp"/><content>Search.y=7r</content>
<leaf isa="br">
</leaf><!--br-->
</container><!--body-->
</container><!--html-->
</section_body>
</section>

Просмотреть файл

@ -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

Просмотреть файл

@ -0,0 +1,39 @@
<html>
<head><!--
-- 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):
-->
<title>Ender Plain Text Test Page</title>
</head>
<body style="white-space: -moz-pre-wrap; width: 72ch; font-family: -moz-fixed; background-color: rgb(255,255,255); ">
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)
</body>
</html>

Просмотреть файл

@ -0,0 +1,5 @@
<html>
<body>
This is a page with "double quotes" and &lt;angle brackets&gt;.
</body>
</html>