コード例 #1
0
ファイル: regexp.cpp プロジェクト: dblock/agnes
TCHAR *CRegExp::regatom(int *flagp)
{
        TCHAR *ret;
        int flags;

        *flagp = WORST;         // Tentatively. 

        switch (*regparse++) {
        case _T('^'):
                ret = regnode(BOL);
                break;
        case _T('$'):
                ret = regnode(EOL);
                break;
        case _T('.'):
                ret = regnode(ANY);
                *flagp |= HASWIDTH|SIMPLE;
                break;
        case _T('['): {
                int range;
                int rangeend;
                int c;

                if (*regparse == _T('^')) {     // Complement of range. 
                        ret = regnode(ANYBUT);
                        regparse++;
                } else
                        ret = regnode(ANYOF);
                if ((c = *regparse) == _T(']') || c == _T('-')) {
                        regc(c);
                        regparse++;
                }
                while ((c = *regparse++) != _T('\0') && c != _T(']')) {
                        if (c != _T('-'))
                                regc(c);
                        else if ((c = *regparse) == _T(']') || c == _T('\0'))
                                regc(_T('-'));
                        else 
                        {
                                range = (unsigned) (TCHAR)*(regparse-2);
                                rangeend = (unsigned) (TCHAR)c;
                                if (range > rangeend)
                                {
                                        //TRACE0("invalid [] range\n");
										LastError = "invalid [] range";
                                        return NULL;
                                }
                                for (range++; range <= rangeend; range++)
                                        regc(range);
                                regparse++;
                        }
                }
                regc(_T('\0'));
                if (c != _T(']'))
                {
                        //TRACE0("unmatched []\n");
						LastError = "unmatched []";
                        return NULL;
                }
                *flagp |= HASWIDTH|SIMPLE;
                break;
                }
        case _T('('):
                ret = reg(1, &flags);
                if (ret == NULL)
                        return(NULL);
                *flagp |= flags&(HASWIDTH|SPSTART);
                break;
        case _T('\0'):
        case _T('|'):
        case _T(')'):
                // supposed to be caught earlier 
                //TRACE0("internal error: \\0|) unexpected\n");
				LastError = "internal error: \\0|) unexpected";
                return NULL;
                break;
        case _T('?'):
        case _T('+'):
        case _T('*'):
                //TRACE0("?+* follows nothing\n");
				LastError = "?+* follows nothing";
                return NULL;
                break;
        case _T('\\'):
                if (*regparse == _T('\0'))
                {
                        //TRACE0("trailing \\\n");
						LastError = "trailing \\\n";
                        return NULL;
                }
                ret = regnode(EXACTLY);
                regc(*regparse++);
                regc(_T('\0'));
                *flagp |= HASWIDTH|SIMPLE;
                break;
        default: {
                size_t len;
                TCHAR ender;

                regparse--;
                len = _tcscspn(regparse, META);
                if (len == 0)
                {
                        //TRACE0("internal error: strcspn 0\n");
						LastError = "internal error: strcspn 0";
                        return NULL;
                }
                ender = *(regparse+len);
                if (len > 1 && ISREPN(ender))
                        len--;          // Back off clear of ?+* operand. 
                *flagp |= HASWIDTH;
                if (len == 1)
                        *flagp |= SIMPLE;
                ret = regnode(EXACTLY);
                for (; len > 0; len--)
                        regc(*regparse++);
                regc(_T('\0'));
                break;
                }
        }

        return(ret);
}
コード例 #2
0
ファイル: filerecvdlg.cpp プロジェクト: ybznek/miranda-ng
void RemoveInvalidPathChars(TCHAR *tszString)
{
	if (tszString)
		for (size_t i = _tcscspn(tszString, InvalidPathChars); tszString[i]; i += _tcscspn(tszString + i + 1, InvalidPathChars) + 1)
			tszString[i] = _T('_');
}
コード例 #3
0
ファイル: endtran.c プロジェクト: ChiragBhalgami/tests
/*
---------------------------------------------------------
   TestSQLEndTran
---------------------------------------------------------
*/
PassFail TestMXSQLEndTran(TestInfo *pTestInfo)
{                  
	TEST_DECLARE;
	RETCODE			returncode;
	TCHAR			Heading[MAX_STRING_SIZE];
	SQLHANDLE 		henv;
 	SQLHANDLE 		hdbc;
 	SQLHANDLE		hstmt;
	TCHAR			*ExecDirStr[] = 
							{
								//"create table testtransact(c1 TCHAR(20),c2 integer)",
								//"create table testtransact(c1 TCHAR(20),c2 integer) NO PARTITION",
                                // The  NO PARTITION is to help speed up this test on NEO/clustered systems with POS turned on.
								_T("--"),
								_T("--"),
								_T("--"),
								_T("--"),
								_T("--"),
								_T("--")
							};
	UWORD			fType[] = { SQL_ROLLBACK, SQL_COMMIT };
	TCHAR			*TypeDesc[] = { _T("SQL_ROLLBACK"), _T("SQL_COMMIT") };
	TCHAR			*Output;
	SQLLEN			OutputLen; // sushil
	struct
	{
		SWORD	ExeRes[2];
		SWORD	FetchRes[2];
		TCHAR	*DataRes[2];
	} CheckRes[] =	{
						{SQL_ERROR,SQL_SUCCESS,SQL_NO_DATA_FOUND,SQL_NO_DATA_FOUND,_T(""),_T("")},
						{SQL_SUCCESS,SQL_SUCCESS,SQL_NO_DATA_FOUND,SQL_SUCCESS,_T(""),_T("--")},
						{SQL_SUCCESS,SQL_SUCCESS,SQL_SUCCESS,SQL_SUCCESS,_T("--"),_T("--")},
						{SQL_SUCCESS,SQL_SUCCESS,SQL_SUCCESS,SQL_NO_DATA_FOUND,_T("--"),_T("")},
						{SQL_SUCCESS,SQL_ERROR,SQL_NO_DATA_FOUND,SQL_NO_DATA_FOUND,_T(""),_T("")}
					};
	int	i = 0, j = 0, iend = 5, jend = 1, commit_on_off = 0;

//===========================================================================================================
	var_list_t *var_list;
	var_list = load_api_vars(_T("SQLEndTran"), charset_file);
	if (var_list == NULL) return FAILED;

	ExecDirStr[0] = var_mapping(_T("SQLEndTran_ExecDirStr_0"), var_list);
	ExecDirStr[1] = var_mapping(_T("SQLEndTran_ExecDirStr_1"), var_list);
	ExecDirStr[2] = var_mapping(_T("SQLEndTran_ExecDirStr_2"), var_list);
	ExecDirStr[3] = var_mapping(_T("SQLEndTran_ExecDirStr_3"), var_list);
	ExecDirStr[4] = var_mapping(_T("SQLEndTran_ExecDirStr_4"), var_list);
	ExecDirStr[5] = var_mapping(_T("SQLEndTran_ExecDirStr_5"), var_list);

	CheckRes[1].DataRes[1] = var_mapping(_T("SQLEndTran_Insert"), var_list);
	CheckRes[2].DataRes[0] = var_mapping(_T("SQLEndTran_Insert"), var_list);
	CheckRes[2].DataRes[1] = var_mapping(_T("SQLEndTran_Update"), var_list);
	CheckRes[3].DataRes[0] = var_mapping(_T("SQLEndTran_Update"), var_list);

//========================================================================================================

	LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing API => SQLEndTran.\n"));
	TEST_INIT;

	TESTCASE_BEGIN("Initializing SQLEndTran test environment\n");
	if(!FullConnectWithOptions(pTestInfo, CONNECT_ODBC_VERSION_3))
	{
		LogMsg(NONE,_T("Unable to connect\n"));
		TEST_FAILED;
		TEST_RETURN;
	}
	henv = pTestInfo->henv;
 	hdbc = pTestInfo->hdbc;
 	hstmt = (SQLHANDLE)pTestInfo->hstmt;
	returncode = SQLAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE)hdbc, &hstmt);	
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocHandle"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		FullDisconnect(pTestInfo);
		TEST_FAILED;
		TEST_RETURN;
	}
	//setting CQD to set POS OFF,as some tests fail otherwise. (to be fixed)
	//SQLExecDirect (hstmt,"CONTROL QUERY DEFAULT POS 'OFF'",SQL_NTS);

	for (commit_on_off = 0; commit_on_off < 10; commit_on_off++)
	{
		returncode = SQLSetConnectAttr((SQLHANDLE)hdbc,SQL_AUTOCOMMIT,(void *)SQL_AUTOCOMMIT_ON,0);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnectAttr"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			FullDisconnect(pTestInfo);
			TEST_FAILED;
			TEST_RETURN;
		}
		TESTCASE_END;
		SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[4],SQL_NTS); /* CLEANUP */
		for (i = 0; i <= (iend-1); i++)
		{
			_stprintf(Heading,_T("Test Positive Functionality of SQLEndTran while Autocommit is ON and executing\n"));
			_tcscat(Heading, ExecDirStr[i]);
			_tcscat(Heading, _T("\n"));
			TESTCASE_BEGINW(Heading);
			returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[i],SQL_NTS);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrorsVer3(henv,hdbc,hstmt);
				TEST_FAILED;
			}
		}
		SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[4],SQL_NTS); /* CLEANUP */
		returncode = SQLSetConnectAttr((SQLHANDLE)hdbc,SQL_AUTOCOMMIT,(void *)SQL_AUTOCOMMIT_OFF,0);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnectAttr"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			FullDisconnect(pTestInfo);
			TEST_FAILED;
			TEST_RETURN;
		}
		TESTCASE_END;
		
		for (i = 0; i <= (iend-1); i++)
		{
			for (j = 0; j <= jend; j++)
			{
				_stprintf(Heading,_T("Test Positive Functionality of SQLEndTran while Autocommit is OFF and executing\n"));
				_tcscat(Heading, ExecDirStr[i]);
				_tcscat(Heading, _T(" & "));
				_tcscat(Heading, TypeDesc[j]);
				_tcscat(Heading, _T("\n"));
				TESTCASE_BEGINW(Heading);
				
				returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[i],SQL_NTS);
				if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
				{
					LogAllErrorsVer3(henv,hdbc,hstmt);
					TEST_FAILED;
				}
				else
				{
					returncode=SQLEndTran(SQL_HANDLE_DBC,(SQLHANDLE)hdbc,fType[j]);
					Sleep(2);																// tmf rollback is slower.
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLTransact"))
					{
						LogAllErrorsVer3(henv,hdbc,hstmt);
						TEST_FAILED;
					}

					returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[iend],SQL_NTS);
					if(!CHECKRC(CheckRes[i].ExeRes[j],returncode,"SQLExecDirect"))
					{
						LogAllErrorsVer3(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					else
					{
						if (returncode == SQL_SUCCESS || returncode == SQL_SUCCESS_WITH_INFO)
						{
							Output = (TCHAR *)malloc(NAME_LEN);
							returncode=SQLBindCol(hstmt,1,SQL_C_TCHAR,Output,NAME_LEN,&OutputLen);
							if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
							{
								LogAllErrorsVer3(henv,hdbc,hstmt);
								TEST_FAILED;
							}
							else
							{
								returncode = SQLFetch(hstmt);
								if(!CHECKRC(CheckRes[i].FetchRes[j],returncode,"SQLFetch"))
								{
									LogAllErrorsVer3(henv,hdbc,hstmt);
									TEST_FAILED;
								}
								else
								{
									if (returncode != SQL_NO_DATA_FOUND && returncode != SQL_ERROR)
									{
										if (_tcscspn(CheckRes[i].DataRes[j],Output) == 0)
										{
											//LogMsg(NONE,_T("expect: %s and actual: %s are matched\n"),Output,CheckRes[i].DataRes[j]);
										}	
										else
										{
											LogMsg(ERRMSG,_T("expect: %s and actual: %s are not matched at line %d \n"),Output,CheckRes[i].DataRes[j],__LINE__);
											TEST_FAILED;	
										}
									}
								}
								free(Output);
								SQLFreeStmt(hstmt,SQL_CLOSE);
							}
						}
					}
				}
			//SQLFreeStmt(hstmt,SQL_CLOSE);
			TESTCASE_END;
			}/* end i loop */
		//SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[4],SQL_NTS); /* CLEANUP */
		}/* end j loop */
	}

