コード例 #1
0
ファイル: editfile.cpp プロジェクト: Meridian59/Meridian59
//
/// Saves the contents of the Editor to a file whose name is specified by FileName.
/// Returns true if the write operation is successful.
/// The caller is responsible for any error UI
//
bool
TEditFile::Write(LPCTSTR fileName)
{
  if (!fileName)
  {
    if (FileName)
      fileName = FileName;
    else
      return false;
  }

  TFile file(fileName, TFile::WriteOnly|TFile::PermExclusive|TFile::CreateAlways);
  if (!file.IsOpen())
    return false;

  bool success = false;
  LPTSTR editBuffer = LockBuffer();
  if (editBuffer) {
    success = file.Write(editBuffer, static_cast<int>(::_tcslen(editBuffer)));
    UnlockBuffer(editBuffer);
    if (success)
      ClearModify();
  }
  return success;
}
コード例 #2
0
int CAPECompress::AddData(unsigned char * pData, int nBytes)
{
    if (m_pBuffer == NULL) return ERROR_INSUFFICIENT_MEMORY;

    int nBytesDone = 0;
    
    while (nBytesDone < nBytes)
    {
        // lock the buffer
        int nBytesAvailable = 0;
        unsigned char * pBuffer = LockBuffer(&nBytesAvailable);
        if (pBuffer == NULL || nBytesAvailable <= 0)
            return ERROR_UNDEFINED;
        
        // calculate how many bytes to copy and add that much to the buffer
        int nBytesToProcess = min(nBytesAvailable, nBytes - nBytesDone);
        memcpy(pBuffer, &pData[nBytesDone], nBytesToProcess);
                        
        // unlock the buffer (fail if not successful)
        int nRetVal = UnlockBuffer(nBytesToProcess);
        if (nRetVal != ERROR_SUCCESS)
                return nRetVal;

        // update our progress
        nBytesDone += nBytesToProcess;
    }

    return ERROR_SUCCESS;
} 
コード例 #3
0
void FString::Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen)
{
	LockBuffer();
	for (size_t checkpt = 0; checkpt < Len(); )
	{
		char *match = strstr (Chars + checkpt, oldstr);
		size_t len = Len();
		if (match != NULL)
		{
			size_t matchpt = match - Chars;
			if (oldstrlen != newstrlen)
			{
				ReallocBuffer (len + newstrlen - oldstrlen);
				memmove (Chars + matchpt + newstrlen, Chars + matchpt + oldstrlen, (len + 1 - matchpt - oldstrlen)*sizeof(char));
			}
			memcpy (Chars + matchpt, newstr, newstrlen);
			checkpt = matchpt + newstrlen;
		}
		else
		{
			break;
		}
	}
	UnlockBuffer();
}
コード例 #4
0
BString&
BString::SetToFormat(const char* format, ...)
{
	int32 bufferSize = 1024;
	char buffer[bufferSize];

	va_list arg;
	va_start(arg, format);
	int32 bytes = vsnprintf(buffer, bufferSize, format, arg);
	va_end(arg);

	if (bytes < 0)
		return Truncate(0);

	if (bytes < bufferSize) {
		SetTo(buffer);
		return *this;
	}

	va_list arg2;
	va_start(arg2, format);
	bytes = vsnprintf(LockBuffer(bytes), bytes + 1, format, arg2);
	va_end(arg2);

	if (bytes < 0)
		bytes = 0;

	UnlockBuffer(bytes);
	return *this;
}
コード例 #5
0
VideoBufferLock::~VideoBufferLock()
{
	UnlockBuffer();
	if (mBuffer)
		mBuffer->Release();
	if (m2DBuffer)
		m2DBuffer->Release();
}
コード例 #6
0
ファイル: viewedit.cpp プロジェクト: rickerliang/OpenNT
// this function returns the length in characters
UINT CEditView::GetBufferLength() const
{
	ASSERT_VALID(this);
	ASSERT(m_hWnd != NULL);
	LPCTSTR lpszText = LockBuffer();
	UINT nLen = lstrlen(lpszText);
	UnlockBuffer();
	return nLen;
}
コード例 #7
0
void FString::ToLower ()
{
	LockBuffer();
	size_t max = Len();
	for (size_t i = 0; i < max; ++i)
	{
		Chars[i] = (char)tolower(Chars[i]);
	}
	UnlockBuffer();
}
コード例 #8
0
ファイル: video.c プロジェクト: BackupTheBerlios/softdevice
/* ---------------------------------------------------------------------------
 */
