Re: nsICharsetDetector
Jean-Marc Desperrier <[email protected]> Fri, 26 Aug 2005 00:53:34 +0200
| Newsgroups | gmane.comp.mozilla.internationalization |
|---|---|
| Organization | Another Netscape Collabra Server User |
| Message-ID | <[email protected]> |
[email protected] wrote: > the nsICharsetDetector interface does not seem to exist. I cannot > locate the idl file anywhere It's old code. Deeply outdated. I don't know what happens here, but maybe there was no idl and the .h was edited by hand. Anyway the .h is here and probably nothing is generated from a idl : http://lxr.mozilla.org/seamonkey/source/intl/chardet/public/nsICharsetDetector.h > Is there anything special I need to do to get the nsICharsetDetector > interface or am I going at this the wrong way? You asked me by mail how I got UniversalChardetTest.cpp working again. I tried several change, but the only one actually useful one was to init xpcom. I have no idea how it can have worked at one time without the init. The most relevant change in my patch is : =================================================================== RCS file: /cvsroot/mozilla/extensions/universalchardet/tests/UniversalChardetTest.cpp,v retrieving revision 1.13 diff -u -w -r1.13 UniversalChardetTest.cpp --- UniversalChardetTest.cpp 1 Nov 2004 18:50:14 -0000 1.13 +++ UniversalChardetTest.cpp 25 Aug 2005 22:35:17 -0000 @@ -35,6 +35,8 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ +#include <nsCOMPtr.h> +#include <nsXPCOM.h> #include "nsISupports.h" #include "nsIComponentManager.h" #include "nsICharsetDetector.h" @@ -111,27 +121,37 @@ printf("blocksize out of range - %s\n", argv[2]); return(-1); } - nsresult rev = NS_OK; + + nsresult rv = NS_OK; + nsIServiceManager *servMgr; + + rv = NS_InitXPCOM2(&servMgr, nsnull, nsnull); + if (NS_FAILED(rv)) return rv; + In fact, locally I have more difference than that, but I think only the above is actually useful. Still I'll copy the full list below : Index: UniversalChardetTest.cpp =================================================================== RCS file: /cvsroot/mozilla/extensions/universalchardet/tests/UniversalChardetTest.cpp,v retrieving revision 1.13 diff -u -w -r1.13 UniversalChardetTest.cpp --- UniversalChardetTest.cpp 1 Nov 2004 18:50:14 -0000 1.13 +++ UniversalChardetTest.cpp 25 Aug 2005 22:50:05 -0000 @@ -35,6 +35,8 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ +#include <nsCOMPtr.h> +#include <nsXPCOM.h> #include "nsISupports.h" #include "nsIComponentManager.h" #include "nsICharsetDetector.h" @@ -81,6 +83,14 @@ strcpy(buf, NS_CHARSET_DETECTOR_CONTRACTID_BASE); strcat(buf, key); return CallCreateInstance(buf, det); +#if 0 + char buf[128]; + nsresult rv; + strcpy(buf, NS_CHARSET_DETECTOR_CONTRACTID_BASE); + strcat(buf, key); + *det = do_CreateInstance(bug, &rv); + return rv; +#endif } @@ -111,27 +121,37 @@ printf("blocksize out of range - %s\n", argv[2]); return(-1); } - nsresult rev = NS_OK; + + nsresult rv = NS_OK; + nsIServiceManager *servMgr; + + rv = NS_InitXPCOM2(&servMgr, nsnull, nsnull); + if (NS_FAILED(rv)) return rv; + +// static char CD_ID[] = "@mozilla.org/intl/charsetdetect;1?type=universal_charset_detector"; +// nsCOMPtr <nsICharsetDetector> det = +// do_CreateInstance(CD_ID, &rv); + nsICharsetDetector *det = nsnull; - rev = GetDetector("universal_charset_detector", &det); - if(NS_FAILED(rev) || (nsnull == det) ){ + rv = GetDetector("universal_charset_detector", &det); + if(NS_FAILED(rv) || (nsnull == det) ){ usage(); printf("Error: Could not find Universal Detector\n"); - printf("XPCOM ERROR CODE = %x\n", rev); + printf("XPCOM ERROR CODE = %x\n", rv); return(-1); } nsICharsetDetectionObserver *obs = nsnull; - rev = GetObserver(&obs); - if(NS_SUCCEEDED(rev)) { - rev = det->Init(obs); + rv = GetObserver(&obs); + if(NS_SUCCEEDED(rv)) { + rv = det->Init(obs); NS_IF_RELEASE(obs); - if(NS_FAILED(rev)) + if(NS_FAILED(rv)) { - printf("XPCOM ERROR CODE = %x\n", rev); + printf("XPCOM ERROR CODE = %x\n", rv); return(-1); } } else { - printf("XPCOM ERROR CODE = %x\n", rev); + printf("XPCOM ERROR CODE = %x\n", rv); return(-1); } @@ -142,10 +162,10 @@ sz = read(0, buf, bs); if(sz > 0) { if(! done) { - rev = det->DoIt( buf, sz, &done); - if(NS_FAILED(rev)) + rv = det->DoIt( buf, sz, &done); + if(NS_FAILED(rv)) { - printf("XPCOM ERROR CODE = %x\n", rev); + printf("XPCOM ERROR CODE = %x\n", rv); return(-1); } } @@ -154,14 +174,17 @@ //} while(sz > 0); if(!done) { - rev = det->Done(); - if(NS_FAILED(rev)) + rv = det->Done(); + if(NS_FAILED(rv)) { - printf("XPCOM ERROR CODE = %x\n", rev); + printf("XPCOM ERROR CODE = %x\n", rv); return(-1); } } NS_IF_RELEASE(det); - return (0); + if (servMgr) + rv = NS_ShutdownXPCOM(servMgr); + + return rv; }