static int CheckRegistrySanity(const Attributes *a, const Promise *pp) { assert(a != NULL); bool retval = true; ValidateRegistryPromiser(pp->promiser, pp); if ((a->database.operation) && (strcmp(a->database.operation, "create") == 0)) { if (a->database.rows == NULL) { Log(LOG_LEVEL_INFO, "No row values promised for the MS registry database"); } if (a->database.columns != NULL) { Log(LOG_LEVEL_ERR, "Columns are only used to delete promised values for the MS registry database"); retval = false; } } if ((a->database.operation) && ((strcmp(a->database.operation, "delete") == 0) || (strcmp(a->database.operation, "drop") == 0))) { if (a->database.columns == NULL) { Log(LOG_LEVEL_INFO, "No columns were promised deleted in the MS registry database"); } if (a->database.rows != NULL) { Log(LOG_LEVEL_ERR, "Rows cannot be deleted in the MS registry database, only entire columns"); retval = false; } } for (Rlist *rp = a->database.rows; rp != NULL; rp = rp->next) { if (CountChar(RlistScalarValue(rp), ',') != 2) { Log(LOG_LEVEL_ERR, "Registry row format should be NAME,REG_SZ,VALUE, not '%s'", RlistScalarValue(rp)); retval = false; } } for (Rlist *rp = a->database.columns; rp != NULL; rp = rp->next) { if (CountChar(RlistScalarValue(rp), ',') > 0) { Log(LOG_LEVEL_ERR, "MS registry column format should be NAME only in deletion"); retval = false; } } return retval; }
static int CheckRegistrySanity(Attributes a, Promise *pp) { bool retval = true; ValidateRegistryPromiser(pp->promiser, a, pp); if ((a.database.operation) && (strcmp(a.database.operation, "create") == 0)) { if (a.database.rows == NULL) { CfOut(cf_inform, "", "No row values promised for the MS registry database"); } if (a.database.columns != NULL) { CfOut(cf_error, "", "Columns are only used to delete promised values for the MS registry database"); retval = false; } } if ((a.database.operation) && ((strcmp(a.database.operation, "delete") == 0) || (strcmp(a.database.operation, "drop") == 0))) { if (a.database.columns == NULL) { CfOut(cf_inform, "", "No columns were promised deleted in the MS registry database"); } if (a.database.rows != NULL) { CfOut(cf_error, "", "Rows cannot be deleted in the MS registry database, only entire columns"); retval = false; } } for (Rlist *rp = a.database.rows; rp != NULL; rp = rp->next) { if (CountChar(ScalarValue(rp), ',') != 2) { CfOut(cf_error, "", "Registry row format should be NAME,REG_SZ,VALUE, not \"%s\"", ScalarValue(rp)); retval = false; } } for (Rlist *rp = a.database.columns; rp != NULL; rp = rp->next) { if (CountChar(rp->item, ',') > 0) { CfOut(cf_error, "", "MS registry column format should be NAME only in deletion"); retval = false; } } return retval; }
char *EscapeCharCopy(const char *str, char to_escape, char escape_with) /* * Escapes the 'to_escape'-chars found in str, by prefixing them with 'escape_with'. * Returns newly allocated string. */ { assert(str); int in_size = strlen(str); int out_size = in_size + CountChar(str, to_escape) + 1; char *out = xcalloc(1, out_size); const char *in_pos = str; char *out_pos = out; for(; *in_pos != '\0'; in_pos++, out_pos++) { if(*in_pos == to_escape) { *out_pos = escape_with; out_pos++; } *out_pos = *in_pos; } return out; }
int CPlainTextEditor::FindPositionAlongLine(int iStartOfLine, int iCharCount) { int iPos; char c; int iCountedSoFar; if (iCharCount == 0) { return iStartOfLine; } iPos = iStartOfLine; iCountedSoFar = 0; for (;;) { c = mszText.GetChar(iPos); if ((c == '\n') || (c == '\0')) { return iPos; } else if (iCountedSoFar == iCharCount) { return iPos; } else if (iCountedSoFar > iCharCount) { return iPos-1; } iCountedSoFar = CountChar(iCountedSoFar, c); iPos++; } }
char *EscapeCharCopy(const char *str, char to_escape, char escape_with) /* * Escapes the 'to_escape'-chars found in str, by prefixing them with 'escape_with'. * Returns newly allocated string. */ { assert(str); size_t in_size = strlen(str); if(in_size > (SIZE_MAX / 2) - 1) { ProgrammingError("Buffer passed to EscapeCharCopy() too large (in_size=%zd)", in_size); } size_t out_size = in_size + CountChar(str, to_escape) + 1; char *out = xcalloc(1, out_size); const char *in_pos = str; char *out_pos = out; for(; *in_pos != '\0'; in_pos++, out_pos++) { if(*in_pos == to_escape) { *out_pos = escape_with; out_pos++; } *out_pos = *in_pos; } return out; }
int CPlainTextEditor::GetCharCountAlongLine(int iPos) { int iStartOfLine; int i; char c; int iCount; iStartOfLine = FindStartOfLine(iPos); if (iStartOfLine == iPos) { return 0; } iCount = 0; for (i = iStartOfLine; i < iPos; i++) { c = mszText.GetChar(i); iCount = CountChar(iCount, c); } return iCount; }
static int CheckDatabaseSanity(Attributes a, Promise *pp) { Rlist *rp; int retval = true, commas = 0; if ((a.database.type) && (strcmp(a.database.type, "ms_registry") == 0)) { retval = CheckRegistrySanity(a, pp); } else if ((a.database.type) && (strcmp(a.database.type, "sql") == 0)) { if ((strchr(pp->promiser, '.') == NULL) && (strchr(pp->promiser, '/') == NULL) && (strchr(pp->promiser, '\\') == NULL)) { if (a.database.columns) { CfOut(cf_error, "", "Row values promised for an SQL table, but only the root database was promised"); retval = false; } if (a.database.rows) { CfOut(cf_error, "", "Columns promised for an SQL table, but only the root database was promised"); retval = false; } } if (a.database.db_server_host == NULL) { CfOut(cf_error, "", "No server host is promised for connecting to the SQL server"); retval = false; } if (a.database.db_server_owner == NULL) { CfOut(cf_error, "", "No database login user is promised for connecting to the SQL server"); retval = false; } if (a.database.db_server_password == NULL) { CfOut(cf_error, "", "No database authentication password is promised for connecting to the SQL server"); retval = false; } for (rp = a.database.columns; rp != NULL; rp = rp->next) { commas = CountChar(rp->item, ','); if ((commas > 2) && (commas < 1)) { CfOut(cf_error, "", "SQL Column format should be NAME,TYPE[,SIZE]"); retval = false; } } } if ((a.database.operation) && (strcmp(a.database.operation, "create") == 0)) { } if ((a.database.operation) && ((strcmp(a.database.operation, "delete") == 0) || (strcmp(a.database.operation, "drop") == 0))) { if (pp->ref == NULL) { CfOut(cf_error, "", "When specifying a delete/drop from an SQL database you must add a comment. Take a backup of the database before making this change. This is a highly destructive operation."); retval = false; } } return retval; }
//初始化函数 BOOL CDlgRuleOption::OnInitDialog() { __super::OnInitDialog(); //创建区域 CRgn RgnImage; CImageHandle BackImageHandle(&m_ImageViewBack); m_ImageViewBack.CreateImageRegion(RgnImage,RGB(255,0,255)); //设置窗口 SetWindowRgn(RgnImage,TRUE); SetWindowPos(NULL,0,0,m_ImageViewBack.GetWidth(),m_ImageViewBack.GetHeight(),SWP_NOZORDER|SWP_NOMOVE); //设置窗口 SetWindowText(TEXT("规则设置:")); m_Brush.CreateSolidBrush(COLOR_RULE_BACK); //设置控件 HINSTANCE hResInstance=AfxGetInstanceHandle(); m_btOk.SetButtonImage(IDB_OPTION_BT_OK,hResInstance,false); m_btCancel.SetButtonImage(IDB_OPTION_BT_CANCEL,hResInstance,false); //构造提示 TCHAR szFastDescribe[128]=TEXT(""),szSlowDescribe[128]=TEXT(""); _sntprintf(szFastDescribe,CountChar(szFastDescribe),TEXT("局时 %d 分钟 步时 %d 分钟 读秒 %d 秒"), MODE_FAST_DRAW_TIME/60L,MODE_FAST_STEP_TIME/60L,MODE_FAST_SECOND_TIME); _sntprintf(szSlowDescribe,CountChar(szSlowDescribe),TEXT("局时 %d 分钟 步时 %d 分钟 无读秒"), MODE_SLOW_DRAW_TIME/60L,MODE_SLOW_STEP_TIME/60L); //设置提示 SetDlgItemText(IDC_FAST_DESCRIBE,szFastDescribe); SetDlgItemText(IDC_SLOW_DESCRIBE,szSlowDescribe); //变量定义 TCHAR szBuffer[32]=TEXT(""); LONG lDrawTime[]={600L,1800L,3600L},lStepTime[]={60L,180L,300L}; LONG lRuleSecondTime[]={30L,60L,180L,300L},lRuleSecondCount[]={1L,3L,5L}; //游戏局时 CComboBox * pComboBox=(CComboBox *)GetDlgItem(IDC_DRAW_TIME); for (INT i=0;i<CountArray(lDrawTime);i++) { _sntprintf(szBuffer,CountChar(szBuffer),TEXT("%ld"),lDrawTime[i]/60L); pComboBox->SetItemData(pComboBox->InsertString(i,szBuffer),lDrawTime[i]/60L); } //游戏步时 pComboBox=(CComboBox *)GetDlgItem(IDC_STEP_TIME); for (INT i=0;i<CountArray(lStepTime);i++) { _sntprintf(szBuffer,CountChar(szBuffer),TEXT("%ld"),lStepTime[i]/60L); pComboBox->SetItemData(pComboBox->InsertString(i,szBuffer),lStepTime[i]/60L); } //游戏读秒 pComboBox=(CComboBox *)GetDlgItem(IDC_SECOND_TIME); for (INT i=0;i<CountArray(lRuleSecondTime);i++) { _sntprintf(szBuffer,CountChar(szBuffer),TEXT("%ld"),lRuleSecondTime[i]); pComboBox->SetItemData(pComboBox->InsertString(i,szBuffer),lRuleSecondTime[i]); } //更新控件 UpdateControlStatus(); return TRUE; }
//重画函数 VOID CDlgRuleOption::OnPaint() { CPaintDC dc(this); //获取位置 CRect rcClient; GetClientRect(&rcClient); //创建缓冲 CDC DCBuffer; CBitmap ImageBuffer; DCBuffer.CreateCompatibleDC(&dc); DCBuffer.SetTextAlign(TA_LEFT|TA_TOP); ImageBuffer.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height()); //设置 DC DCBuffer.SetBkMode(TRANSPARENT); DCBuffer.SelectObject(&ImageBuffer); DCBuffer.SelectObject(CSkinResourceManager::GetDefaultFont()); //绘画背景 CImageHandle HandleViewBack(&m_ImageViewBack); m_ImageViewBack.BitBlt(DCBuffer,0,0); //绘画信息 if (m_bControl==false) { //设置 DC DCBuffer.SetTextColor(RGB(64,10,10)); //游戏模式 TCHAR szModeString[64]=TEXT(""); LPCTSTR pszGameMode[]={TEXT("快棋模式"),TEXT("慢棋模式"),TEXT("自定义模式")}; _sntprintf(szModeString,CountChar(szModeString),TEXT("游戏模式:%s"),pszGameMode[m_GameRuleInfo.cbCurrentMode-1]); //游戏局时 TCHAR szDrawString[64]=TEXT(""); _sntprintf(szDrawString,CountChar(szDrawString),TEXT("游戏局时:%d 分钟"),m_GameRuleInfo.wRuleDrawTime/60); //游戏步时 TCHAR szStepString[64]=TEXT(""); _sntprintf(szStepString,CountChar(szStepString),TEXT("游戏步时:%d 分钟"),m_GameRuleInfo.wRuleStepTime/60); //游戏读秒 TCHAR szSecondString[64]=TEXT(""); _sntprintf(szSecondString,CountChar(szSecondString),TEXT("读秒时间:%d 秒"),m_GameRuleInfo.wRuleSecondTime); //输出信息 const INT nXPos=50,nYPos=87,nStringSpace=25; DCBuffer.TextOut(nXPos,nYPos,szModeString,lstrlen(szModeString)); DCBuffer.TextOut(nXPos,nYPos+nStringSpace,szDrawString,lstrlen(szDrawString)); DCBuffer.TextOut(nXPos,nYPos+nStringSpace*2,szStepString,lstrlen(szStepString)); DCBuffer.TextOut(nXPos,nYPos+nStringSpace*3,szSecondString,lstrlen(szSecondString)); } //设置 DC DCBuffer.SetTextColor(RGB(125,125,125)); DCBuffer.SetTextAlign(TA_CENTER|TA_TOP); //剩余时间 TCHAR szTimeLeave[32]=TEXT(""); _sntprintf(szTimeLeave,CountChar(szTimeLeave),TEXT("此对话框在 %d 秒后自动关闭"),m_nResidualTime); DCBuffer.TextOut(rcClient.Width()/2,rcClient.bottom-80,szTimeLeave,lstrlen(szTimeLeave)); //绘画界面 dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),&DCBuffer,0,0,SRCCOPY); //清理资源 DCBuffer.DeleteDC(); ImageBuffer.DeleteObject(); return; }