bool FieldHelper::AddField( const CString& type, const CString& field ) { if( IsEmptyString( type ) || IsEmptyString( field ) ) return false; bool ret = AddField_Helper( PROPERTY_DATA_FIELD_DICT, type, field ); if( ret ) { AcDbObjectIdArray objIds; GetDataObjectsByType( type, objIds ); if( !objIds.isEmpty() ) { AddFieldToDataObject( objIds ); } } return ret; }
void SIMPLEAPI SlxInitProfile(const wchar_t* pszCompanyName, const wchar_t* pszAppName, bool bFileBased) { g_strCompanyName=pszCompanyName; g_strAppName=pszAppName; g_bFileBased=bFileBased; ASSERT(!IsEmptyString(g_strCompanyName)); ASSERT(!IsEmptyString(g_strAppName)); if (g_bFileBased) { // Work out profile file name CUniString strSettingsFile=SlxGetProfileFileName(pszCompanyName, pszAppName, true); // Load settings g_ProfileFile.Init(strSettingsFile); } }
bool FieldHelper::RemoveField( const CString& type, const CString& field ) { if( IsEmptyString( type ) || IsEmptyString( field ) ) return false; int index = RemoveField_Helper( PROPERTY_DATA_FIELD_DICT, type, field ); bool ret = ( INVALID_ENTRY != index ); if( ret ) { // åˆ é™¤å›¾å…ƒä¸çš„å—段 AcDbObjectIdArray objIds; GetDataObjectsByType( type, objIds ); if( !objIds.isEmpty() ) { RemoveFieldFromDataObject( objIds, index ); } } return ret; }
int SIMPLEAPI ParseInt(const wchar_t* psz, int iDefault) { if (IsEmptyString(psz)) return iDefault; int iVal; if (!ParseInt(psz, &iVal)) return iDefault; return iVal; }
int SIMPLEAPI SlxGetProfileInt(const wchar_t* pszSection, const wchar_t* pszEntry, int nDefault) { ASSERT(!IsEmptyString(g_strAppName)); if (g_bFileBased) { return g_ProfileFile.GetIntValue(pszSection, pszEntry, nDefault); } else { DWORD dw; if (RegGetDWORD(HKEY_CURRENT_USER, SlxGetProfileKey(pszSection), pszEntry, &dw)!=ERROR_SUCCESS) return nDefault; return int(dw); } }
CUniString SIMPLEAPI SlxGetProfileString(const wchar_t* pszSection, const wchar_t* pszEntry, const wchar_t* pszDefault) { ASSERT(!IsEmptyString(g_strAppName)); if (g_bFileBased) { return g_ProfileFile.GetValue(pszSection, pszEntry, pszDefault); } else { CUniString str; if (RegGetString(HKEY_CURRENT_USER, SlxGetProfileKey(pszSection), pszEntry, str)!=ERROR_SUCCESS) return pszDefault; return str; } }
bool SIMPLEAPI SlxSetProfileInt(const wchar_t* pszSection, const wchar_t* pszEntry, int nValue) { ASSERT(!IsEmptyString(g_strAppName)); if (g_bFileBased) { g_ProfileFile.SetIntValue(pszSection, pszEntry, nValue); } else { CSmartHandle<HKEY> Key; if (RegCreateKey(HKEY_CURRENT_USER, Format(L"Software\\%s\\%s\\%s", g_strCompanyName, g_strAppName, pszSection), &Key)!=ERROR_SUCCESS) return false; RegSetValueEx(Key, pszEntry, 0, REG_DWORD, (BYTE*)&nValue, sizeof(nValue)); } return true; }
// IDOK button handler LRESULT CSelectMachineDlg::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { ATLControls::CListBox cb(GetDlgItem(IDC_MACHINENAME)); int iSel=cb.GetCurSel(); if (iSel<0) return 0; CComBSTR bstrMachineName; cb.GetTextBSTR(iSel, bstrMachineName.m_str); if (IsEmptyString(bstrMachineName)) return 0; m_strMachineName=bstrMachineName; m_bPowerOnMachine=!!IsDlgButtonChecked(IDC_POWERONMACHINE); EndDialog(wID); return 0; }
int IO::ExtractLines(const char *input_file_path, std::vector<std::string> &lines) { int lineNum = -1; std::ifstream fin(input_file_path); if (!fin.is_open()) { std::cerr << "Can't open the file " << input_file_path << "\n"; return lineNum; } while (!fin.eof()) { std::string line; getline(fin, line); Trim(line); if (!IsEmptyString(line)) { lines.push_back(line); lineNum++; } } return lineNum; }
static void getMadString( mad_reg_set_data *data, mad_registers *regs, int i, RegStringCreateData *create ) { mad_type_handle mtype; mad_type_info mti; mad_radix radix; const mad_reg_info *rinfo; void *value; unsigned max_len; const char *descript; MADRegSetDisplayGetPiece( data, regs, i, &descript, &( create[i].maxd ), &rinfo, &mtype, &( create[i].length ) ); if ( create[i].maxd == 0 && descript != NULL ){ create[i].maxd = strlen( descript ); } if ( descript != NULL && IsEmptyString( descript ) == FALSE ){ strcpy( create[i].buffer, descript ); create[i].maxd ++; } else { create[i].buffer[0] = '\0'; create[i].maxd = 0; } if( create[i].length == 0 && rinfo != NULL ) { create[i].length = getMADMaxFormatWidth(mtype); } if( rinfo != NULL ) { MADTypeInfo( rinfo->type, &mti ); value = alloca( BITS2BYTES( mti.b.bits ) ); BitGet( value, (unsigned char *)regs, rinfo->bit_start, rinfo->bit_size ); radix = MADTypePreferredRadix( mtype ); max_len = create[i].length + 1; MADTypeHandleToString( radix, mtype, value, create[i].value, &max_len ); } else { create[i].value[0] = '\0'; } }
// Check if machine has additions installed bool CVBoxMachine::AdditionsActive() { if (!m_spMachine) return false; CComPtr<ISession> spSession; HRESULT hr=spSession.CoCreateInstance(__uuidof(Session)); if (FAILED(hr)) return false; // Open existing session if (FAILED(m_spMachine->LockMachine(spSession, LockType_Shared))) //if (FAILED(m_spVirtualBox->OpenExistingSession(spSession, m_bstrMachineID))) return false; CComPtr<IConsole> spConsole; if (FAILED(spSession->get_Console(&spConsole)) || !spConsole) { spSession->UnlockMachine(); return false; } CComPtr<IGuest> spGuest; if (FAILED(spConsole->get_Guest(&spGuest)) || !spGuest) { spSession->UnlockMachine(); return false; } CComBSTR bstrAdditionsVersion; spGuest->get_AdditionsVersion(&bstrAdditionsVersion); spSession->UnlockMachine(); return !IsEmptyString(bstrAdditionsVersion); }
static CUniString EscapeString(const wchar_t* psz, bool bValue, bool bForceQuotes=false) { if (IsEmptyString(psz)) return L"\"\""; if (bValue) { // Check if all digits const wchar_t* p=psz; while (p[0]) { if (!iswdigit(p[0])) break; p++; } // Yes! if (!p[0]) return psz; } CUniString str; bool bNeedQuotes=!!iswdigit(psz[0]) || bForceQuotes; const wchar_t* p=psz; while (p[0]) { if (!iswalnum(p[0])) bNeedQuotes=true; switch (p[0]) { case L'\\': str+=L"\\\\"; break; case L'\"': str+=L"\\\""; break; case L'\n': str+=L"\\n"; break; case L'\r': str+=L"\\r"; break; case L'\t': str+=L"\\t"; break; default: str.Append(p, 1); break; } p++; } if (bNeedQuotes) str=Format(L"\"%s\"", str.sz()); return str; }
int main(int iArgCount, char *pszArgs[]) { int iVarLength = 0; FILE *pInFile = stdin; char *pszMailRoot; char szMailRoot[SYS_MAX_PATH] = ""; /* Initialize time */ tzset(); if ((pszMailRoot = SysGetEnv(ENV_MAIL_ROOT)) == NULL || (iVarLength = (int)strlen(pszMailRoot)) == 0) { free(pszMailRoot); fprintf(stderr, "cannot find environment variable: %s\n", ENV_MAIL_ROOT); return 1; } StrSNCpy(szMailRoot, pszMailRoot); if (szMailRoot[iVarLength - 1] != SYS_SLASH_CHAR) strcat(szMailRoot, SYS_SLASH_STR); free(pszMailRoot); /* Parse command line */ int i; bool bExtractRcpts = false; bool bXMailFormat = false; bool bDotMode = true; char szMailFrom[256] = ""; char szExtMailFrom[256] = ""; char szInputFile[SYS_MAX_PATH] = ""; char szRcptFile[SYS_MAX_PATH] = ""; SysGetUserAddress(szMailFrom, sizeof(szMailFrom) - 1, ENV_DEFAULT_DOMAIN); for (i = 1; i < iArgCount; i++) { if (strcmp(pszArgs[i], "--") == 0) { ++i; break; } if (strcmp(pszArgs[i], "--rcpt-file") == 0) { if (++i < iArgCount) StrSNCpy(szRcptFile, pszArgs[i]); } else if (strcmp(pszArgs[i], "--xinput-file") == 0) { if (++i < iArgCount) { StrSNCpy(szInputFile, pszArgs[i]); bXMailFormat = true; } } else if (strcmp(pszArgs[i], "--input-file") == 0) { if (++i < iArgCount) StrSNCpy(szInputFile, pszArgs[i]); } else if (strcmp(pszArgs[i], "-i") == 0 || strcmp(pszArgs[i], "-oi") == 0) { bDotMode = false; } else if (strcmp(pszArgs[i], "-t") == 0) { bExtractRcpts = true; } else if (strncmp(pszArgs[i], "-f", 2) == 0) { if (pszArgs[i][2] != '\0') CopyAddress(szMailFrom, pszArgs[i] + 2, sizeof(szMailFrom) - 1); else if ((i + 1) < iArgCount) { CopyAddress(szMailFrom, pszArgs[i + 1], sizeof(szMailFrom) - 1); i++; } } else if (strncmp(pszArgs[i], "-F", 2) == 0) { if (pszArgs[i][2] != '\0') StrSNCpy(szExtMailFrom, pszArgs[i] + 2); else if (i + 1 < iArgCount) { StrSNCpy(szExtMailFrom, pszArgs[i + 1]); i++; } char const *pszOpen = strchr(szExtMailFrom, '<'); if (pszOpen == NULL) CopyAddress(szMailFrom, szExtMailFrom, sizeof(szMailFrom) - 1); else { char szTmpMailFrom[256]; StrSNCpy(szTmpMailFrom, pszOpen + 1); char *pszClose = (char *) strchr(szTmpMailFrom, '>'); if (pszClose != NULL) *pszClose = '\0'; CopyAddress(szMailFrom, szTmpMailFrom, sizeof(szMailFrom) - 1); } } else if (strncmp(pszArgs[i], "-o", 2) == 0) { } else if (strcmp(pszArgs[i], "-L") == 0 || strcmp(pszArgs[i], "-O") == 0 || strcmp(pszArgs[i], "-R") == 0 || strcmp(pszArgs[i], "-X") == 0 || strcmp(pszArgs[i], "-V") == 0 || strcmp(pszArgs[i], "-N") == 0 || strncmp(pszArgs[i], "-qG", 3) == 0 || strncmp(pszArgs[i], "-q!", 3) == 0) { if (i + 1 < iArgCount) i++; } else break; } /* Save recipients index and counter */ int iRcptIndex, iRcptCount; iRcptIndex = Min(i, iArgCount); iRcptCount = iArgCount - iRcptIndex; /* Check if recipients are supplied */ if (!bExtractRcpts && iRcptCount == 0 && IsEmptyString(szRcptFile)) { fprintf(stderr, "empty recipient list\n"); return 2; } if (!IsEmptyString(szInputFile)) { if ((pInFile = fopen(szInputFile, "rb")) == NULL) { perror(szInputFile); return 3; } } /* Check if the sender is specified */ if (IsEmptyString(szMailFrom)) { char const *pszUser = SysGetEnv(ENV_USER); if (pszUser == NULL) pszUser = "******"; CopyAddress(szMailFrom, pszUser, sizeof(szMailFrom) - 1); } /* Create file name */ char szHostName[256] = ""; char szDataFile[SYS_MAX_PATH] = ""; char szMailFile[SYS_MAX_PATH] = ""; SysGetHostName(szHostName, sizeof(szHostName) - 1); SysSNPrintf(szDataFile, sizeof(szDataFile), "%s%s%lu000.%lu.%s", szMailRoot, LOCAL_TEMP_SUBPATH, (unsigned long) time(NULL), SysGetProcessId(), szHostName); SysSNPrintf(szMailFile, sizeof(szMailFile), "%s.mail", szDataFile); /* Open raw data file */ FILE *pDataFile = fopen(szDataFile, "w+b"); if (pDataFile == NULL) { perror(szDataFile); if (pInFile != stdin) fclose(pInFile); return 4; } /* Open maildrop file */ FILE *pMailFile = fopen(szMailFile, "wb"); if (pMailFile == NULL) { perror(szMailFile); fclose(pDataFile); remove(szDataFile); if (pInFile != stdin) fclose(pInFile); return 5; } fprintf(pMailFile, "mail from:<%s>\r\n", szMailFrom); for (i = iRcptIndex; i < iArgCount; i++) { char szAddr[256]; CopyAddress(szAddr, pszArgs[i], sizeof(szAddr) - 1); fprintf(pMailFile, "rcpt to:<%s>\r\n", szAddr); } int iLine; bool bInHeaders = true; bool bHasFrom = false; bool bHasDate = false; bool bRcptSource = false; bool bNoEmit = false; char szBuffer[1536]; for (iLine = 0; fgets(szBuffer, sizeof(szBuffer) - 1, pInFile) != NULL; iLine++) { int iLineLength = (int)strlen(szBuffer); for (; iLineLength > 0 && (szBuffer[iLineLength - 1] == '\r' || szBuffer[iLineLength - 1] == '\n'); iLineLength--); szBuffer[iLineLength] = '\0'; /* Is it time to stop reading ? */ if (bDotMode && strcmp(szBuffer, ".") == 0) break; /* Decode XMail spool file format */ if (bXMailFormat) { if (strcmp(szBuffer, MAIL_DATA_TAG) == 0) bXMailFormat = false; continue; } /* Extract mail from */ if (bInHeaders) { bool bStraightFile = false; if ((iLine == 0) && !IsRFC822HeaderLine(szBuffer)) bStraightFile = true; if (bStraightFile || iLineLength == 0) { bInHeaders = false; bNoEmit = false; /* Add mail from (if not present) */ if (!bHasFrom) { if (strlen(szExtMailFrom) != 0) fprintf(pDataFile, "From: %s\r\n", szExtMailFrom); else fprintf(pDataFile, "From: <%s>\r\n", szMailFrom); } /* Add date (if not present) */ if (!bHasDate) { char szDate[128] = ""; GetTimeStr(szDate, sizeof(szDate) - 1, time(NULL)); fprintf(pDataFile, "Date: %s\r\n", szDate); } if (bStraightFile) fprintf(pDataFile, "\r\n"); } if (szBuffer[0] == ' ' || szBuffer[0] == '\t') { if (bExtractRcpts && bRcptSource) { int iRcptCurr = EmitRecipients(pMailFile, szBuffer); if (iRcptCurr > 0) iRcptCount += iRcptCurr; } } else if (iLineLength > 0) { bNoEmit = (strnicmp(szBuffer, "Bcc:", 4) == 0); bRcptSource = strnicmp(szBuffer, "To:", 3) == 0 || strnicmp(szBuffer, "Cc:", 3) == 0 || strnicmp(szBuffer, "Bcc:", 4) == 0; if (bExtractRcpts && bRcptSource) { int iRcptCurr = EmitRecipients(pMailFile, szBuffer); if (iRcptCurr > 0) iRcptCount += iRcptCurr; } if (!bHasFrom && strnicmp(szBuffer, "From:", 5) == 0) bHasFrom = true; if (!bHasDate && strnicmp(szBuffer, "Date:", 5) == 0) bHasDate = true; } } if (!bNoEmit) fprintf(pDataFile, "%s\r\n", szBuffer); } /* Close input file if different from stdin */ if (pInFile != stdin) fclose(pInFile); /* Dump recipient file */ if (!IsEmptyString(szRcptFile)) { FILE *pRcptFile = SafeOpenFile(szRcptFile, "rb"); if (pRcptFile == NULL) { perror(szRcptFile); fclose(pDataFile); remove(szDataFile); fclose(pMailFile); remove(szMailFile); return 6; } while (fgets(szBuffer, sizeof(szBuffer) - 1, pRcptFile) != NULL) { int iLineLength = (int)strlen(szBuffer); for (; iLineLength > 0 && (szBuffer[iLineLength - 1] == '\r' || szBuffer[iLineLength - 1] == '\n'); iLineLength--); szBuffer[iLineLength] = '\0'; if (iLineLength >= MAX_ADDR_NAME) continue; /* [i_a] '@' is also accepted in the section before the '<email-address>', e.g. "loony@toones <*****@*****.**>" Besides, this code must be able to handle lines like 'from bla <*****@*****.**>; via blub ([email protected]); etc.' */ char const *lt_p = strchr(szBuffer, '<'); char const *gt_p = (!lt_p ? lt_p : strchr(lt_p + 1, '>')); char const *pszAt = strchr(lt_p ? lt_p + 1 : szBuffer, '@'); while (lt_p && gt_p && pszAt) { if (pszAt > gt_p) { lt_p = strchr(lt_p + 1, '<'); gt_p = (!lt_p ? lt_p : strchr(lt_p + 1, '>')); pszAt = (!lt_p ? /* copout for bad line */ strchr(szBuffer, '@') : strchr(lt_p + 1, '@')); } else { break; } } if (pszAt == NULL) continue; char szRecipient[MAX_ADDR_NAME] = ""; if (AddressFromAtPtr(pszAt, szBuffer, szRecipient, sizeof(szRecipient)) != NULL) { fprintf(pMailFile, "rcpt to:<%s>\r\n", szRecipient); ++iRcptCount; } } fclose(pRcptFile); } /* Check the number of recipients */ if (iRcptCount == 0) { fprintf(stderr, "empty recipient list\n"); fclose(pDataFile); remove(szDataFile); fclose(pMailFile); remove(szMailFile); return 7; } /* Empty line separator between maildrop header and data */ fprintf(pMailFile, "\r\n"); /* Append data file */ rewind(pDataFile); unsigned int uReaded; do { if (((uReaded = (unsigned int)fread(szBuffer, 1, (int)sizeof(szBuffer), pDataFile)) != 0) && (fwrite(szBuffer, 1, uReaded, pMailFile) != uReaded)) { perror(szMailFile); fclose(pDataFile); remove(szDataFile); fclose(pMailFile); remove(szMailFile); return 8; } } while (uReaded == sizeof(szBuffer)); fclose(pDataFile); remove(szDataFile); /* Sync and close the mail file */ if (SysFileSync(pMailFile) < 0 || fclose(pMailFile)) { remove(szMailFile); fprintf(stderr, "cannot write file: %s\n", szMailFile); return 9; } /* Move the mail file */ char szDropFile[SYS_MAX_PATH]; SysSNPrintf(szDropFile, sizeof(szDropFile), "%s%s%lu000.%lu.%s", szMailRoot, LOCAL_SUBPATH, (unsigned long) time(NULL), SysGetProcessId(), szHostName); if (SysMoveFile(szMailFile, szDropFile) < 0) { remove(szMailFile); fprintf(stderr, "cannot move file: %s\n", szMailFile); return 10; } return 0; }