void cVideoOut::SetOldPicture(sPicBuffer *picture)
{
  if (oldPicture)
    UnlockBuffer(oldPicture);
  if (picture && picture->owner==this) {
    LockBuffer(picture);
    oldPicture=picture;
  } else
    oldPicture = NULL;
}
コード例 #9
0
ファイル: viewedit.cpp プロジェクト: rickerliang/OpenNT
void CEditView::WriteToArchive(CArchive& ar)
	// Write just the text to an archive, no length prefix.
{
	ASSERT_VALID(this);
	LPCTSTR lpszText = LockBuffer();
	ASSERT(lpszText != NULL);
	UINT nLen = GetBufferLength();
	TRY
	{
		ar.Write(lpszText, nLen*sizeof(TCHAR));
	}
	CATCH_ALL(e)
	{
		UnlockBuffer();
		THROW_LAST();
	}
	END_CATCH_ALL
	UnlockBuffer();
	ASSERT_VALID(this);
}
コード例 #10
0
ファイル: zstring.cpp プロジェクト: BadSanta1980/gzdoom
void FString::ReplaceChars (const char *oldcharset, char newchar)
{
	size_t i, j;

	LockBuffer();
	for (i = 0, j = Len(); i < j; ++i)
	{
		if (strchr (oldcharset, Chars[i]) != NULL)
		{
			Chars[i] = newchar;
		}
	}
	UnlockBuffer();
}
コード例 #11
0
ファイル: zstring.cpp プロジェクト: BadSanta1980/gzdoom
void FString::ReplaceChars (char oldchar, char newchar)
{
	size_t i, j;

	LockBuffer();
	for (i = 0, j = Len(); i < j; ++i)
	{
		if (Chars[i] == oldchar)
		{
			Chars[i] = newchar;
		}
	}
	UnlockBuffer();
}
コード例 #12
0
ファイル: viewedit.cpp プロジェクト: rickerliang/OpenNT
void CEditView::GetSelectedText(CString& strResult) const
{
	ASSERT_VALID(this);
	int nStartChar, nEndChar;
	GetEditCtrl().GetSel(nStartChar, nEndChar);
	ASSERT((UINT)nEndChar <= GetBufferLength());
	LPCTSTR lpszText = ((CEditView*)this)->LockBuffer();
	UINT nLen = EndOfLine(lpszText, nEndChar, nStartChar) - nStartChar;
	memcpy(strResult.GetBuffer(nLen), lpszText + nStartChar,
		nLen * sizeof(TCHAR));
	strResult.ReleaseBuffer(nLen);
	UnlockBuffer();
	ASSERT_VALID(this);
}
コード例 #13
0
ファイル: editview.cpp プロジェクト: Ukusbobra/open-watcom-v2
void CEditView::GetSelectedText( CString &strResult ) const
/*********************************************************/
{
    DWORD   dwSelStart;
    DWORD   dwSelEnd;
    ::SendMessage( m_hWnd, EM_GETSEL, (WPARAM)&dwSelStart, (LPARAM)&dwSelEnd );
    if( dwSelEnd > dwSelStart ) {
        LPCTSTR lpszBuffer = LockBuffer();
        strResult.SetString( lpszBuffer + dwSelStart, dwSelEnd - dwSelStart );
        UnlockBuffer();
    } else {
        strResult.Empty();
    }
}
コード例 #14
0
ファイル: raystorm.cpp プロジェクト: Kalamatee/RayStorm
void CPadView::OnAppRender()
{
	BOOL bWaitResult;
	UBYTE *p;
	int xRes, yRes;
	char *szProg;
	MSG msg;

	CRenderOutput RenderOutput;
	if (!pRenderOutput)
	{
		pRenderOutput = new CRenderOutput();		
		pRenderOutput->Create(IDD_RENDER);
		pRenderOutput->CenterWindow();
	}
	if (pRenderOutput && !pRenderOutput->IsWindowVisible())
		pRenderOutput->ShowWindow(SW_SHOW);

	szProg = (char *)LockBuffer();
	hThread = pRenderOutput->Start(szProg);
	if (hThread)
	{
		do
		{
			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}

			bWaitResult = WaitForSingleObject (hThread, 0);
		}
		while (bWaitResult != WAIT_OBJECT_0);
	}

	CloseHandle(hThread);
	hThread = NULL;

	UnlockBuffer();
	pRenderOutput->End();
	
	if (ViewerDlg.IsWindowVisible())
	{
		if (GetPictureInfo(&p, &xRes, &yRes))
			ViewerDlg.Update(p, xRes, yRes);
	}
