Example #1
0
bool Parser::SkipWhitespace() {
	char c=CheckChar();
	bool white=false;
	while(isspace(c)) {
		GetChar();
		c=CheckChar();
		white=true;
	}
	return white;
}
Example #2
0
bool Tokenizer::GetToken(std::string& _buf) {
	SkipWhitespace();

	int pos=0;
	char c=CheckChar();
	while(c!=' ' && c!='\n' && c!='\t' && c!='\v' && c!='\r' && c!='\f' && !feof((FILE*)File)) {
		_buf.append(1, GetChar());
		c=CheckChar();
	}
	return !feof((FILE*)File);
}
Example #3
0
bool Parser::GetToken(char *str) {
	SkipWhitespace();

	int pos=0;
	char c=CheckChar();
	while(c!=' ' && c!='\n' && c!='\t' && c!='\r' && !feof((FILE*)File)) {
		str[pos++]=GetChar();
		c=CheckChar();
	}
	str[pos]='\0';
	return true;
}
Example #4
0
void SMaskEdit::MaskReplaceSel(LPCTSTR lpszNewText)
{
    ASSERT(CanUseMask());

    if (m_nStartChar != m_nEndChar)
        MaskDeleteSel();

    int x = m_nStartChar, nNewTextLen = (int)_tcslen(lpszNewText);
    int nWindowTextLen = m_strWindowText.GetLength();

    if (x >= nWindowTextLen)
        return;

    for (int i = 0; i < nNewTextLen; ++i)
    {
        TCHAR ch = lpszNewText[i];

        if (ch == m_chPrompt || CheckChar(ch, x))
        {
            InsertCharAt(x, ch);
            x++;

            while (x < nWindowTextLen && !IsPromptPos(x))
                x++;

            if (x >= m_strWindowText.GetLength())
                break;
        }
    }
    CorrectPosition(x);
    m_nStartChar = m_nEndChar = x;
}
Example #5
0
int Parser::GetInt() {
	SkipWhitespace();
	int pos=0;
	char temp[256];

	char c=CheckChar();
	if(c=='-') {
		temp[pos++]=GetChar();
		c=CheckChar();
	}
	if(!isdigit(c)) {
		printf("ERROR: Parser::GetInt()- Expecting int on line %d of '%s'\n",LineNum,FileName);
		return 0;
	}
	temp[pos++]=GetChar();

	while(isdigit(c=CheckChar())) temp[pos++]=GetChar();

	temp[pos++]='\0';
	return atoi(temp);
}
Example #6
0
bool
Tokenizer::ReadChar(bool (*aClassifier)(const char aChar), char* aValue)
{
  MOZ_RELEASE_ASSERT(aValue);

  if (!CheckChar(aClassifier)) {
    return false;
  }

  *aValue = *mRollback;
  return true;
}
Example #7
0
string StateString::decode(StreamManip &manip) {
    if(manip.Guess("x", 1)) {
        manip.FreezePos();
        if(!manip.GuessInChars("1234567890abcdefABCDEF", 22))
            throw(ErrInf("Escape symbol - without following digits", manip));
        while(manip.GuessInChars("1234567890abcdefABCDEF", 22))
            ;
        return CheckChar(manip, manip.UnfreezeToL(16));
    }
    if(manip.GuessInChars("01234567", 8)) {
        manip.unget();
        int OK;
        manip.FreezePos();
        if(manip.GuessInChars("01234567", 8))
            if(manip.GuessInChars("01234567", 8))
                OK = 1;
        return CheckChar(manip, manip.UnfreezeToL(8));
    }
    if(manip.GuessInChars("\'\"\\", 3))
        return string(1, (char)manip.LastChar());
    //		if (manip.GuessInChars("ntrfbav",7)) return string("\\").append(1,(char)manip.LastChar());
    if(manip.GuessInChars("n", 1))
        return string(1, '\n');
    if(manip.GuessInChars("t", 1))
        return string(1, '\t');
    if(manip.GuessInChars("r", 1))
        return string(1, '\r');
    if(manip.GuessInChars("f", 1))
        return string(1, '\f');
    if(manip.GuessInChars("b", 1))
        return string(1, '\b');
    if(manip.GuessInChars("a", 1))
        return string(1, '\a');
    if(manip.GuessInChars("v", 1))
        return string(1, '\v');
    if(manip.GuessInChars("\n", 1))
        return string("");
    return string(1, (char)manip.get());
}
Example #8
0
/////////////////////////////////////////////////////////////////////////////
// CMyDateEdit message handlers
void CMyDateEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CString str;
	GetWindowText(str);
	for (int i = 0; i<str.GetLength() && i<m_str.GetLength();i++)
		m_str.SetAt(i, str.GetAt(i));
	if(!m_bMaskKeyInProgress)
		if(!CheckChar(nChar)) return;
		if(m_bUseMask)  //要使用掩码
		{
			if(isdigit(nChar))  //是可打印字符
			{
				int startPos,endPos;
				GetSel(startPos,endPos);
				SetSel(startPos,endPos+1);
				if(m_strMask.GetAt(startPos)=='-'||m_strMask.GetAt(startPos)==':'||m_strMask.GetAt(startPos)==' ')
				{
					SetSel(startPos+1,startPos+1);
					SendChar(nChar);
					return;
				}
			}
			else if(nChar==VK_BACK)
			{
				int startPos,endPos;
				GetSel(startPos,endPos);
				if((startPos==endPos) && (startPos>=1) && (startPos<=m_str.GetLength()))
				{
					char c;
					c=m_strMask.GetAt(startPos-1);
					if(c=='-'||c==':'||c==' ') 
					{					
						SetSel(startPos-1,startPos-1);
						return;
					}
					////回退光标
					SetSel(startPos-1,startPos-1);
					SendChar(c);
						//再次退回
					SendMessage(WM_KEYDOWN,VK_LEFT,0);
				}
				else   //越界或者存在选择区域
					MessageBeep((UINT)-1);
				return;
			}

		}
	CEdit::OnChar(nChar, nRepCnt, nFlags);
}
Example #9
0
int Tokenizer::GetInt() {
	SkipWhitespace();
	int pos=0;
	char temp[256];

	// Get first character ('-' or digit)
	char c=CheckChar();
	if(c=='-') {
		temp[pos++]=GetChar();
		c=CheckChar();
	}
	if(!isdigit(c)) {
		printf("ERROR: Tokenizer::GetInt()- Expecting int on line %d of '%s'\n",LineNum, filename);
		return 0;
	}
	temp[pos++]=GetChar();

	// Get integer potion
	while(isdigit(c=CheckChar())) temp[pos++]=GetChar();

	// Finish
	temp[pos++]='\0';
	return atoi(temp);
}
Example #10
0
float Tokenizer::GetFloat() {
	SkipWhitespace();
	int pos=0;
	char temp[256];

	// Get first character ('-' or digit)
	char c=CheckChar();
	if(c=='-') {
		temp[pos++]=GetChar();
		c=CheckChar();
	}
	if(!isdigit(c)) {
		printf("ERROR: Tokenizer::GetFloat()- Expecting float on line %d of '%s' '%c'\n",LineNum,FileName,c);
		return 0.0f;
	}
	temp[pos++]=GetChar();

	// Get integer potion of mantissa
	while(isdigit(c=CheckChar())) temp[pos++]=GetChar();

	// Get fraction component
	if(c=='.') {
		temp[pos++]=GetChar();
		while(isdigit(c=CheckChar())) temp[pos++]=GetChar();
	}

	// Get exponent
	if(c=='e' || c=='E') {
		temp[pos++]=GetChar();
		c=CheckChar();
		if(c=='+' || c=='-') {
			temp[pos++]=GetChar();
			c=CheckChar();
		}
		if(!isdigit(c)) {
			printf("ERROR: Tokenizer::GetFloat()- Poorly formatted float exponent on line %d of '%s'\n",LineNum,FileName);
			return 0.0f;
		}
		while(isdigit(c=CheckChar())) temp[pos++]=GetChar();
	}

	// Finish
	temp[pos++]='\0';
	return float(atof(temp));
}
Example #11
0
float Tokenizer::GetFloat() {
	SkipWhitespace();
	int pos=0;
	char temp[256];

	// Get first character ('-' or digit)
	char c=CheckChar();
	if(c=='-') {
		temp[pos++]=GetChar();
		c=CheckChar();
	}
	if(!isdigit(c)) {
		std::cout << "ERROR: Tokenizer::GetFloat()- Expecting float on line " << LineNum << " of '" << filename << "' '" << c << "'" << std::endl;
		return 0.0f;
	}
	temp[pos++]=GetChar();

	// Get integer potion of mantissa
	while(isdigit(c=CheckChar())) temp[pos++]=GetChar();

	// Get fraction component
	if(c=='.') {
		temp[pos++]=GetChar();
		while(isdigit(c=CheckChar())) temp[pos++]=GetChar();
	}

	// Get exponent
	if(c=='e' || c=='E') {
		temp[pos++]=GetChar();
		c=CheckChar();
		if(c=='+' || c=='-') {
			temp[pos++]=GetChar();
			c=CheckChar();
		}
		if(!isdigit(c)) {
			std::cout << "ERROR: Tokenizer::GetFloat()- Poorly formatted float exponent on line " << LineNum << " of '" << filename << "'\n" << std::endl;
			return 0.0f;
		}
		while(isdigit(c=CheckChar())) temp[pos++]=GetChar();
	}

	// Finish
	temp[pos++]='\0';
	return float(atof(temp));
}
Example #12
0
void SMaskEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    if (!CanUseMask())
    {
        __super::OnChar(nChar, nRepCnt, nFlags);
        return;
    }

    switch (nChar)
    {
    case VK_SPACE:
    case VK_BACK:
        return; // handled in WM_KEYDOWN
    }

    GetMaskState();

    if (!PosInRange(m_nStartChar) || !IsPromptPos(m_nStartChar))
    {
        NotifyPosNotInRange();
        return;
    }

    TCHAR ch = (TCHAR)nChar;

    if (!CheckChar(ch, m_nStartChar))
    {
        NotifyInvalidCharacter(ch, m_strMask[m_nStartChar]);
        return;
    }

    if (IsPrintChar(ch))
    {
        ProcessChar(ch);
        SetMaskState();
    }
    else
    {
        if (nChar != 127)
            __super::OnChar(nChar, nRepCnt, nFlags);
    }
}
Example #13
0
bool GetAssignment(std::string line)
{
	if (line.find(";") != string::npos)
	{
		//check for characters after the ;
		std::string lineS = line.substr(line.find_first_of(";"), line.length() - line.find_first_of("="));
		for (int i = 0; i < lineS.length(); i++)
		{
			if (CheckChar(lineS[i]))
			{
				error = "charaters after semicolon!";
				return false;
			}
		}
		line = line.substr(0, line.find_first_of(";"));
		//
		lineS = line.substr(0, line.find_first_of("="));
		//check if line contains white space
		if (lineS.find(" ") != string::npos)
		{
			int indexOfWhiteSpace = lineS.find_first_of(" ");
			if (indexOfWhiteSpace == lineS.length() - 1)
				lineS = lineS.substr(0, indexOfWhiteSpace);
			else if (indexOfWhiteSpace == 0)
				lineS = lineS.substr(1);
			else 
			{
				error = "incorrent space in id";
				return false;
			}
		}
		if (!CheckID(lineS))
			return false;
		if (!GetExpression(line.substr(line.find_first_of("=") + 1, (line.length() - line.find_first_of("=") - 1))))
			return false;		
		return true;
	}
	error = "No semicolon in the assignment!";
	return false;
}
Example #14
0
bool CheckID(std::string line)
{
	for (int i = 0; i < line.length(); i++)
	{
		if (i == 0)
		{
			if (!CheckCharOnly(line[i]))
			{
				error = "incorrect character at the begginging of an ID";
				return false;
			}
		}
		else
		{
			if (!CheckChar(line[i]))
			{
				error = "incorrect character in ID";
				return false;
			}
		}
	}
	return true;
}
char CheckChar(FILE * pfSubSourceFile,char ** ppcSubCurrent,char cSubTemp,char fcSubBlank)//检查字符功能,具有合并空格,去除回车
{
	if(cSubTemp==EOF) 
	{
		return 0x20;
	}//判断是否到文件末尾,结束返回空格

	if(cSubTemp!=10&&isspace(cSubTemp))//判断是否为空格,合并多个空格为一个
	{
		if(fcSubBlank=='N') 
		{
			**ppcSubCurrent=0x20;
			(*ppcSubCurrent)++;
			fcSubBlank='Y';//修改空格标志位
		}
		cSubTemp=fgetc(pfSubSourceFile);//空格的话再读入一个字符
		cSubTemp=CheckChar(pfSubSourceFile,ppcSubCurrent,cSubTemp,fcSubBlank);//递归检查
	}

	if(cSubTemp=='/')//判断注视
	{
		char cTemp;//临时变量,用于检查下一个是否为'/'

		cTemp=fgetc(pfSubSourceFile);//再读入一个字符

		if(cTemp=='/') //若为注视一直读入知道换行符,否则退回刚才读入的字符
		{
			while(fgetc(pfSubSourceFile)!='\n');
			//遇到注视,在注视结尾返回空格
			cSubTemp='\n';
		}
		else ungetc(cTemp,pfSubSourceFile);//退回刚才读入的字符

	}

	return cSubTemp;//返回字符
}
Example #16
0
HRESULT cFont::GetTextExtent(const char* strText, SIZE* pSize)
{
    if (NULL == strText || NULL == pSize)
        return E_FAIL;

    FLOAT fRowWidth = 0.0f;
    FLOAT fRowHeight = (m_fTexCoords[0][3] - m_fTexCoords[0][1])*dwHeight;
    FLOAT fWidth = 0.0f;
    FLOAT fHeight = fRowHeight;

    while (*strText)
    {
        unsigned char c = *strText++;

        if (c == '\n')
        {
            fRowWidth = 0.0f;
            fHeight += fRowHeight;
        }

        if (CheckChar(c))
            continue;

        FLOAT tx1 = m_fTexCoords[c - 32][0];
        FLOAT tx2 = m_fTexCoords[c - 32][2];

        fRowWidth += (tx2 - tx1)*dwWidth;

        if (fRowWidth > fWidth)
            fWidth = fRowWidth;
    }

    pSize->cx = (int)fWidth;
    pSize->cy = (int)fHeight;

    return S_OK;
}
Example #17
0
float Parser::GetFloat() {
	SkipWhitespace();
	int pos=0;
	char temp[256];

	char c=CheckChar();
	if(c=='-') {
		temp[pos++]=GetChar();
		c=CheckChar();
	}
	if(!isdigit(c)) {
		printf("ERROR: Parser::GetFloat()- Expecting float on line %d of '%s' '%c'\n",LineNum,FileName,c);
		return 0.0f;
	}
	temp[pos++]=GetChar();

	while(isdigit(c=CheckChar())) temp[pos++]=GetChar();

	if(c=='.') {
		temp[pos++]=GetChar();
		while(isdigit(c=CheckChar())) temp[pos++]=GetChar();
	}

	if(c=='e' || c=='E') {
		temp[pos++]=GetChar();
		c=CheckChar();
		if(c=='+' || c=='-') {
			temp[pos++]=GetChar();
			c=CheckChar();
		}
		if(!isdigit(c)) {
			printf("ERROR: Parser::GetFloat()- Poorly formatted float exponent on line %d of '%s'\n",LineNum,FileName);
			return 0.0f;
		}
		while(isdigit(c=CheckChar())) temp[pos++]=GetChar();
	}
	temp[pos++]='\0';
	return float(atof(temp));
}
Example #18
0
void CBCGMaskEdit::OnCharPrintchar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	ASSERT(m_strMask.IsEmpty() == m_strInputTemplate.IsEmpty());
	ASSERT(m_strMask.GetLength() == m_strInputTemplate.GetLength());

	ASSERT(_istprint((BCG_TCHAR) nChar) != FALSE);

	// -----------------------------------------------
	// Processing ES_UPPERCASE and ES_LOWERCASE styles
	// -----------------------------------------------
	DWORD dwStyle = GetStyle ();
	if (dwStyle & ES_UPPERCASE)
	{
		nChar = _totupper((BCG_TCHAR) nChar);
	}
	else if (dwStyle & ES_LOWERCASE)
	{
		nChar = _totlower((BCG_TCHAR) nChar);
	}
	
	int nStartPos, nEndPos;

	CEdit::GetSel(nStartPos, nEndPos);

	ASSERT(nStartPos>=0);
	ASSERT(nEndPos>=0);
	ASSERT(nEndPos>=nStartPos);

	// -----------------
	// Calc group bounds
	// -----------------
	int nGroupStart, nGroupEnd;
	GetGroupBounds(nGroupStart, nGroupEnd, nStartPos);

	// ------------
	// Out of range
	// ------------
	if ((nStartPos<0) && (nEndPos > m_str.GetLength()) ||
		(nStartPos < nGroupStart) || (nStartPos > nGroupEnd) ||
		(nEndPos < nGroupStart) || (nEndPos > nGroupEnd))
	{
		MessageBeep((UINT)-1);
		CEdit::SetSel(nGroupStart, nGroupEnd);
		return;
	}

	TCHAR chChar = (TCHAR) nChar;

	// -----------------
	// No selected chars
	// -----------------
	if (nStartPos == nEndPos)
	{
		// Use m_strMask
		if (!m_strMask.IsEmpty())
		{
			// ----------------------------------------------
			// Automaticaly move the cursor to the next group
			// ----------------------------------------------
			if (nEndPos==nGroupEnd || // at the end of group
				nStartPos < nGroupStart || nStartPos > nGroupEnd) // not in the middle of a group
			{
				// no space for new char
				if (nEndPos >= m_str.GetLength()-1)
				{
					MessageBeep((UINT)-1);
					return;
				}

				// can search next group
				else if (nEndPos < m_str.GetLength()-1)
				{
					GetGroupBounds(nGroupStart, nGroupEnd, nEndPos+1, TRUE);
				}

				// if next group was found
				if ((nGroupStart != -1) && (nGroupStart > nEndPos))
				{
					CEdit::SetSel(nGroupStart, nGroupStart);
					nStartPos = nGroupStart;
					nEndPos = nGroupStart;
				}

				// no more groups
				else
				{
					MessageBeep((UINT)-1);
					return;
				}
			}

			// ----------------------
			// Check char in position
			// ----------------------
			if (!CheckChar(chChar, nStartPos)) 
			{
				MessageBeep((UINT)-1);
				return;
			}

			// ---------------------------------
			// Replace char in Editbox and m_str
			// ---------------------------------
			CEdit::SetSel(nStartPos, nEndPos+1);
			CEdit::ReplaceSel(CString(chChar), TRUE);
			m_str.SetAt(nEndPos, chChar);          
			CEdit::SetSel(nEndPos+1, nEndPos+1);

			// ----------------------------------------------
			// Automaticaly move the cursor to the next group
			// ----------------------------------------------
			CEdit::GetSel(nStartPos, nEndPos);
			if (nEndPos==nGroupEnd) // at the end of group
			{
				// can search next group
				if (nEndPos < m_str.GetLength()-1)
				{
					GetGroupBounds(nGroupStart, nGroupEnd, nEndPos+1, TRUE);
				}

				// if next group was found
				if ((nGroupStart != -1) && (nGroupStart > nEndPos))
				{
					CEdit::SetSel(nGroupStart, nGroupStart);
					nStartPos = nGroupStart;
					nEndPos = nGroupStart;
				}
			}
		}

		// Don't use m_strMask
		else
		{
			// ----------------------
			// Check char in position
			// ----------------------
			if (!CheckChar(chChar, nStartPos)) 
			{
				MessageBeep((UINT)-1);
				return;
			}

			// Don't use m_chMask
			CEdit::OnChar(nChar, nRepCnt, nFlags);
		}
	}

	// -------------------------------
	// Have one or more chars selected
	// -------------------------------
	else
	{
		// ----------------------
		// Check char in position
		// ----------------------
		if (!CheckChar(chChar, nStartPos)) 
		{
			MessageBeep((UINT)-1);
			return;
		}

		// ----------------------------------
		// Replace chars in Editbox and m_str
		// ----------------------------------
		if (!m_strInputTemplate.IsEmpty()) // Use m_strInputTemplate
		{
			// ---------------------------------------------------
			// Calc the number of literals with the same mask char
			// ---------------------------------------------------
			ASSERT(nStartPos >= 0);
			ASSERT(nEndPos > 0);
			ASSERT(nStartPos <= m_strInputTemplate.GetLength());

			int nSameMaskCharsNum = 1;
			int nIndex = nStartPos; // an index of the first selected char
			TCHAR chMaskChar = m_strMask[nIndex];
			BOOL bScanMore = TRUE;
			while (bScanMore && (nIndex + nSameMaskCharsNum < nGroupEnd))
			{
				if (m_strMask[nIndex + nSameMaskCharsNum] == chMaskChar)
				{
					nSameMaskCharsNum++;
				}
				else
				{
					bScanMore = FALSE;
				}
			}
			
			// Make sure the selection has the same mask char
			if (nEndPos - nStartPos > nSameMaskCharsNum)
			{
				MessageBeep((UINT)-1);
				CEdit::SetSel(nIndex, nIndex+nSameMaskCharsNum);
				return;
			}

			// -------------------------------
			// Form the shifted replace string
			// -------------------------------
			ASSERT(nIndex >= nGroupStart);
			ASSERT(nIndex + nSameMaskCharsNum <= nGroupEnd);
			
			CString strReplace = m_str.Mid(nIndex, nSameMaskCharsNum);
			if (nSameMaskCharsNum > 0)
			{
				ASSERT(nStartPos <= m_strInputTemplate.GetLength());
				ASSERT(nEndPos <= m_strInputTemplate.GetLength());
				int nRange = nEndPos - nStartPos;
				ASSERT(nRange>0);

				strReplace = strReplace.Right(nSameMaskCharsNum - nRange + 1);
				strReplace += CString(m_chMaskInputTemplate, nRange - 1);
				ASSERT(strReplace.GetLength() > 0);
				strReplace.SetAt(0, chChar);
			}

			// -------------------------------------------
			// Replace the content with the shifted string
			// -------------------------------------------
			CEdit::SetSel(nIndex, nIndex+nSameMaskCharsNum);
			CEdit::ReplaceSel(strReplace, TRUE);
			CEdit::SetSel(nIndex, nIndex);
			for(int i=0; i < strReplace.GetLength(); i++)
			{
				m_str.SetAt(nIndex+i, strReplace[i]);
			}
			CEdit::SetSel(nStartPos+1, nStartPos+1);
		}
		else
		{
			// Don't use m_chMaskInputTemplate
			CEdit::OnChar(nChar, nRepCnt, nFlags);
		}
		
	}
}
int PreProcess(char *pcSubName)//预处理子程序,完成功能每次向ScanBuffer中装入固定字长的源程序代码
{
	static char fcFlag='L';
	int i;

	//将源程序中读入剔除空格注视等放到buffer
	char * pcCurrent=0;//只是当前要赋值的字节
	char ** ppcCurrent=&pcCurrent;//指向指针的指针
	char * pcStart;//指向数组的开始,计算偏移量用
	char * pcTemp;//临时变量,初始化用
	FILE * pfSourceFile;//指向要打开的源程序文件

	//初始化pcCurrent确认当前要装入的缓冲区
	if(fcFlag=='L') 
	{
		pcCurrent=acScanBufL;
		pcStart=acScanBufL;
	}
	else
	{
		pcCurrent=acScanBufR;
		pcStart=acScanBufR;
	}

	//初始化当前缓冲区为空字符
	pcTemp=pcCurrent;
	for(i=0;i<SBUFSIZE;i++)
	{
		*pcTemp=0;
		pcTemp++;
	}

	//打开文件
	pfSourceFile=fopen("test.txt","r");
	if(pfSourceFile==NULL) 
	{
		printf("The file %s was not opened\n",pcSubName);//判断文件打开是否成功
		exit(0);//装入失败退出
	}
	else//打开成功读入
	{
		if(fseek(pfSourceFile,lnOffset,SEEK_SET))//移动文件指针到应该的位置
		{
			perror("Fseek failed");
			exit(1);//移动光标失败退出
		}

		while((pcCurrent-pcStart)!=SBUFSIZE)//循环读入指定长度字符
		{
			char cTemp;//临时变量
			cTemp=fgetc(pfSourceFile);//读入一个字符
			cTemp=CheckChar(pfSourceFile,ppcCurrent,cTemp,'N');//获取一个合法的字符

			if(cTemp==0x20)
			{
				*pcCurrent=cTemp;
				pcCurrent++;
				*pcCurrent='#';//程序结束
				break;//判断是否到文件末尾
			}

			*pcCurrent=cTemp;//若刚才输入的不为空格也没结束则输入到缓冲区
			pcCurrent++;
		
		}	

		//修改偏移量为当前偏移量,为下次读入用
		lnOffset=ftell(pfSourceFile);
		
		//关闭文件
		fclose(pfSourceFile);

		//修改fcFlag为下次再次装入,更改缓冲区
		if(fcFlag=='L') fcFlag='R';
		else fcFlag='L';
	}

	return 3;
}
Example #20
0
HRESULT cFont::DrawText(FLOAT sx, FLOAT sy, DWORD dwColor, const char* strText, DWORD dwFlags)
{
    if (this->m_pDevice == NULL)return E_FAIL;
    m_pStateBlockSaved->Capture();
    m_pStateBlockDrawText->Apply();
    this->m_pDevice->SetFVF(D3DFVF_FONT2DVERTEX);
    this->m_pDevice->SetPixelShader(NULL);
    this->m_pDevice->SetStreamSource(0, m_pVB, 0, sizeof(FONT2DVERTEX));
    if (dwFlags & D3DFONT_FILTERED)
    {
        this->m_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
        this->m_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
    }
    if (dwFlags & DT_RIGHT)
    {
        SIZE sz;
        GetTextExtent(strText, &sz);
        sx -= (FLOAT)sz.cx;
    }
    if (dwFlags & DT_CENTER)
    {
        SIZE sz;
        GetTextExtent(strText, &sz);
        sx -= (FLOAT)(sz.cx / 2.0);
    }
    FLOAT fStartX = sx;
    FONT2DVERTEX* pVertices = NULL;
    DWORD         dwNumTriangles = 0;
    m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
    while (*strText)
    {
        unsigned char c = *strText++;
        if (c == '\n')
        {
            sx = fStartX;
            sy += (m_fTexCoords[0][3] - m_fTexCoords[0][1])*dwHeight;
        }
        if (CheckChar(c))
            continue;
        FLOAT tx1 = m_fTexCoords[c - 32][0];
        FLOAT ty1 = m_fTexCoords[c - 32][1];
        FLOAT tx2 = m_fTexCoords[c - 32][2];
        FLOAT ty2 = m_fTexCoords[c - 32][3];

        FLOAT w = (tx2 - tx1) *  dwWidth / m_fTextScale;
        FLOAT h = (ty2 - ty1) * dwHeight / m_fTextScale;

        if (c != ' ')
        {
            if (dwFlags & DT_SHADOW)
            {
                float sxa, sya;
                sxa = sx;
                sya = sy;
                sxa = sx + 1.0f;
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + 0 - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + 0 - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty1);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + w - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + w - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty1);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + w - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + 0 - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty1);

                sxa = sx - 1.0f;
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + 0 - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + 0 - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty1);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + w - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + w - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty1);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + w - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sxa + 0 - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty1);

                sya = sy - 1.0f;
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sya + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sya + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty1);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sya + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sya + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty1);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sya + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sya + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty1);
                sya = sy + 1.0f;
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sya + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sya + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty1);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sya + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sya + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty1);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sya + h - 0.5f, 0.9f, 1.0f), 0xff000000, tx2, ty2);
                *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sya + 0 - 0.5f, 0.9f, 1.0f), 0xff000000, tx1, ty1);
                dwNumTriangles += 8;
            }
            *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), dwColor, tx1, ty2);
            *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), dwColor, tx1, ty1);
            *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), dwColor, tx2, ty2);
            *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), dwColor, tx2, ty1);
            *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), dwColor, tx2, ty2);
            *pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), dwColor, tx1, ty1);
            dwNumTriangles += 2;
            if (dwNumTriangles * 3 > (MAX_NUM_VERTICES - 6))
            {
                this->m_pVB->Unlock();
                this->m_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
                pVertices = NULL;
                this->m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
                dwNumTriangles = 0L;
            }
        }
        sx += w;
    }
    this->m_pVB->Unlock();
    if (dwNumTriangles > 0)
        this->m_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
    m_pStateBlockSaved->Apply();

    return S_OK;
}