printf("invalid URL: '");
PRINTF("invalid URL: '");
extern "C" NS_EXPORT int DebugRobot(   nsVoidArray * workList,    nsIDocShell * docShell,    int iMaxLoads,    char * verify_dir,   void (*yieldProc )(const char *)   ){  int iCount = 1;  CStreamListener * pl = new CStreamListener;   NS_ADDREF(pl);  if (nsnull==workList)     return -1;  g_iMaxProcess = iMaxLoads;  g_iProcessed = 0;  g_bHitTop = PR_FALSE;  g_duplicateList = new nsVoidArray();  RobotSinkObserver* myObserver = new RobotSinkObserver();  NS_ADDREF(myObserver);  g_workList = workList;/*  nsIDTDDebug * pIDTDDebug;  nsresult rval = NS_NewDTDDebug(&pIDTDDebug);  if (NS_OK != rval) {    fputs("Cannot create parser debugger.\n", stdout);    NS_RELEASE(myObserver);    return -1;  }  pIDTDDebug->SetVerificationDirectory(verify_dir);*/  for (;;) {    PRInt32 n = g_workList->Count();    if (0 == n) {      break;    }    nsString* urlName = (nsString*) g_workList->ElementAt(n - 1);    g_workList->RemoveElementAt(n - 1);    // Create url    nsIURI* url;    nsresult rv;    NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);    if (NS_FAILED(rv)) return rv;    nsIURI *uri = nsnull;    char *uriStr = urlName->ToNewCString();    if (!uriStr) return NS_ERROR_OUT_OF_MEMORY;    rv = service->NewURI(uriStr, nsnull, &uri);    nsCRT::free(uriStr);    if (NS_FAILED(rv)) return rv;    rv = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url);    NS_RELEASE(uri);    if (NS_OK != rv) {      printf("invalid URL: '");      fputs(*urlName, stdout);      printf("'\n");      NS_RELEASE(myObserver);      return -1;    }    char str_num[25];    sprintf (str_num,"%d",iCount++);    fputs ("Robot: parsing(",stdout);    fputs (str_num,stdout);    fputs (") ",stdout);    fputs (*urlName,stdout);    fputs ("...",stdout);    delete urlName;    nsIParser* parser;    static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);    static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);    rv = nsComponentManager::CreateInstance(kCParserCID,                                       nsnull,                                       kCParserIID,                                       (void **)&parser);    if (NS_OK != rv) {      printf("can't make parser\n");      NS_RELEASE(myObserver);      return -1;    }    nsIRobotSink* sink;    rv = NS_NewRobotSink(&sink);    if (NS_OK != rv) {      printf("can't make parser\n");      NS_RELEASE(myObserver);      return -1;    }    sink->Init(url);    sink->AddObserver(myObserver);    parser->SetContentSink(sink);    g_bReadyForNextUrl = PR_FALSE;      parser->Parse(url, nsnull,PR_TRUE);/* XXX hook up stream listener here! */    while (!g_bReadyForNextUrl) {      if (yieldProc != NULL) {        char* spec;        (void)url->GetSpec(&spec);        (*yieldProc)(spec);        nsCRT::free(spec);      }    }    g_bReadyForNextUrl = PR_FALSE;    if (docShell) {      nsIDocumentLoader *docLoader;      nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));      webShell->GetDocumentLoader(docLoader);      if (docLoader) {        docLoader->AddObserver(pl);        NS_RELEASE(docLoader);      }      char* spec;      (void)url->GetSpec(&spec);      nsAutoString theSpec; theSpec.AssignWithConversion(spec);      nsCRT::free(spec);      nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));      webNav->LoadURI(theSpec.GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE);/* XXX hook up stream listener here! */      while (!g_bReadyForNextUrl) {        if (yieldProc != NULL) {          (void)url->GetSpec(&spec);          (*yieldProc)(spec);          nsCRT::free(spec);        }      }    }      NS_RELEASE(sink);    NS_RELEASE(parser);    NS_RELEASE(url);  }  fputs ("Robot completed.\n", stdout);  NS_RELEASE(pl);  NS_RELEASE(myObserver);//  pIDTDDebug->DumpVectorRecord();  //NS_RELEASE(pIDTDDebug);  return 0;}