//	rsiCleanup();
}
コード例 #15
0
ファイル: zstring.cpp プロジェクト: BadSanta1980/gzdoom
void FString::StripChars (const char *killchars)
{
	size_t read, write, mylen;

	LockBuffer();
	for (read = write = 0, mylen = Len(); read < mylen; ++read)
	{
		if (strchr (killchars, Chars[read]) == NULL)
		{
			Chars[write++] = Chars[read];
		}
	}
	Chars[write] = '\0';
	ReallocBuffer (write);
	UnlockBuffer();
}
コード例 #16
0
ファイル: zstring.cpp プロジェクト: BadSanta1980/gzdoom
void FString::StripChars (char killchar)
{
	size_t read, write, mylen;

	LockBuffer();
	for (read = write = 0, mylen = Len(); read < mylen; ++read)
	{
		if (Chars[read] != killchar)
		{
			Chars[write++] = Chars[read];
		}
	}
	Chars[write] = '\0';
	ReallocBuffer (write);
	UnlockBuffer();
}
コード例 #17
0
void FString::SwapCase ()
{
	LockBuffer();
	size_t max = Len();
	for (size_t i = 0; i < max; ++i)
	{
		if (isupper(Chars[i]))
		{
			Chars[i] = (char)tolower(Chars[i]);
		}
		else
		{
			Chars[i] = (char)toupper(Chars[i]);
		}
	}
	UnlockBuffer();
}
コード例 #18
0
ファイル: editfile.cpp プロジェクト: Meridian59/Meridian59
//
/// Reads the contents of a previously specified file into the Editor. Returns true
/// if read operation is successful.
/// The caller is responsible for any error UI
//
bool
TEditFile::Read(LPCTSTR fileName)
{
  if (!fileName)
  {
    if (FileName)
      fileName = FileName;
    else
      return false;
  }

  bool   success = false;
  TFile file(fileName, TFile::ReadOnly|TFile::OpenExisting);

  if (file.IsOpen()) {
    long  charsToRead = file.Length();
    if (charsToRead >= 0) {
      Clear();

      // Lock and resize Editor's buffer to the size of the file
      // Then if OK, read the file into editBuffer
      //
      LPTSTR editBuffer = LockBuffer(uint(charsToRead+1));
      if (editBuffer) {
        if (file.Read(editBuffer, uint(charsToRead)) == uint(charsToRead)) {

          // 0 terminate Editor's buffer
          //
          editBuffer[int(charsToRead)] = 0;
          success = true;
          ClearModify();
        }
        UnlockBuffer(editBuffer, true);
      }
    }
  }
  return success;
}
コード例 #19
0
void FString::MergeChars (char merger, char newchar)
{
	size_t read, write, mylen;

	LockBuffer();
	for (read = write = 0, mylen = Len(); read < mylen; )
	{
		if (Chars[read] == merger)
		{
			while (Chars[++read] == merger)
			{
			}
			Chars[write++] = newchar;
		}
		else
		{
			Chars[write++] = Chars[read++];
		}
	}
	Chars[write] = '\0';
	ReallocBuffer (write);
	UnlockBuffer();
}
コード例 #20
0
void FString::MergeChars (const char *charset, char newchar)
{
	size_t read, write, mylen;

	LockBuffer();
	for (read = write = 0, mylen = Len(); read < mylen; )
	{
		if (strchr (charset, Chars[read]) != NULL)
		{
			while (strchr (charset, Chars[++read]) != NULL)
			{
			}
			Chars[write++] = newchar;
		}
		else
		{
			Chars[write++] = Chars[read++];
		}
	}
	Chars[write] = '\0';
	ReallocBuffer (write);
	UnlockBuffer();
}
コード例 #21
0
void DoExecute (GPtr globals)
{
	
	size_t total = 0;
	size_t done = 0;
	
	Boolean	doThis = true;
	
	BufferID sBuffer = 0;
	Ptr sData = NULL;
	BufferID dBuffer = 0;
	Ptr dData = NULL;
	BufferID mBuffer = 0;
	Ptr mData = NULL;
	BufferID rBuffer = 0;
	Ptr rData = NULL;
	
	PixelMemoryDesc sDesc, dDesc, mDesc, rDesc;

	ReadImageDocumentDesc *doc = gStuff->documentInfo;
	WriteChannelDesc *selection = gStuff->newSelection;
	ChannelReadPort selectionRead;
	ReadChannelDesc *composite;
	ReadChannelDesc *transparency;
	ReadChannelDesc *curChannel;
	
	/* Access the port procs. */
	
	if (!WarnChannelPortAvailable ())
		{
		gResult = errPlugInHostInsufficient;
		goto CleanUp;
		}
		
	gQueryForParameters = ReadScriptParams (globals);
	
	if ( gQueryForParameters ) doThis = DoUI (globals);
	
	if ( !doThis ) goto CleanUp; // user cancelled, etc.
	
	/* look in gStuff->supportedTreatments for support for this next thang */
		
	if (gCreate == iCreateMaskpath)
	{ // can't do that!
		Handle h = PIGetResource (StringResource, errCantCreatePath, &total);
		if (h != NULL) 
		{
			Str255 errString = "";
			// The handle, since it's a string, is automagically fetched as a
			// pascal string.  If we use PIHandle2PString, we'll get two
			// length bytes.  This way, the length byte (which is already byte
			// 0 of the handle) is preserved as the very first byte of the
			// string:
			PIHandle2CString(h, (char*)errString, 255); // handle, string, maxlength
			PIDisposeHandle(h);
			h = NULL; // reset
			gResult = PIReportError(errString);
		}
		else gStuff->treatment = KeyToEnum(EnumToKey(gCreate,typeMyCreate),typeMyPISel);
		// otherwise Pshop will catch it automatically
		goto CleanUp; // don't do any of this gunk
	}
	else
		gStuff->treatment = KeyToEnum(EnumToKey(gCreate,typeMyCreate),typeMyPISel);
		// Set the treatment then move on
		
	/* We will need a read port for the selection. */
	
	gResult = ReadFromWritePort(&selectionRead, selection->port);
	if (gResult != noErr) goto CleanUp;
	
	/* Figure out which composite data to use. */
	
	if (DoTarget)
	{
		composite = doc->targetCompositeChannels;
		transparency = doc->targetTransparency;
	
		if (composite == NULL)
		{
			composite = doc->mergedCompositeChannels;
			transparency = doc->mergedTransparency;
		}
	}
	else
	{
		composite = doc->mergedCompositeChannels;
		transparency = doc->mergedTransparency;
	}
			
	/* Allocate the buffers. */
	
	if (!WarnBufferProcsAvailable ())
		{
		gResult = +1;
		goto CleanUp;
		}
		
	#define kBufferSize kBlockRows * (long) kBlockCols
	
	gResult = AllocateBuffer (kBufferSize, &sBuffer);
	if (gResult != noErr) goto CleanUp;
	
	gResult = AllocateBuffer (kBufferSize, &dBuffer);
	if (gResult != noErr) goto CleanUp;
	
	gResult = AllocateBuffer (kBufferSize, &rBuffer);
	if (gResult != noErr) goto CleanUp;
	
	if (transparency != NULL)
		{
		gResult = AllocateBuffer (kBufferSize, &mBuffer);
		if (gResult != noErr) goto CleanUp;
		}
		
	/* Lock the buffers down. */
	
	sData = LockBuffer (sBuffer, false);
	dData = LockBuffer (dBuffer, false);
	rData = LockBuffer (rBuffer, false);
	if (mBuffer != 0) mData = LockBuffer (mBuffer, false);
	
	/* Set up the pixel memory descriptors. */
	
	sDesc.data = sData;
	sDesc.rowBits = kBlockCols * 8;
	sDesc.colBits = 8;
	sDesc.bitOffset = 0;
	sDesc.depth = 8;
	
	dDesc = sDesc;
	dDesc.data = dData;
	
	rDesc = sDesc;
	rDesc.data = rData;
	
	mDesc = sDesc;
	mDesc.data = mData;
	
	rData[0] = kInitRandom; // flag for uninitialized random buffer
	
	/* Count the channels to process. */
	
	if (doc->selection != NULL)
		total += AccountChannel (doc->selection, NULL, selection);
	
	curChannel = composite;
	while (curChannel != NULL)
	{
		if (DoTarget ? curChannel->target : curChannel->shown)
			total += AccountChannel (curChannel, transparency, selection);
									  
		curChannel = curChannel->next;
	}
		

	if (doc->targetLayerMask != NULL && 
	   (DoTarget ? doc->targetLayerMask->target : doc->targetLayerMask->shown))
			total += AccountChannel (doc->targetLayerMask, NULL, selection);
			
	curChannel = doc->alphaChannels;
	while (curChannel != NULL)
	{
		if (DoTarget ? curChannel->target : curChannel->shown)
			total += AccountChannel (curChannel, NULL, selection);
							  
		curChannel = curChannel->next;
	}

	
	/* Apply any existing selection. */
	
	if (doc->selection != NULL)
		{
		ApplyChannel (globals, doc->selection, &sDesc,
						  NULL, &mDesc,
						  selection, selectionRead, &dDesc,
						  &rDesc, &done, total);
		if (gResult != noErr) goto CleanUp;
		}
	
	/* Apply each of the channels. This isn't the most efficient
	approach since it reads the data back out of the selection
	repeatedly, but it provides a good work out for the code. */
	
	curChannel = composite;
	while (curChannel != NULL)
	{
		if (DoTarget ? curChannel->target : curChannel->shown)
		{
			ApplyChannel (globals, curChannel, &sDesc,
							  transparency, &mDesc,
							  selection, selectionRead, &dDesc,
							  &rDesc, &done, total);
			if (gResult != noErr) goto CleanUp;
		}
							  
		curChannel = curChannel->next;
	}
		
	/* Apply the layer mask. */
	if (doc->targetLayerMask != NULL &&
	   (DoTarget ? doc->targetLayerMask->target : doc->targetLayerMask->shown))
	{
		ApplyChannel (globals, doc->targetLayerMask, &sDesc,
						  NULL, &mDesc,
						  selection, selectionRead, &dDesc,
						  &rDesc, &done, total);
		if (gResult != noErr) goto CleanUp;
	}
		
	/* Process the alpha channels. */
	curChannel = doc->alphaChannels;
	while (curChannel != NULL)
	{
		if (DoTarget ? curChannel->target : curChannel->shown)
		{
			ApplyChannel (globals, curChannel, &sDesc,
							  NULL, &mDesc,
							  selection, selectionRead, &dDesc,
							  &rDesc, &done, total);
			if (gResult != noErr) goto CleanUp;
		}
							  
		curChannel = curChannel->next;
	}
	
	CleanUp:
	
	if (sData != NULL) UnlockBuffer (sBuffer);
	if (dData != NULL) UnlockBuffer (dBuffer);
	if (mData != NULL) UnlockBuffer (mBuffer);
	if (rData != NULL) UnlockBuffer (rBuffer);
	
	if (sBuffer != 0) FreeBuffer (sBuffer);
	if (dBuffer != 0) FreeBuffer (dBuffer);
	if (mBuffer != 0) FreeBuffer (mBuffer);	
	if (rBuffer != 0) FreeBuffer (rBuffer);
	
	WriteScriptParams(globals);

}
コード例 #22
0
ファイル: editview.cpp プロジェクト: Ukusbobra/open-watcom-v2
UINT CEditView::PrintInsideRect( CDC *pDC, RECT &rectLayout, UINT nIndexStart,
                                 UINT nIndexStop )
