Example #1
0
//////////////////////////////////////////////////////////////////////
// DeleteBuffer
// return:   0  success
//          -1  error
//
int CAsyncPort::DeleteBuffer(unsigned nBytes)
{
    if (nBytes >= m_nInBufSize) {
        return (ClearInputBuffer());
	}

    HANDLE hMutex = CreateMutex(NULL, FALSE, m_szMutexName);
    if (hMutex == NULL) {
        return (-1);
    }
    if (WaitForSingleObject(hMutex, INFINITE) == WAIT_FAILED) {
        CloseHandle(hMutex);
        return (-1);
    }

	while (nBytes --) {
		m_nInBufIndex = (m_nInBufIndex + 1) % IN_BUFFER_SIZE;
        m_nInBufSize --;
	}

    ReleaseMutex(hMutex);
    CloseHandle(hMutex);

    return (0);
}
Example #2
0
bool CGraphmatFile :: GraphmatMain ()
{
    m_LastError = "";

    if (0x500000 < GetInputBuffer().size())
    {
        m_LastError = "File is to large, it cannot be more than 5 MB";
        return false;
    };


    InitTokenBuffer();

    {
        // NUMBER of all UNITS which were read from INPUT file
        size_t  CurrOutBufOffset  = 0;

        // we should process all bytes except the last terminating null
        size_t InputBufferSize = GetInputBuffer().size()-1;

        for (size_t InputOffset  = 0; InputOffset < InputBufferSize ; )
        {
            CGraLine NewLine;

            NewLine.SetToken(GetUnitBufferStart() + CurrOutBufOffset);
            DWORD	PageNumber;
            InputOffset = NewLine.ReadWord(InputOffset,this, PageNumber);

            //  ignore single spaces in order to save memory
            if	( !NewLine.IsSingleSpaceToDelete() )
            {
                AddUnit(NewLine);
                CurrOutBufOffset += NewLine.GetTokenLength();
                if (NewLine.IsPageBreak() )
                    SetPageNumber(GetUnits().size() - 1,PageNumber);
            }
            else
            {
                assert (!GetUnits().empty());
                GetUnit(GetUnits().size() -1).SetSingleSpaceAfter();
            };


        }
    }


    // больше TBuf не нужен, так что освобождаем память
    ClearInputBuffer();


    for (size_t i=1; i< GetUnits().size(); i++)
        InitNonContextDescriptors(GetUnit(i));


    if (m_bOnlyNonContextDescriptors)
        return true;

    BuildUnitBufferUpper();

    InitContextDescriptors (0,GetUnits().size());

    MacSynHierarchy();


    if (m_bSentBreaker)
        if (!DealSentBreaker ())
        {
            m_LastError = "An exception occurred in Sentence breaker";
            return false;
        };


    if   (m_bWriteTextBuffer)
        WriteVector(m_SaveTxtName, GetUnitBuf());

    if   (m_bWriteGraFile)
        WriteGraphMat (m_GraFileName.c_str());


    return true;
};