//========================================================================================================

	SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[4],SQL_NTS); /* CLEANUP */
    
	returncode = SQLDisconnect((SQLHANDLE)hdbc);
    if(!CHECKRC(SQL_ERROR,returncode,"SQLDisconnect")) 
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		TEST_FAILED;	
	}	
	
	// Free the open transactions.
	returncode=SQLEndTran(SQL_HANDLE_DBC,(SQLHANDLE)hdbc,SQL_ROLLBACK);
	Sleep(2);	

	returncode=FullDisconnect3(pTestInfo);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFullDisconnect"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		TEST_FAILED;
	}

	LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLEndTran.\n"));
	free_list(var_list);
	TEST_RETURN;
}
コード例 #4
0
ファイル: alias.c プロジェクト: Fetchered/ReactOS-CMD
/* specified routines */
VOID ExpandAlias (LPTSTR cmd, INT maxlen)
{
	LPTSTR buffer;
	TCHAR *position, *in, *out;
	LPTSTR Token;
	LPTSTR tmp;

	tmp = cmd_dup(cmd);
	if (!tmp)
		return;

	/* first part is the macro name */
	position = tmp + _tcscspn(tmp, _T(" \n"));
	if (position == tmp)
	{
		cmd_free(tmp);
		return;
	}
	*position++ = _T('\0');
	position += _tcsspn(position, _T(" "));

	buffer = cmd_alloc(maxlen);
	if (!buffer)
	{
		cmd_free(tmp);
		return;
	}
	
	if (GetConsoleAlias(tmp, buffer, maxlen, _T("cmd.exe")) == 0)
	{
		cmd_free(tmp);
		cmd_free(buffer);
		return;
	}

	in = buffer;
	out = cmd;
	while (*in)
	{
		if (*in == _T('$'))
		{
			Token = position;
			if (in[1] >= _T('1') && in[1] <= _T('9'))
			{
				/* Copy a single space-delimited token from the input line */
				INT num;
				for (num = in[1] - _T('1'); num > 0; num--)
				{
					Token += _tcscspn(Token, _T(" \n"));
					Token += _tcsspn(Token, _T(" "));
				}
				while (!_tcschr(_T(" \n"), *Token))
				{
					if (out >= &cmd[maxlen - 1])
						break;
					*out++ = *Token++;
				}
				in += 2;
				continue;
			}
			else if (in[1] == _T('*'))
			{
				/* Copy the entire remainder of the line */
				while (*Token && *Token != _T('\n'))
				{
					if (out >= &cmd[maxlen - 1])
						break;
					*out++ = *Token++;
				}
				in += 2;
				continue;
			}
		}
		if (out >= &cmd[maxlen - 1])
			break;
		*out++ = *in++;
	}
	*out++ = _T('\n');
	*out = _T('\0');

	cmd_free(buffer);
	cmd_free(tmp);
}
コード例 #5
0
ファイル: strex.cpp プロジェクト: Rupan/winscp
// strcspn equivalent
CString CString::SpanExcluding(LPCTSTR lpszCharSet) const
{
	ASSERT(AfxIsValidString(lpszCharSet));
	return Left(_tcscspn(m_pchData, lpszCharSet));
}
コード例 #6
0
ファイル: ctrl_contact.cpp プロジェクト: Seldom/miranda-ng
/**
 * name:	 DlgProc_EditPhone()
 * desc:	 dialog procedure
 *
 * return:	 0 or 1
 **/
