Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
DetectCharset.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  nsStatis
class  nsBaseStatis
class  nsSimpleStatis
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 245 of file DetectCharset.cpp.


Function Documentation

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

Definition at line 281 of file DetectCharset.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:

Definition at line 290 of file DetectCharset.cpp.

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

The Xalan testcases app.

Definition at line 301 of file DetectCharset.cpp.

                                {
  char buf[MAXBSIZE];
  PRUint32 bs;
  if( 3 != argc )
  {
    usage();
    printf("Need 2 arguments\n");
    return(-1);
  }
  bs = atoi(argv[2]);
  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(argv[1], &det);
  if(NS_FAILED(rev) || (nsnull == det) ){
    usage();
    printf("Invalid Detector - %s\n", argv[1]);
    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;
  nsSimpleStatis  ks(0xb0,0xc8, (float)0.95952, "EUC-KR");
  nsSimpleStatis  js(0xa4,0xa5, (float)0.45006, "EUC-JP");
  nsStatis* stat[2] = {&ks, &js};
  PRUint32 i;
  do
  {
    sz = read(0, buf, bs); 
    if(sz > 0) {
      if(! done) {
printf("call DoIt %d\n",sz);
        rev = det->DoIt( buf, sz, &done);
printf("DoIt return Done = %d\n",done);
        if(NS_FAILED(rev))
        {
          printf("XPCOM ERROR CODE = %x\n", rev);
          return(-1);
        }
      }
      for(i=0;i<2;i++)
        stat[i]->HandleData(buf, sz);
    }
  // } while((sz > 0) &&  (!done) );
  } while(sz > 0);
  if(!done)
  {
printf("Done = %d\n",done);
printf("call Done %d\n",sz);
    rev = det->Done();
    if(NS_FAILED(rev))
    {
      printf("XPCOM ERROR CODE = %x\n", rev);
      return(-1);
    }
  }
  for(i=0;i<2;i++) {
    stat[i]->DataEnd();
    stat[i]->Report();
  }
printf( "Done\n");
  
  NS_IF_RELEASE(det);
printf( "Done 2\n");
  return (0);
}

Here is the call graph for this function:

void usage ( void  )

Definition at line 247 of file DetectCharset.cpp.

             {
   printf("Usage: DetectFile detector blocksize\n"
          "     detector: " 
          "ja_parallel_state_machine,"
          "ko_parallel_state_machine,"
          "zhcn_parallel_state_machine,"
          "zhtw_parallel_state_machine,"
          "zh_parallel_state_machine,"
          "cjk_parallel_state_machine,"
          "ruprob,"
          "ukprob,"
        "\n     blocksize: 1 ~ %ld\n"
          "  Data are passed in from STDIN\n"
          ,  MAXBSIZE);
}