Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
UniversalChardetTest.cpp File Reference
#include "nsISupports.h"
#include "nsIComponentManager.h"
#include "nsICharsetDetector.h"
#include "nsICharsetDetectionObserver.h"
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

class  nsReporter

Defines

#define MAXBSIZE   (1L << 13)

Functions

void usage ()
nsresult GetDetector (const char *key, nsICharsetDetector **det)
nsresult GetObserver (nsICharsetDetectionObserver **aRes)
int main (int argc, char **argv)
 The Xalan testcases app.

Define Documentation

#define MAXBSIZE   (1L << 13)

Definition at line 51 of file UniversalChardetTest.cpp.


Function Documentation

nsresult GetDetector ( const char *  key,
nsICharsetDetector **  det 
)

Definition at line 78 of file UniversalChardetTest.cpp.

{
  char buf[128];
  strcpy(buf, NS_CHARSET_DETECTOR_CONTRACTID_BASE);
  strcat(buf, key);
  return CallCreateInstance(buf, det);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 87 of file UniversalChardetTest.cpp.

{
  *aRes = nsnull;
  nsReporter* rep = new nsReporter();
  if(rep) {
     return rep->QueryInterface(NS_GET_IID(nsICharsetDetectionObserver) ,
                                (void**)aRes);
  }
  return NS_ERROR_OUT_OF_MEMORY;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 98 of file UniversalChardetTest.cpp.

                                {
  char buf[MAXBSIZE];
  PRUint32 bs;
  if( 2 != argc )
  {
    usage();
    printf("Need 1 arguments\n");
    return(-1);
  }
  bs = atoi(argv[1]);
  if((bs <1)||(bs>MAXBSIZE))
  {
    usage();
    printf("blocksize out of range - %s\n", argv[2]);
    return(-1);
  }
  nsresult rev = NS_OK;
  nsICharsetDetector *det = nsnull;
  rev = GetDetector("universal_charset_detector", &det);
  if(NS_FAILED(rev) || (nsnull == det) ){
    usage();
    printf("Error: Could not find Universal Detector\n");
    printf("XPCOM ERROR CODE = %x\n", rev);
    return(-1);
  }
  nsICharsetDetectionObserver *obs = nsnull;
  rev = GetObserver(&obs);
  if(NS_SUCCEEDED(rev)) {
    rev = det->Init(obs);
    NS_IF_RELEASE(obs);
    if(NS_FAILED(rev))
    {
      printf("XPCOM ERROR CODE = %x\n", rev);
      return(-1);
    }
  } else {
    printf("XPCOM ERROR CODE = %x\n", rev);
    return(-1);
  }

  size_t sz;
  PRBool done = PR_FALSE;
  do
  {
    sz = read(0, buf, bs);
    if(sz > 0) {
      if(! done) {
        rev = det->DoIt( buf, sz, &done);
        if(NS_FAILED(rev))
        {
          printf("XPCOM ERROR CODE = %x\n", rev);
          return(-1);
        }
      }
    }
  } while((sz > 0) &&  (!done) );
  //} while(sz > 0);
  if(!done)
  {
    rev = det->Done();
    if(NS_FAILED(rev))
    {
      printf("XPCOM ERROR CODE = %x\n", rev);
      return(-1);
    }
  }

  NS_IF_RELEASE(det);
  return (0);
}

Here is the call graph for this function:

void usage ( void  )

Definition at line 53 of file UniversalChardetTest.cpp.

             {
   printf("Usage: DetectFile blocksize\n"
        "    blocksize: 1 ~ %ld\n"
          "  Data are passed in from STDIN\n"
          ,  MAXBSIZE);
}