while (NS_SUCCEEDED(rv) && (isActiveFlag == PR_TRUE) && (!mInputStream->eof()) && (!mInputStream->failed()))
nsCOMPtr<nsILineInputStream> lineInputStream = do_QueryInterface(mInputStream); NS_ENSURE_TRUE(lineInputStream, NS_NOINTERFACE);  PRBool moreData = PR_TRUE;  while(NS_SUCCEEDED(rv) && isActiveFlag && moreData)
BookmarkParser::Parse(nsIRDFResource *aContainer, nsIRDFResource *nodeType){    // tokenize the input stream.    // XXX this needs to handle quotes, etc. it'd be nice to use the real parser for this...    nsresult            rv;    nsCOMPtr<nsIRDFContainer> container;    rv = nsComponentManager::CreateInstance(kRDFContainerCID,                        nsnull,                        NS_GET_IID(nsIRDFContainer),                        getter_AddRefs(container));    if (NS_FAILED(rv)) return rv;    rv = container->Init(mDataSource, aContainer);    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIRDFResource>    bookmarkNode = aContainer;    nsAutoString            description, line;    PRBool              isActiveFlag = PR_TRUE, inDescriptionFlag = PR_FALSE;    if ((mContents) && (mContentsLen > 0))    {        // we were able to read the entire bookmark file into memory, so process it        char                *linePtr;        PRInt32             eol;        while ((isActiveFlag == PR_TRUE) && (mStartOffset < (signed)mContentsLen))        {            linePtr = &mContents[mStartOffset];            eol = getEOL(mContents, mStartOffset, mContentsLen);            PRInt32 aLength;            if ((eol >= mStartOffset) && (eol < (signed)mContentsLen))            {                // mContents[eol] = '\0';                aLength = eol - mStartOffset;                mStartOffset = eol + 1;            }            else            {                aLength = mContentsLen - mStartOffset;                mStartOffset = mContentsLen + 1;                isActiveFlag = PR_FALSE;            }            if (aLength < 1)    continue;            line.Truncate();            DecodeBuffer(line, linePtr, aLength);            rv = ProcessLine(container, nodeType, bookmarkNode,                line, description, inDescriptionFlag, isActiveFlag);            if (NS_FAILED(rv))  break;        }    }    else if (mInputStream)    {        // we were unable to read in the entire bookmark file at once,        // so let's try reading it in a bit at a time instead, and process it        while (NS_SUCCEEDED(rv) && (isActiveFlag == PR_TRUE) &&            (!mInputStream->eof()) && (!mInputStream->failed()))        {            line.Truncate();            while (PR_TRUE)            {                char    buf[256];                PRBool  untruncated = mInputStream->readline(buf, sizeof(buf));                // in.readline() return PR_FALSE if there was buffer overflow,                // or there was a catastrophe. Check to see if we're here                // because of the latter...                NS_ASSERTION (! mInputStream->failed(), "error reading file");                if (mInputStream->failed())                {                    rv = NS_ERROR_FAILURE;                    break;                }                PRUint32        aLength;                if (untruncated)    aLength = strlen(buf);                else            aLength = sizeof(buf);                DecodeBuffer(line, buf, aLength);                                if (untruncated)    break;            }            if (NS_SUCCEEDED(rv))            {                rv = ProcessLine(container, nodeType, bookmarkNode,                    line, description, inDescriptionFlag, isActiveFlag);            }        }    }    return rv;}