Back to index

lightning-sunbird  0.9+nobinonly
Functions
TestParser.cpp File Reference
#include "nsXPCOM.h"
#include "nsIComponentManager.h"
#include "nsParserCIID.h"
#include "nsIParser.h"
#include "nsILoggingSink.h"
#include "nsIInputStream.h"

Go to the source code of this file.

Functions

static NS_DEFINE_CID (kParserCID, NS_PARSER_CID)
static NS_DEFINE_CID (kLoggingSinkCID, NS_LOGGING_SINK_CID)
static NS_DEFINE_CID (kNavDTDCID, NS_CNAVDTD_CID)
nsresult ParseData (char *anInputStream, char *anOutputStream)
int main (int argc, char **argv)
 The Xalan testcases app.

Function Documentation

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 117 of file TestParser.cpp.

{
  if (argc < 3) {
              printf("\nUsage: <inputfile> <outputfile>\n"); 
    return -1;
  }

  nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
  if (NS_FAILED(rv)) {
    printf("NS_InitXPCOM2 failed\n");
    return -1;
  }

  ParseData(argv[1],argv[2]);

  return 0;
}

Here is the call graph for this function:

static NS_DEFINE_CID ( kParserCID  ,
NS_PARSER_CID   
) [static]
static NS_DEFINE_CID ( kLoggingSinkCID  ,
NS_LOGGING_SINK_CID   
) [static]
static NS_DEFINE_CID ( kNavDTDCID  ,
NS_CNAVDTD_CID   
) [static]
nsresult ParseData ( char *  anInputStream,
char *  anOutputStream 
)

Definition at line 52 of file TestParser.cpp.

                                                             {
  NS_ENSURE_ARG_POINTER(anInputStream);
  NS_ENSURE_ARG_POINTER(anOutputStream);
       
  nsresult result = NS_OK;

  // Create a parser
  nsCOMPtr<nsIParser> parser(do_CreateInstance(kParserCID, &result));
  if (NS_FAILED(result)) {
    printf("\nUnable to create a parser\n");
    return result;
  }
  // Create a sink
  nsCOMPtr<nsILoggingSink> sink(do_CreateInstance(kLoggingSinkCID, &result));
  if (NS_FAILED(result)) {
    printf("\nUnable to create a sink\n");
    return result;
  }
  // Create a dtd
  nsCOMPtr<nsIDTD> dtd(do_CreateInstance(kNavDTDCID, &result));
  if(NS_FAILED(result)) {
    printf("Unable to create a dtd\n");
    return result;
  }
     
  PRFileDesc* in = PR_Open(anInputStream, PR_RDONLY, 777);
  if (!in) {
    printf("\nUnable to open input file - %s\n", anInputStream);
    return result;
  }
  
  PRFileDesc* out = PR_Open(anOutputStream, PR_CREATE_FILE|PR_WRONLY, 777);
  if (!out) {
    printf("\nUnable to open output file - %s\n", anOutputStream);
    return result;
  }

  nsString stream;
  char buffer[1024] = {0}; // XXX Yikes!
  PRBool done = PR_FALSE;
  PRInt32 length = 0;
  while(!done) {
    length = PR_Read(in, buffer, sizeof(buffer));
    if (length != 0) {
      stream.AppendWithConversion(buffer, length);
    }
    else {
      done=PR_TRUE;
    }
  }

  sink->SetOutputStream(out);
  parser->RegisterDTD(dtd);
       parser->SetContentSink(sink);
  result = parser->Parse(stream, 0, NS_LITERAL_CSTRING("text/html"), PR_FALSE, PR_TRUE);
  
  PR_Close(in);
  PR_Close(out);

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function: