Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
convperf.cpp File Reference
#include <windows.h>
#include <winnls.h>
#include "nscore.h"
#include "nsString.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsIUnicodeEncoder.h"
#include "nsIUnicodeDecoder.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define INBUFSIZE   (1024*16)
#define MEDBUFSIZE   (1024*16*2)
#define OUTBUFSIZE   (1024*16*8)

Functions

static NS_DEFINE_CID (kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID)
static NS_DEFINE_IID (kICharsetConverterManagerIID, NS_ICHARSETCONVERTERMANAGER_IID)
void usage ()
void memcpyDecode (const char *src, PRInt32 srclen, char *dest)
void memcpyEncode (const char *src, PRInt32 srclen, char *dest)
void WideDecode (const char *src, PRInt32 srclen, PRUnichar *dest, PRInt32 *destLen)
void NarrowEncode (const PRUnichar *src, PRInt32 srclen, char *dest, PRInt32 *destLen)
void msDecode (UINT cp, const char *src, PRInt32 srclen, PRUnichar *dest, PRInt32 *destLen)
void msEncode (UINT cp, const PRUnichar *src, PRInt32 srcLen, char *dest, PRInt32 *destLen)
int main (int argc, const char **argv)

Variables

int fromcodeind = 0
int tocodeind = 0
FILEinfile = 0
char inbuffer [INBUFSIZE]
char outbuffer [OUTBUFSIZE]
PRUnichar medbuffer [MEDBUFSIZE]
nsIUnicodeEncoderencoder = nsnull
nsIUnicodeDecoderdecoder = nsnull
UINT incp = 932
UINT outcp = 932

Define Documentation

#define INBUFSIZE   (1024*16)

Definition at line 61 of file convperf.cpp.

#define MEDBUFSIZE   (1024*16*2)

Definition at line 62 of file convperf.cpp.

#define OUTBUFSIZE   (1024*16*8)

Definition at line 63 of file convperf.cpp.


Function Documentation

int main ( int  argc,
const char **  argv 
)

Definition at line 113 of file convperf.cpp.

{
   nsresult res;
   nsCOMPtr<nsICharsetConverterManager> ccMain =
      do_GetService(kCharsetConverterManagerCID, &res);
   if(NS_FAILED(res))
   {
        fprintf(stderr, "Cannot get Character Converter Manager %x\n", res);
   }
   int i;
   if(argc > 5)
   {
     for(i =0; i < argc; i++)
     {
       if(strcmp(argv[i], "-f") == 0)
       {
             tocodeind = i+1;
             res = ccMain->GetUnicodeDecoder(argv[tocodeind], &decoder);
             if(NS_FAILED(res)) {
              fprintf(stderr, "Cannot get Unicode decoder %s %x\n", 
                     argv[tocodeind],res);
              return -1;
            }

       }
       if(strcmp(argv[i], "-t") == 0)
       {
             fromcodeind = i+1;
             res = ccMain->GetUnicodeEncoderRaw(argv[fromcodeind], &encoder);
             if(NS_FAILED(res)) {
              fprintf(stderr, "Cannot get Unicode encoder %s %x\n", 
                     argv[fromcodeind],res);
              return -1;
            }
       }
     }
     if(argc == 6)
     {
        infile = fopen(argv[5], "rb");
        if(NULL == infile) 
        {  
           usage();
           fprintf(stderr,"cannot open file %s\n", argv[5]);
           return -1; 
        }
     }
     else
     {
        infile = stdin;
     }
    
     PRInt32 insize,medsize,outsize;
     while((insize=fread(inbuffer, 1,INBUFSIZE,infile)) > 0)
     {
        medsize=MEDBUFSIZE;
        
       res = decoder->Convert(inbuffer,&insize, medbuffer, &medsize);
        if(NS_FAILED(res)) {
            fprintf(stderr, "failed in decoder->Convert %x\n",res);
           return -1;
       }
        outsize = OUTBUFSIZE;
       res = encoder->Convert(medbuffer, &medsize, outbuffer,&outsize);
        if(NS_FAILED(res)) {
            fprintf(stderr, "failed in encoder->Convert %x\n",res);
           return -1;
       }
        fwrite(outbuffer, 1, outsize, stdout);

        memcpyDecode(inbuffer, insize, outbuffer);

        memcpyEncode(inbuffer, insize, outbuffer);

        medsize = MEDBUFSIZE;
        msDecode(incp, inbuffer, insize, medbuffer, &medsize);

        outsize = OUTBUFSIZE;
        msEncode(outcp, medbuffer, medsize, outbuffer, &outsize);

        medsize = MEDBUFSIZE;
        WideDecode( inbuffer, insize, medbuffer, &medsize);

        outsize = OUTBUFSIZE;
        NarrowEncode( medbuffer, medsize, outbuffer, &outsize);
     }
     
     fclose(infile);
     fclose(stdout);
     fprintf(stderr, "Done!\n");
     return 0;
   }
   usage();
   return -1;
}

Here is the call graph for this function:

void memcpyDecode ( const char *  src,
PRInt32  srclen,
char *  dest 
)

Definition at line 72 of file convperf.cpp.

{
   ::memcpy(dest, src, srclen);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void memcpyEncode ( const char *  src,
PRInt32  srclen,
char *  dest 
)

Definition at line 76 of file convperf.cpp.

{
   ::memcpy(dest, src, srclen);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void msDecode ( UINT  cp,
const char *  src,
PRInt32  srclen,
PRUnichar dest,
PRInt32 destLen 
)

Definition at line 97 of file convperf.cpp.

{
   *destLen = ::MultiByteToWideChar(cp, 0,src, srclen, (LPWSTR)dest, *destLen);
   if(*destLen <= 0)
      fprintf(stderr, "problem in ::MultiByteToWideChar\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void msEncode ( UINT  cp,
const PRUnichar src,
PRInt32  srcLen,
char *  dest,
PRInt32 destLen 
)

Definition at line 104 of file convperf.cpp.

{
   *destLen = ::WideCharToMultiByte(cp, 0, src, srcLen, (LPSTR)dest, *destLen, 
                (LPCSTR)" ", FALSE);
   if(*destLen <= 0)
      fprintf(stderr, "problem in ::WideCharToMultiByte\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NarrowEncode ( const PRUnichar src,
PRInt32  srclen,
char *  dest,
PRInt32 destLen 
)

Definition at line 89 of file convperf.cpp.

{
   const PRUnichar* end = src+srclen ;
   while(src < end)
     *dest++ = (char) *src++;
   *destLen = srclen;
}

Here is the caller graph for this function:

static NS_DEFINE_CID ( kCharsetConverterManagerCID  ,
NS_ICHARSETCONVERTERMANAGER_CID   
) [static]
static NS_DEFINE_IID ( kICharsetConverterManagerIID  ,
NS_ICHARSETCONVERTERMANAGER_IID   
) [static]
void usage ( void  )

Definition at line 52 of file convperf.cpp.

{
  printf(
"convperf -f fromcode -t tocode [file]\n"
  );
}
void WideDecode ( const char *  src,
PRInt32  srclen,
PRUnichar dest,
PRInt32 destLen 
)

Definition at line 81 of file convperf.cpp.

{
   const char* end = src+srclen ;
   while(src < end)
     *dest++ = (PRUnichar) *src++;
   *destLen = srclen;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 68 of file convperf.cpp.

Definition at line 67 of file convperf.cpp.

Definition at line 58 of file convperf.cpp.

Definition at line 64 of file convperf.cpp.

UINT incp = 932

Definition at line 69 of file convperf.cpp.

FILE* infile = 0

Definition at line 60 of file convperf.cpp.

Definition at line 66 of file convperf.cpp.

Definition at line 65 of file convperf.cpp.

UINT outcp = 932

Definition at line 70 of file convperf.cpp.

Definition at line 59 of file convperf.cpp.