/************************************************/
{
    ASSERT( pDC != NULL );

    LPCTSTR lpszBuffer = LockBuffer();
    
    TEXTMETRIC tm;
    pDC->GetTextMetrics( &tm );

    int nWidth = rectLayout.right - rectLayout.left;
    int nCharHeight = tm.tmHeight + tm.tmExternalLeading;
    int y = rectLayout.top;
    int nCurrentIndex = nIndexStart;
    while( y + nCharHeight < rectLayout.bottom && nCurrentIndex <= nIndexStop ) {
        if( lpszBuffer[nCurrentIndex] == _T('\r') ) {
            nCurrentIndex++;
            if( lpszBuffer[nCurrentIndex] == _T('\n') ) {
                nCurrentIndex++;
            }
            y += nCharHeight;
            continue;
        } else if( lpszBuffer[nCurrentIndex] == _T('\0') ) {
            nCurrentIndex++;
            continue;
        }
        
        int nLength = 0;
        int nLineWidth = 0;
        int nLastSpace = 0;
        while( nLineWidth < nWidth && nCurrentIndex + nLength <= nIndexStop &&
               lpszBuffer[nCurrentIndex + nLength] != _T('\r') &&
               lpszBuffer[nCurrentIndex + nLength] != _T('\n') &&
               lpszBuffer[nCurrentIndex + nLength] != _T('\0') ) {
            nLength++;
            nLineWidth = pDC->GetTabbedTextExtent( lpszBuffer + nCurrentIndex, nLength,
                                                   1, &m_nTabStops ).cx;
            if( _istspace( lpszBuffer[nCurrentIndex + nLength] ) ) {
                nLastSpace = nLength;
            }
        }
        if( !(GetStyle() & ES_AUTOHSCROLL) && nLastSpace > 0 ) {
            nLength = nLastSpace + 1;
        } else if( nLineWidth >= nWidth ) {
            nLength--;
        }
        pDC->TabbedTextOut( rectLayout.left, y, lpszBuffer + nCurrentIndex, nLength, 1,
                            &m_nTabStops, rectLayout.left );
        nCurrentIndex += nLength;
        if( GetStyle() & ES_AUTOHSCROLL ) {
            while( lpszBuffer[nCurrentIndex] != _T('\r') &&
                   lpszBuffer[nCurrentIndex] != _T('\n') ) {
                nCurrentIndex++;
            }
        }
        if( lpszBuffer[nCurrentIndex] == _T('\r') ) {
            nCurrentIndex++;
            if( lpszBuffer[nCurrentIndex] == _T('\n') ) {
                nCurrentIndex++;
            }
        } else if( lpszBuffer[nCurrentIndex] == _T('\n') ) {
            nCurrentIndex++;
        }
        y += nCharHeight;
    }

    UnlockBuffer();
    return( nCurrentIndex );
}
コード例 #23
0
void FD3D12DynamicRHI::RHIUnlockStructuredBuffer(FStructuredBufferRHIParamRef StructuredBufferRHI)
{
	UnlockBuffer(nullptr, FD3D12DynamicRHI::ResourceCast(StructuredBufferRHI));
}
コード例 #24
0
ファイル: viewedit.cpp プロジェクト: rickerliang/OpenNT
UINT CEditView::PrintInsideRect(CDC* pDC, RECT& rectLayout,
	UINT nIndexStart, UINT nIndexStop)
	// worker function for laying out text in a rectangle.
{
	ASSERT_VALID(this);
	ASSERT_VALID(pDC);
	BOOL bWordWrap = (GetStyle() & ES_AUTOHSCROLL) == 0;

	// get buffer and real starting and ending postions
	UINT nLen = GetBufferLength();
	if (nIndexStart >= nLen)
		return nLen;
	LPCTSTR lpszText = LockBuffer();
	if (nIndexStop > nLen)
		nIndexStop = nLen;
	ASSERT(nIndexStart < nLen);

	// calculate text & tab metrics
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);
	int cyChar = tm.tmHeight + tm.tmExternalLeading;