INT_PTR CALLBACK DlgProc_Phone(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	LPCBEXITEM cbi = (LPCBEXITEM)GetUserData(hDlg);
	static int noRecursion = 0;

	switch (msg) {
	case WM_INITDIALOG:
		{
			UINT i, item, countryCount;
			LPIDSTRLIST	pCountries;
			HWND hCombo = GetDlgItem(hDlg, EDIT_COUNTRY);

			cbi = (LPCBEXITEM)lParam;
			if (!cbi) return FALSE;
			SetUserData(hDlg, lParam);

			SendDlgItemMessage(hDlg, IDC_HEADERBAR, WM_SETICON, 0, (LPARAM)IcoLib_GetIcon(ICO_DLG_PHONE, TRUE));
			if (db_get_b(NULL, MODNAME, SET_ICONS_BUTTONS, 1)) {
				SendDlgItemMessage(hDlg, IDOK, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIcon(ICO_BTN_OK));
				SendDlgItemMessage(hDlg, IDCANCEL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIcon(ICO_BTN_CANCEL));
			}

			// translate Userinfo buttons
			{
				TCHAR szButton[MAX_PATH];
				HWND hBtn;

				hBtn = GetDlgItem(hDlg, IDOK);
				GetWindowText(hBtn, szButton, _countof(szButton));
				SetWindowText(hBtn, TranslateTS(szButton));
				hBtn = GetDlgItem(hDlg, IDCANCEL);
				GetWindowText(hBtn, szButton, _countof(szButton));
				SetWindowText(hBtn, TranslateTS(szButton));
			}
			if (*cbi->pszVal) SetWindowText(hDlg, LPGENT("Edit phone number"));
			if (cbi->wFlags & CBEXIF_SMS) CheckDlgButton(hDlg, CHECK_SMS, BST_CHECKED);
			TranslateDialogDefault(hDlg);

			EnableWindow(GetDlgItem(hDlg, IDOK), *cbi->pszVal);
			SendDlgItemMessage(hDlg, EDIT_AREA, EM_LIMITTEXT, 31, 0);
			SendDlgItemMessage(hDlg, EDIT_NUMBER, EM_LIMITTEXT, 63, 0);
			SendDlgItemMessage(hDlg, EDIT_CATEGORY, EM_LIMITTEXT, cbi->ccCat - 1, 0);
			SendDlgItemMessage(hDlg, EDIT_PHONE, EM_LIMITTEXT, cbi->ccVal - 1, 0);

			GetCountryList(&countryCount, &pCountries);
			for (i = 0; i < countryCount; i++) {
				if (pCountries[i].nID == 0 || pCountries[i].nID == 0xFFFF) continue;
				item = SendMessage(hCombo, CB_ADDSTRING, NULL, (LPARAM)pCountries[i].ptszTranslated);
				SendMessage(hCombo, CB_SETITEMDATA, item, pCountries[i].nID);
			}

			SetDlgItemText(hDlg, EDIT_PHONE, cbi->pszVal);
			SetDlgItemText(hDlg, EDIT_CATEGORY, cbi->pszCat);
			EnableWindow(GetDlgItem(hDlg, EDIT_CATEGORY), !(cbi->wFlags & CBEXIF_CATREADONLY));
		}
		return TRUE;

	case WM_CTLCOLORSTATIC:
		SetBkColor((HDC)wParam, RGB(255, 255, 255));
		return (INT_PTR)GetStockObject(WHITE_BRUSH);

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
			case IDOK:
				if (HIWORD(wParam) == BN_CLICKED) {
					TCHAR szText[MAXDATASIZE];
					int errorPos;

					if (!GetDlgItemText(hDlg, EDIT_PHONE, szText, _countof(szText)) || !CheckPhoneSyntax(szText, cbi->pszVal, cbi->ccVal, errorPos) || errorPos > -1) {
						MsgErr(hDlg, TranslateT("The phone number should start with a + and consist of\nnumbers, spaces, brackets and hyphens only."));
						break;
					}
					// save category string
					GetDlgItemText(hDlg, EDIT_CATEGORY, cbi->pszCat, cbi->ccCat);

					// save SMS flag
					if ((int)IsDlgButtonChecked(hDlg, CHECK_SMS) != ((cbi->wFlags & CBEXIF_SMS) == CBEXIF_SMS))
						cbi->wFlags ^= CBEXIF_SMS;
				}
				//fall through
			case IDCANCEL:
				if (HIWORD(wParam) == BN_CLICKED) 
					EndDialog(hDlg, wParam);
				break;

		case EDIT_COUNTRY:
			if (HIWORD(wParam) != CBN_SELCHANGE)
				break;

		case EDIT_AREA:
		case EDIT_NUMBER:
			if (LOWORD(wParam) != EDIT_COUNTRY && HIWORD(wParam) != EN_CHANGE) break;
			if (noRecursion) break;
			EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
			{
				TCHAR szPhone[MAXDATASIZE], szArea[32], szData[64];
				int	 nCurSel = SendDlgItemMessage(hDlg, EDIT_COUNTRY, CB_GETCURSEL, 0, 0);
				UINT	nCountry = (nCurSel != CB_ERR) ? SendDlgItemMessage(hDlg, EDIT_COUNTRY, CB_GETITEMDATA, nCurSel, 0) : 0;

				GetDlgItemText(hDlg, EDIT_AREA, szArea, _countof(szArea));
				GetDlgItemText(hDlg, EDIT_NUMBER, szData, _countof(szData));
				mir_sntprintf(szPhone, _T("+%u (%s) %s"), nCountry, szArea, szData);
				noRecursion = 1;
				SetDlgItemText(hDlg, EDIT_PHONE, szPhone);
				noRecursion = 0;
			}
			break;

		case EDIT_PHONE:
			if (HIWORD(wParam) != EN_UPDATE) break;
			if (noRecursion) break;
			noRecursion = 1;
			{
				TCHAR szText[MAXDATASIZE], *pText = 0, *pArea, *pNumber;
				bool isValid = true;
				GetDlgItemText(hDlg, EDIT_PHONE, szText, _countof(szText));
				if (szText[0] != '+')
					isValid = false;
				if (isValid) {
					int country = _tcstol(szText + 1, &pText, 10);
					if (pText - szText > 4)
						isValid = false;
					else {
						int i;
						for (i = SendDlgItemMessage(hDlg, EDIT_COUNTRY, CB_GETCOUNT, 0, 0) - 1; i >= 0; i--) {
							if (country == SendDlgItemMessage(hDlg, EDIT_COUNTRY, CB_GETITEMDATA, i, 0)) {
								SendDlgItemMessage(hDlg, EDIT_COUNTRY, CB_SETCURSEL, i, 0);
								break;
							}
						}
						if (i < 0)
							isValid = false;
					}
				}
				if (isValid) {
					pArea = pText + _tcscspn(pText, _T("0123456789"));
					pText = pArea + _tcsspn(pArea, _T("0123456789"));
					if (*pText) {
						*pText = '\0';
						pNumber = pText + 1 + _tcscspn(pText + 1, _T("0123456789"));
						SetDlgItemText(hDlg, EDIT_NUMBER, pNumber);
					}
					SetDlgItemText(hDlg, EDIT_AREA, pArea);
				}
				if (!isValid) {
					SendDlgItemMessage(hDlg, EDIT_COUNTRY, CB_SETCURSEL, -1, 0);
					SetDlgItemText(hDlg, EDIT_AREA, _T(""));
					SetDlgItemText(hDlg, EDIT_NUMBER, _T(""));
				}
			}
			noRecursion = 0;
			EnableWindow(GetDlgItem(hDlg, IDOK), GetWindowTextLength(GetDlgItem(hDlg, EDIT_PHONE)));
			break;
		}
		break;
	}
	return FALSE;
}
コード例 #7
0
ファイル: AppMenu.cpp プロジェクト: kanbang/myexercise
void AppMenu::CreateMenus()
{
    CMDIFrameWnd* pMainFrame = acedGetAcadFrame();
    pMainFrame->LockWindowUpdate();

    //得到菜单栏上面的最后一个菜单
    CString sName;
    if( !GetLastMenuFromMenubar( sName ) )
        return;

    sName.Replace( _T( "&" ), _T( "" ) ); //debug

    IAcadMenuGroup* mnuGrp = NULL;
    if ( !GetAcadMenuGroup( &mnuGrp, sName ) )
        return ;

    //得到所有菜单组
    IAcadPopupMenus*   mnus = NULL;
    IAcadPopupMenu*   mnu = NULL;
    IAcadPopupMenuItem*  mnuitem = NULL;
    HRESULT hr = S_OK;
    hr = mnuGrp->get_Menus( &mnus );
    long cnt = 0l;
    hr = mnus->get_Count( &cnt );
    int i = 0;
    int j = 0;
    int k = 0;
    VARIANT index;
    VariantInit( &index );
    V_VT( &index ) = VT_I4;
    CArray<IAcadPopupMenu*, IAcadPopupMenu*> MnuAdrs;

    long lIndex = 0;
    TCHAR MenuName[256];
    for ( i = 0; i < m_menuCount; i++ )
    {
        CString tmpMenu = m_TopMenuNames[i];
        tmpMenu.Replace( _T( "&" ), _T( "" ) );
        if( IsMenuExist( mnu, lIndex, tmpMenu, mnus ) ) //处理二次加载
        {
            V_I4( &index ) = lIndex;
        }
        else
        {
            //			MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)m_TopMenuNames[i], -1, MenuName, 256);
            _tcscpy( MenuName, m_TopMenuNames[i] );
            mnus->Add( MenuName, &mnu );
            V_I4( &index ) = cnt++;
        }

        MnuAdrs.Add( mnu );
        mnu->InsertInMenuBar( index );
    }

    IAcadPopupMenu* MenuItem = NULL;
    int subMenuNum = 0;
    CCADMenuArray* Menus;
    TCHAR szSubMenu[256];
    TCHAR szSubMenuMacro[256];
    CString MenusName;
    CString Menusorder;
    for ( j = 0; j < m_menuCount; j++ )
    {
        Menus = m_menus.GetAt( j );
        subMenuNum = Menus->GetSize();
        for ( k = 0; k < subMenuNum; k++ )
        {
            mnu = MnuAdrs.GetAt( j );
            if ( !_tcscmp( _T( "--" ), Menus->GetAt( k )->name ) )
            {
                V_I4( &index ) = k;
                mnu->AddSeparator( index, &mnuitem );
            }
            else
            {
                V_I4( &index ) = k;
                MenusName = Menus->GetAt( k )->name;
                Menusorder = Menus->GetAt( k )->order;
                _tcscpy( szSubMenu, MenusName );
                _tcscpy( szSubMenuMacro, Menusorder );
                //MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)MenusName, -1, szSubMenu, 256);
                //MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)Menusorder, -1, szSubMenuMacro, 256);
                if ( _tcscspn( Menus->GetAt( k )->name, _T( "*" ) ) < ( size_t )MenusName.GetLength() )
                {
                    MenusName.TrimLeft( _T( '*' ) );
                    //					MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)MenusName, -1, szSubMenu, 256);
                    _tcscpy( szSubMenu, MenusName );
                    hr = mnu->AddSubMenu( index, szSubMenu, &MenuItem );
                }
                else if ( _tcscspn( Menus->GetAt( k )->name, _T( "$" ) ) < ( size_t )MenusName.GetLength() )
                {
                    MenusName.TrimLeft( _T( '$' ) );
                    if( MenusName.Compare( _T( "--" ) ) == 0 ) //添加子菜单的分隔符
                    {
                        hr = MenuItem->AddSeparator( index, &mnuitem );
                    }
                    else
                    {
                        //MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)MenusName, -1, szSubMenu, 256);
                        _tcscpy( szSubMenu, MenusName );
                        hr = MenuItem->AddMenuItem( index, szSubMenu, szSubMenuMacro, &mnuitem );
                    }
                }
                else
                {
                    hr = mnu->AddMenuItem( index, szSubMenu, szSubMenuMacro, &mnuitem );
                }
            }
        }
    }

    for ( i = 0; i < MnuAdrs.GetSize(); i++ )
    {
        MnuAdrs[i]->Release();
    }
    mnuitem->Release();
    mnus->Release();
    mnuGrp->Release();
    pMainFrame->UnlockWindowUpdate();

    stcMyTopMenuNames.Copy( m_TopMenuNames ); //将顶级菜单名存入静态数组中,卸载时使用

    //return ;
}
コード例 #8
0
ファイル: FilePath.cpp プロジェクト: KnowNo/test-code-backup
ERootType CFilePath::GetRootType(
    LPCTSTR psPath,
    int *pnLen,
    BOOL bGreedy)
{
    const TCHAR *psInvalidChars = L"\\/:*/\"<>|";
    const TCHAR chBK = '\\';

    if (!psPath || !*psPath)
        return GRT_Return(rtNoRoot, 0, pnLen);

    if (_istalpha(*psPath) && psPath[1] == ':')
    {
        if (psPath[2] == chBK)
        {
            return GRT_Return(rtDriveRoot, 3, pnLen);
        } else
        {
            return GRT_Return(rtDriveCur, 2, pnLen);
        }
    }

    if (psPath[0] == chBK && psPath[1] == chBK)
    {
        if (psPath[2] == '?' && psPath[3] == chBK)
        {
            int nExtraLen = 0;
            GetRootType(psPath+4, &nExtraLen) ;
            return GRT_Return(rtLongPath, 4 + nExtraLen, pnLen);
        }

        int nLen = 2 + _tcscspn(psPath + 2, psInvalidChars);
        TCHAR const *psEnd = psPath+nLen;

        if (*psEnd == 0)
            return GRT_Return(rtServerOnly, nLen, pnLen);

        if (*psEnd == chBK && psEnd[1] == 0)
            return GRT_Return(rtServerOnly, nLen + 1, pnLen);

        if (*psEnd == chBK)
        {
            if (!bGreedy)
                return GRT_Return(rtServer, nLen, pnLen);

            nLen += 1 + _tcscspn(psEnd + 1, psInvalidChars);
            psEnd = psPath + nLen;

            if (*psEnd == 0)
                return GRT_Return(rtServerShare, nLen, pnLen);

            if (*psEnd == '\\')
                return GRT_Return(rtServerShare, nLen + 1, pnLen);
        }
    }

    int nLen = _tcscspn(psPath, psInvalidChars);
    TCHAR const *psEnd = psPath + nLen;

    if (nLen > 0 && *psEnd == ':')
    {
        if (psEnd[1] == '/' && psEnd[2] == '/')
            return GRT_Return(rtProtocol, nLen + 3, pnLen);
        else
            return GRT_Return(rtPseudoProtocol, nLen + 1, pnLen);
    }

    return GRT_Return(rtNoRoot, 0, pnLen);
}
コード例 #9
0
ファイル: Strclass.cpp プロジェクト: xianyinchen/LUNAPlus
// strcspn equivalent
CStrClass CStrClass::SpanExcluding(LPCTSTR lpszCharSet) const
{
	return Left(_tcscspn(m_pchData, lpszCharSet));
}
コード例 #10
0
ファイル: msgs.cpp プロジェクト: bagdxk/openafs
UINT ShowMessageBox (UINT Id, UINT Button, UINT Help, ...) {

    CString temp;
    TCHAR *pszstring,
    *pszpaste,
    *pszcut,
    *pszdone,
    *pszconvert;
    TCHAR chread;
    va_list params;
    int x;

    pszconvert = new TCHAR[255];
    va_start(params, Help);
    LoadString (temp, Id);
    pszstring = temp.GetBuffer(512);
    _tcscpy(pszstring,pszstring);
    temp.ReleaseBuffer();
    // Look and see - is there a need to insert chars (95% of the time, there won't)
    if (!_tcsstr(pszstring, _T("%"))) {
	delete pszconvert;
	return AfxMessageBox(pszstring, Button, Help);
    }

    x = _tcscspn(pszstring, _T("%"));
    pszdone = new TCHAR[512];
    pszcut = new TCHAR[512];
    pszpaste = new TCHAR[512];
    _tcscpy(pszcut, &pszstring[x+2]);
    _tcsncpy(pszpaste, pszstring, x);
    pszpaste[x] = _T('\0');
    chread = pszstring[x+1];

    for ( ; ; ) {

	switch (chread) {
	case	_T('i') :
	case	_T('d') :
	{
	    int anint = va_arg(params, int);
	    _itot( anint, pszconvert, 10);
	    break;
	}
	case	_T('u') :
	{
	    UINT anuint = va_arg(params, UINT);
	    _itot( anuint, pszconvert, 10);
	    break;
	}

	case	_T('x') :
	case	_T('X') :
	{
	    int ahex = va_arg(params, int);
	    _itot( ahex, pszconvert, 16);
	    break;
	}
	case	_T('g') :
	case	_T('f') :
	case	_T('e') :
	{
	    double adbl = va_arg(params, double);
            _stprintf(pszconvert, _T("%g"), adbl);
	    break;
	}
	case	_T('s') :
	{
	    TCHAR *pStr = va_arg(params, TCHAR*);
	    ASSERT(_tcslen(pStr) <= 255);
	    _tcscpy(pszconvert, pStr);
	    break;
	}
	case	_T('l') :
	{
	    chread = pszdone[x+2];
	    switch(chread) {
	    case	_T('x')	:
	    {
		long int alhex = va_arg(params, long int);
		_ltot(alhex, pszconvert, 16);
		_tcscpy(pszcut, &pszcut[1]);
		break;
	    }
	    case 	_T('d')	:
		default 	:
		{
		    long int along = va_arg(params, long int);
		    _ltot( along, pszconvert, 10);
		    // For the L, there will be one character after it,
		    //   so move ahead another letter
		    _tcscpy(pszcut, &pszcut[1]);
		    break;
		}
	    }
	    break;
	}

	case	_T('c') :
	{
	    int letter = va_arg(params, int);
	    pszconvert[0] = (TCHAR)letter;
	    pszconvert[1] = '\0';
	    break;
	}
	case 	_T('a')	:
	{
	    CString zeta;
	    TCHAR* lsc;
	    UINT ls = va_arg(params, UINT);
	    LoadString (zeta, ls);
	    lsc = zeta.GetBuffer(255);
	    _tcscpy(pszconvert, lsc);
	    zeta.ReleaseBuffer();
	    break;
	}
	case	_T('o')	:
	{
	    CString get = va_arg(params, CString);
	    TCHAR* ex = get.GetBuffer(255);
	    _tcscpy(pszconvert,ex);
	    get.ReleaseBuffer();
	    break;
	}
	    default 	:
	    {
		_tcscpy(pszconvert, _T(" Could not load message. Invalid %type in string table entry. "));
		delete pszdone;
		pszdone = new TCHAR[_tcslen(pszpaste)+_tcslen(pszcut)+_tcslen(pszconvert)+5];
		_tcscpy(pszdone, pszpaste);
		_tcscat(pszdone, pszconvert);
		_tcscat(pszdone, pszcut);
		AfxMessageBox(pszdone, Button, Help);
		delete pszcut;
		delete pszpaste;
		delete pszconvert;
		delete pszdone;
		ASSERT(FALSE);
		return 0;
	    }
	} // case

	delete pszdone;
	pszdone = new TCHAR[_tcslen(pszpaste)+_tcslen(pszcut)+_tcslen(pszconvert)+5];
	_tcscpy(pszdone, pszpaste);
	_tcscat(pszdone, pszconvert);
	_tcscat(pszdone, pszcut);
	// Now pszdone holds the entire message.
	// Check to see if there are more insertions to be made or not

	if (!_tcsstr(pszdone, _T("%")))	{
	    UINT rt_type = AfxMessageBox(pszdone, Button, Help);
	    delete pszcut;
	    delete pszpaste;
	    delete pszconvert;
	    delete pszdone;
	    return rt_type;
	} // if

	// there are more insertions to make, prepare the strings to use.
	x = _tcscspn(pszdone, _T("%"));
	_tcscpy(pszcut, &pszdone[x+2]);
	_tcsncpy(pszpaste, pszdone, x);
	pszpaste[x] = _T('\0');
	chread = pszdone[x+1];

    } // for
    ASSERT(FALSE);
    return 0;

} // ShowMessageBox