rv = NS_NewHTMLParser(&parser);
rv = NS_NewParser(&parser);
extern "C" NS_EXPORT int DebugRobot(   nsVoidArray * workList,    nsIWebWidget * ww,    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;  nsIParserDebug * pIParserDebug;  nsresult rval = NS_NewParserDebug(&pIParserDebug);  if (NS_OK != rval) {    fputs("Cannot create parser debugger.\n", stdout);    NS_RELEASE(myObserver);    return -1;  }  pIParserDebug->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    nsIURL* url;    nsresult rv = NS_NewURL(&url, *urlName);    if (NS_OK != rv) {      printf("invalid URL: '");      fputs(*urlName, stdout);      printf("'\n");      NS_RELEASE(pIParserDebug);      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;    rv = NS_NewHTMLParser(&parser);    if (NS_OK != rv) {      printf("can't make parser\n");      NS_RELEASE(pIParserDebug);      NS_RELEASE(myObserver);      return -1;    }    nsIRobotSink* sink;    rv = NS_NewRobotSink(&sink);    if (NS_OK != rv) {      printf("can't make parser\n");      NS_RELEASE(pIParserDebug);      NS_RELEASE(myObserver);      return -1;    }    sink->Init(url);    sink->AddObserver(myObserver);    parser->SetContentSink(sink);    g_bReadyForNextUrl = PR_FALSE;    parser->Parse(url, pl, PR_TRUE, pIParserDebug);/* XXX hook up stream listener here! */    while (!g_bReadyForNextUrl) {       if (yieldProc != NULL)          (*yieldProc)(url->GetSpec());    }    g_bReadyForNextUrl = PR_FALSE;    if (ww) {      ww->LoadURL(url->GetSpec(), pl);/* XXX hook up stream listener here! */      while (!g_bReadyForNextUrl) {         if (yieldProc != NULL)            (*yieldProc)(url->GetSpec());      }    }      NS_RELEASE(sink);    NS_RELEASE(parser);    NS_RELEASE(url);  }  fputs ("Robot completed.\n", stdout);  NS_RELEASE(pl);  NS_RELEASE(myObserver);  pIParserDebug->DumpVectorRecord();  NS_RELEASE(pIParserDebug);  return 0;}