#ifndef _MAC
	int nTabStop = m_nTabStops *
		pDC->GetTabbedTextExtent(_T("\t"), 1, 0, NULL).cx / 8 / 4;
#else
	int nTabStop = pDC->GetTextExtent(_T("\t"), 1).cx;
#endif
	int aCharWidths[256];
	pDC->GetCharWidth(0, 255, aCharWidths);

	int y = rectLayout.top;
	UINT cx = rectLayout.right - rectLayout.left;
	UINT nIndex = nIndexStart;

	VERIFY(pDC->SaveDC() != 0);
	BOOL bLayoutOnly = pDC->IntersectClipRect(&rectLayout) == NULLREGION;

	do
	{
		UINT nIndexEnd = EndOfLine(lpszText, nIndexStop, nIndex);
		if (nIndex == nIndexEnd)
		{
			y += cyChar;
		}
		else if (bWordWrap)
		{
			// word-wrap printing
			do
			{
				UINT nIndexWrap = ClipLine(pDC, aCharWidths,
					cx, nTabStop, lpszText, nIndex, nIndexEnd);
				UINT nIndexWord = nIndexWrap;
				if (nIndexWord != nIndexEnd)
				{
					while (nIndexWord > nIndex &&
					  !isspace(lpszText[nIndexWord]))
					{
						nIndexWord--;
					}
					if (nIndexWord == nIndex)
						nIndexWord = nIndexWrap;
				}
				CRect rect(rectLayout.left, y, rectLayout.right, y+cyChar);
				if (!bLayoutOnly && pDC->RectVisible(rect))
				{
#ifndef _MAC
					pDC->TabbedTextOut(rect.left, y,
						(LPCTSTR)(lpszText+nIndex), nIndexWord-nIndex, 1,
						&nTabStop, rect.left);
#else
					pDC->TextOut(rect.left, y,
						(LPCTSTR)(lpszText+nIndex), nIndexWord-nIndex);
#endif
				}
				y += cyChar;
				nIndex = nIndexWord;
				while (nIndex < nIndexEnd && isspace(lpszText[nIndex]))
					nIndex++;
			} while (nIndex < nIndexEnd && y+cyChar <= rectLayout.bottom);

			nIndexEnd = nIndex;
		}
		else
		{
			// non-word wrap printing (much easier and faster)
			CRect rect(rectLayout.left, y, rectLayout.right, y+cyChar);
			if (!bLayoutOnly && pDC->RectVisible(rect))
			{
				UINT nIndexClip = ClipLine(pDC, aCharWidths, cx, nTabStop,
					lpszText, nIndex, nIndexEnd);
				if (nIndexClip < nIndexEnd)
				{
					if (_istlead(*(lpszText+nIndexClip)))
						nIndexClip++;
					nIndexClip++;
				}
#ifndef _MAC
				pDC->TabbedTextOut(rect.left, y,
					(LPCTSTR)(lpszText+nIndex), nIndexClip-nIndex, 1,
					&nTabStop, rect.left);
#else
				pDC->TextOut(rect.left, y,
					(LPCTSTR)(lpszText+nIndex), nIndexClip-nIndex);
#endif
			}
			y += cyChar;
		}
		nIndex = NextLine(lpszText, nIndexStop, nIndexEnd);
	}
	while (nIndex < nIndexStop && y+cyChar <= rectLayout.bottom);

	pDC->RestoreDC(-1);
	UnlockBuffer();
	ASSERT_VALID(this);

	rectLayout.bottom = y;
	return nIndex;
}
コード例 #25
0
ファイル: viewedit.cpp プロジェクト: rickerliang/OpenNT
BOOL CEditView::FindText(LPCTSTR lpszFind, BOOL bNext, BOOL bCase)
{
	ASSERT_VALID(this);
	ASSERT(lpszFind != NULL);
	ASSERT(*lpszFind != '\0');

	UINT nLen = GetBufferLength();
	int nStartChar, nEndChar;
	GetEditCtrl().GetSel(nStartChar, nEndChar);
	UINT nStart = nStartChar;
	int iDir = bNext ? +1 : -1;

	// can't find a match before the first character
	if (nStart == 0 && iDir < 0)
		return FALSE;

	CWaitCursor wait;
	LPCTSTR lpszText = LockBuffer();

	if (iDir < 0)
	{
		// always go back one for search backwards
		nStart -= (lpszText+nStart) -
			_tcsdec(lpszText, lpszText+nStart);
	}
	else if (nStartChar != nEndChar && SameAsSelected(lpszFind, bCase))
	{
		// easy to go backward/forward with SBCS
		if (_istlead(lpszText[nStart]))
			nStart++;
		nStart += iDir;
	}

	// handle search with nStart past end of buffer
	size_t nLenFind = lstrlen(lpszFind);
	if (nStart+nLenFind-1 >= nLen)
	{
		if (iDir < 0 && nLen >= nLenFind)
		{
			if (_afxDBCS)
			{
				// walk back to previous character n times
				nStart = nLen;
				int n = nLenFind;
				while (n--)
				{
					nStart -= (lpszText+nStart) -
						_tcsdec(lpszText, lpszText+nStart);
				}
			}
			else
			{
				// single-byte character set is easy and fast
				nStart = nLen - nLenFind;
			}
			ASSERT(nStart+nLenFind-1 <= nLen);
		}
		else
		{
			UnlockBuffer();
			return FALSE;
		}
	}

	// start the search at nStart
	LPCTSTR lpsz = lpszText + nStart;
	AFX_COMPARE_PROC pfnCompare = bCase ? lstrcmp : lstrcmpi;

	if (_afxDBCS)
	{
		// double-byte string search
		LPCTSTR lpszStop;
		if (iDir > 0)
		{
			// start at current and find _first_ occurrance
			lpszStop = lpszText + nLen - nLenFind + 1;
		}
		else
		{
			// start at top and find _last_ occurrance
			lpszStop = lpsz;
			lpsz = lpszText;
		}

		LPCTSTR lpszFound = NULL;
		while (lpsz <= lpszStop)
		{
			if (!bCase || (*lpsz == *lpszFind &&
				(!_istlead(*lpsz) || lpsz[1] == lpszFind[1])))
			{
				LPTSTR lpch = (LPTSTR)(lpsz + nLenFind);
				TCHAR chSave = *lpch;
				*lpch = '\0';
				int nResult = (*pfnCompare)(lpsz, lpszFind);
				*lpch = chSave;
				if (nResult == 0)
				{
					lpszFound = lpsz;
					if (iDir > 0)
						break;
				}
			}
			lpsz = _tcsinc(lpsz);
		}
		UnlockBuffer();

		if (lpszFound != NULL)
		{
			int n = (int)(lpszFound - lpszText);
			GetEditCtrl().SetSel(n, n+nLenFind);
			return TRUE;
		}
	}
	else
	{
		// single-byte string search
		UINT nCompare;
		if (iDir < 0)
			nCompare = (UINT)(lpsz - lpszText) + 1;
		else
			nCompare = nLen - (UINT)(lpsz - lpszText) - nLenFind + 1;

		while (nCompare > 0)
		{
			ASSERT(lpsz >= lpszText);
			ASSERT(lpsz+nLenFind-1 <= lpszText+nLen-1);

			LPSTR lpch = (LPSTR)(lpsz + nLenFind);
			char chSave = *lpch;
			*lpch = '\0';
			int nResult = (*pfnCompare)(lpsz, lpszFind);
			*lpch = chSave;
			if (nResult == 0)
			{
				UnlockBuffer();
				int n = (int)(lpsz - lpszText);
				GetEditCtrl().SetSel(n, n+nLenFind);
				ASSERT_VALID(this);
				return TRUE;
			}

			// restore character at end of search
			*lpch = chSave;

			// move on to next substring
			nCompare--;
			lpsz += iDir;
		}
		UnlockBuffer();
	}

	ASSERT_VALID(this);
	return FALSE;
}
コード例 #26
0
ファイル: modereq.cpp プロジェクト: dcti/dnetc-client-base
int ModeReqRun(Client *client)
{
  int retval = 0;

  /* This exits if we don't see a CPU we want,
     Also saves us from floating point exceptions on GPU clients 
  */
  if ((modereq.reqbits & MODEREQ_NEEDS_CPU_MASK) != 0)
  {
    if (GetNumberOfDetectedProcessors() == 0)  // -1 is OK when OS doesn't support detection
      return 0;
  }

  if (++modereq.isrunning == 1)
  {
    int restart = ((modereq.reqbits & MODEREQ_RESTART) != 0);
    modereq.reqbits &= ~MODEREQ_RESTART;

    while ((modereq.reqbits & MODEREQ_ALL)!=0)
    {
      unsigned int bits = modereq.reqbits;
      if ((bits & (MODEREQ_BENCHMARK |
                   MODEREQ_BENCHMARK_QUICK |
                   MODEREQ_BENCHMARK_ALLCORE )) != 0)
      {
        do
        {
          unsigned int contest, benchsecs = 16;
          unsigned long sel_contests = modereq.bench_projbits;
          modereq.bench_projbits = 0;

          if ((bits & (MODEREQ_BENCHMARK_QUICK))!=0)
            benchsecs = 8;
          for (contest = 0; contest < CONTEST_COUNT; contest++)
          {
            if (CheckExitRequestTriggerNoIO())
              break;
            if (sel_contests == 0 /*none set==all set*/
                || (sel_contests & (1L<<contest)) != 0)
            {
              if ((bits & (MODEREQ_BENCHMARK_ALLCORE))!=0)
                if(client->corenumtotestbench < 0)
                  selcoreBenchmark( client, contest, benchsecs, -1 );
                else
                  selcoreBenchmark( client, contest, benchsecs, client->corenumtotestbench);
              else
                TBenchmark( client, contest, benchsecs, 0, NULL, NULL );
            }
          }
          Log("Compare and share your rates in the speeds database at\n"
              "http://www.distributed.net/speed/\n"
              "(benchmark rates are for a single processor core)\n");
        } while (!CheckExitRequestTriggerNoIO() && modereq.bench_projbits);
        retval |= (bits & (MODEREQ_BENCHMARK_QUICK | MODEREQ_BENCHMARK |
                           MODEREQ_BENCHMARK_ALLCORE));
        modereq.reqbits &= ~(MODEREQ_BENCHMARK_QUICK | MODEREQ_BENCHMARK |
                             MODEREQ_BENCHMARK_ALLCORE);
      }
      if ((bits & MODEREQ_CMDLINE_HELP) != 0)
      {
        DisplayHelp(modereq.helpoption);
        modereq.helpoption = (const char *)0;
        modereq.reqbits &= ~(MODEREQ_CMDLINE_HELP);
        retval |= (MODEREQ_CMDLINE_HELP);
      }
      if ((bits & (MODEREQ_CONFIG | MODEREQ_CONFRESTART)) != 0)
      {
        /* cmdline_config is set if there is an explicit --config on the cmdline */
        /* Configure() returns <0=error,0=exit+nosave,>0=exit+save */
        Configure(client,(!(!modereq.cmdline_config)) /* nottycheck */);
        /* it used to be such that restart would only be posted on an exit+save */
        /* but now we restart for other retvals too, otherwise the GUI windows */
        /* end up with half-assed content */
        if ((bits & MODEREQ_CONFRESTART) != 0)
          restart = 1;
        modereq.cmdline_config = 0;
        modereq.reqbits &= ~(MODEREQ_CONFIG | MODEREQ_CONFRESTART);
        retval |= (bits & (MODEREQ_CONFIG | MODEREQ_CONFRESTART));
      }
      if ((bits & (MODEREQ_FETCH | MODEREQ_FLUSH)) != 0)
      {
        if (client)
        {
          int domode = 0;
          int interactive = ((bits & MODEREQ_FQUIET) == 0);
          domode  = ((bits & MODEREQ_FETCH) ? BUFFERUPDATE_FETCH : 0);
          domode |= ((bits & MODEREQ_FLUSH) ? BUFFERUPDATE_FLUSH : 0);
          TRACE_BUFFUPD((0, "BufferUpdate: reason = ModeReqRun\n"));
          domode = BufferUpdate( client, domode, interactive );
          if (domode & BUFFERUPDATE_FETCH)
            retval |= MODEREQ_FETCH;
          if (domode & BUFFERUPDATE_FLUSH)
            retval |= MODEREQ_FLUSH;
          if (domode!=0 && (bits & MODEREQ_FQUIET) != 0)
            retval |= MODEREQ_FQUIET;
        }
        modereq.reqbits &= ~(MODEREQ_FETCH | MODEREQ_FLUSH | MODEREQ_FQUIET);
      }
      if ((bits & MODEREQ_IDENT) != 0)
      {
        CliIdentifyModules();
        modereq.reqbits &= ~(MODEREQ_IDENT);
        retval |= (MODEREQ_IDENT);
      }
      if ((bits & MODEREQ_UNLOCK) != 0)
      {
        if (modereq.filetounlock)
        {
          UnlockBuffer(modereq.filetounlock);
          modereq.filetounlock = (const char *)0;
        }
        modereq.reqbits &= ~(MODEREQ_UNLOCK);
        retval |= (MODEREQ_UNLOCK);
      }
      if ((bits & MODEREQ_IMPORT) != 0)
      {
        if (modereq.filetoimport && client)
        {
          BufferImportFileRecords(client, modereq.filetoimport, 1 /* interactive */);
          modereq.filetoimport = (const char *)0;
          retval |= (MODEREQ_IMPORT);
        }
        modereq.reqbits &= ~(MODEREQ_IMPORT);
      }
      if ((bits & MODEREQ_CPUINFO) != 0)
      {
        DisplayProcessorInformation();
        modereq.reqbits &= ~(MODEREQ_CPUINFO);
        retval |= (MODEREQ_CPUINFO);
      }
      if ((bits & (MODEREQ_TEST | MODEREQ_TEST_ALLCORE)) != 0)
      {

        int testfailed = 0;
        do
        {
          unsigned int contest;
          unsigned long sel_contests = modereq.test_projbits;
          modereq.test_projbits = 0;

          for (contest = 0; !testfailed && contest < CONTEST_COUNT; contest++)
          {
            if (CheckExitRequestTriggerNoIO())
            {
              testfailed = 1;
              break;
            }
            if (sel_contests == 0 /*none set==all set*/
                || (sel_contests & (1L<<contest)) != 0)
            {
              if ((bits & (MODEREQ_TEST_ALLCORE)) != 0)
              {
                if (client->corenumtotestbench < 0)
                {
                  if (selcoreSelfTest( client, contest, -1 ) < 0)
                    testfailed = 1;
                }
                else
                {
                  if (selcoreSelfTest( client, contest, client->corenumtotestbench ) < 0)
                    testfailed = 1;
                }
              }
              else if ( SelfTest( client, contest ) < 0 )
                testfailed = 1;
            }
          }
        } while (!testfailed && modereq.test_projbits);
        retval |= (MODEREQ_TEST|MODEREQ_TEST_ALLCORE);
        modereq.reqbits &= ~(MODEREQ_TEST|MODEREQ_TEST_ALLCORE);
      }
      if ((bits & (MODEREQ_STRESS | MODEREQ_STRESS_ALLCORE)) != 0)
      {

        int testfailed = 0;
        do
        {
          unsigned int contest;
          unsigned long sel_contests = modereq.stress_projbits;
          modereq.stress_projbits = 0;

          for (contest = 0; !testfailed && contest < CONTEST_COUNT; contest++)
          {
            if (CheckExitRequestTriggerNoIO())
            {
              testfailed = 1;
              break;
            }
            if (sel_contests == 0 /*none set==all set*/
                || (sel_contests & (1L<<contest)) != 0)
            {
              if ((bits & (MODEREQ_STRESS_ALLCORE)) != 0)
              {
                if (client->corenumtotestbench < 0)
                {
                  if (selcoreStressTest( client, contest, -1 ) < 0)
                    testfailed = 1;
                }
                else
                {
                  if (selcoreStressTest( client, contest, client->corenumtotestbench ) < 0)
                    testfailed = 1;
                }
              }
              else if ( StressTest( client, contest ) < 0 )
                testfailed = 1;
            }
          }
        } while (!testfailed && modereq.stress_projbits);
        retval |= (MODEREQ_STRESS|MODEREQ_STRESS_ALLCORE);
        modereq.reqbits &= ~(MODEREQ_STRESS|MODEREQ_STRESS_ALLCORE);
      }
      if ((bits & MODEREQ_VERSION) != 0)
      {
        /* the requested information already has been printed */
        modereq.reqbits &= ~(MODEREQ_VERSION);
        retval |= (MODEREQ_VERSION);
      }
      if (CheckExitRequestTriggerNoIO())
      {
        restart = 0;
        break;
      }
    } //end while

    if (restart)
      RaiseRestartRequestTrigger();
  } //if (++isrunning == 1)

  modereq.isrunning--;
  return retval;
}
コード例 #27
0
ファイル: Main.cpp プロジェクト: Venomic/CPURasterizer
	void Main(PlatformAPI *api)
	{
		// Application settings
		Application app;
		app.api = api;
		SetApplicationTitle(api, "CPU Rasterizer");

		// Mouse setup
		app.mouse_exclusive = true;
		app.mouse_sensitivity = 0.8f * 0.0022f; // Sensitivity * source engine scale

		// Setup player properties
		app.player_yaw = 0.0f;
		app.player_pitch = 0.0f;
		app.player_flags = 0;

		// Setup camera
		app.camera.pos = float3(0.0f, 0.0f, -8.0f);
		app.camera.fov = Tau * 0.25f;

		// Setup scene
		CreateTestScene(app.scene);
		
		// Set events
		SetKeyboardEvent(api, &app, OnKeyboardEvent);
		SetMouseEvent(api, &app, OnMouseEvent);
		SetMouseCaptureMode(api, MouseCaptureModeExclusive);

		// Create software renderer
		app.renderer = CreateSoftwareRenderer(api, 1280, 720, false);

		// Load default font.
		app.font = CreateFontFromFile("C:\\Windows\\Fonts\\calibrib.ttf", 18.0f);

		// Initialize the rasterizer data
		{
			app.frame_info = NULL;

			// Default framebuffer
			app.framebuffer.width = 1280;
			app.framebuffer.height = 720;
			U32 size = GetRequiredMemoryAmount(app.framebuffer, true, true);
			Initialize(app.framebuffer, malloc(size), true, true);

			// Threads
			CreateRasterizerThreads(app);
		}

		// Frame update loop
		U64 frame_start_time = GetTime(api);
		app.frame_delta = 0.0001f;
		while (Update(api))
		{
			// Apply player rotation to camera.
			app.camera.axis[0] = float3(1.0f, 0.0f, 0.0f);
			app.camera.axis[1] = float3(0.0f, 1.0f, 0.0f);
			app.camera.axis[2] = float3(0.0f, 0.0f, 1.0f);
			Rotate(app.camera.axis[0], float3(1.0f, 0.0f, 0.0f), app.player_pitch);
			Rotate(app.camera.axis[1], float3(1.0f, 0.0f, 0.0f), app.player_pitch);
			Rotate(app.camera.axis[2], float3(1.0f, 0.0f, 0.0f), app.player_pitch);
			Rotate(app.camera.axis[0], float3(0.0f, 1.0f, 0.0f), app.player_yaw);
			Rotate(app.camera.axis[1], float3(0.0f, 1.0f, 0.0f), app.player_yaw);
			Rotate(app.camera.axis[2], float3(0.0f, 1.0f, 0.0f), app.player_yaw);

			// Apply player movement to camera
			float3 player_velocity = 0.0f;
			if (app.player_flags & PlayerFlagMoveForward)
				player_velocity += app.camera.axis[2];
			if (app.player_flags & PlayerFlagMoveBackward)
				player_velocity -= app.camera.axis[2];
			if (app.player_flags & PlayerFlagMoveRight)
				player_velocity -= app.camera.axis[0];
			if (app.player_flags & PlayerFlagMoveLeft)
				player_velocity += app.camera.axis[0];
			if (Dot(player_velocity, player_velocity) != 0.0f)
				Normalize(player_velocity);
			player_velocity *= 5.0f * app.frame_delta;
			app.camera.pos += player_velocity;

			// Render the frame
			LockBufferInfo frame_info;
			LockBuffer(app.renderer, frame_info);
			RenderFrame(app, frame_info);
			PrintDebugStats(app, frame_info);
			UnlockBuffer(app.renderer);

			// Calculate frame delta time
			U64 time = GetTime(api);
			U64 delta = time - frame_start_time;
			frame_start_time = time;
			app.frame_delta = float(delta) / float(U64(1) << U64(32));
		}
	}
コード例 #28
0
ファイル: DrawDevice.cpp プロジェクト: n-n-n/ImageVideo
 ~VideoBufferLock()
 {
     UnlockBuffer();
     SafeRelease(&m_pBuffer);
     SafeRelease(&m_p2DBuffer);
 }