DynStr *DynStrFromCharP3(const char_t *strOne, const char_t *strTwo, const char_t *strThree) { ulong_t bufSize; DynStr * dstr; DynStr * dstrNew; ulong_t strOneLen, strTwoLen, strThreeLen; assert(NULL!=strOne); assert(NULL!=strTwo); assert(NULL!=strThree); strOneLen = tstrlen(strOne); strTwoLen = tstrlen(strTwo); strThreeLen = tstrlen(strThree); bufSize = strOneLen + strTwoLen + strThreeLen + 1; dstr = DynStrFromCharP(strOne, bufSize); if (NULL==dstr) return NULL; dstrNew = DynStrAppendCharPBuf(dstr, strTwo, strTwoLen); assert(NULL != dstrNew); dstrNew = DynStrAppendCharPBuf(dstr, strThree, strThreeLen); assert(NULL != dstrNew); assert(dstrNew == dstr); assert(0==DynStrLeft(dstr)); return dstr; }
/* --------- BUILDMENU Message --------- */ static void BuildMenuMsg(WINDOW wnd, PARAM p1) { int offset = 3; reset_menubar(wnd); mctr = 0; ActiveMenuBar = (MBAR *) p1; ActiveMenu = ActiveMenuBar->PullDown; while (ActiveMenu->Title != NULL && ActiveMenu->Title != (void*)-1) { char *cp; if (tstrlen(GetText(wnd)+offset) < strlen(ActiveMenu->Title)+3) break; GetText(wnd) = DFrealloc(GetText(wnd), (tstrlen(GetText(wnd))+5) * sizeof(ATTRCHR)); memmove(GetText(wnd) + offset+4, GetText(wnd) + offset, (tstrlen(GetText(wnd)+offset)+1) * sizeof(ATTRCHR)); CopyCommand(GetText(wnd)+offset,ActiveMenu->Title,FALSE, wnd->WindowColors [STD_COLOR] [FG], wnd->WindowColors [STD_COLOR] [BG]); menu[mctr].x1 = offset; offset += strlen(ActiveMenu->Title) + (MSPACE); menu[mctr].x2 = offset-MSPACE - 1; cp = strchr(ActiveMenu->Title, SHORTCUTCHAR); if (cp) menu[mctr].sc = tolower(*(cp+1)); mctr++; ActiveMenu++; } ActiveMenu = ActiveMenuBar->PullDown; }
DynStr * DynStrAppendCharP2(DynStr *dstr, const char_t *str1, const char_t *str2) { if (NULL == DynStrAppendData(dstr, (const char*)str1, tstrlen(str1)*sizeof(char_t))) return NULL; if (NULL == DynStrAppendData(dstr, (const char*)str2, tstrlen(str2)*sizeof(char_t))) return NULL; return dstr; }
static int get_capture_config(const tchar *config_file, struct capture_config *config, int add_flags, const tchar *fs_source_path) { int ret; tchar *tmp_config_file = NULL; memset(config, 0, sizeof(*config)); /* For WIMBoot capture, check for default capture configuration file * unless one was explicitly specified. */ if (!config_file && (add_flags & WIMLIB_ADD_FLAG_WIMBOOT)) { /* XXX: Handle loading file correctly when in NTFS volume. */ size_t len = tstrlen(fs_source_path) + tstrlen(wimboot_cfgfile); tmp_config_file = MALLOC((len + 1) * sizeof(tchar)); struct stat st; tsprintf(tmp_config_file, T("%"TS"%"TS), fs_source_path, wimboot_cfgfile); if (!tstat(tmp_config_file, &st)) { config_file = tmp_config_file; add_flags &= ~WIMLIB_ADD_FLAG_WINCONFIG; } else { WARNING("\"%"TS"\" does not exist.\n" " Using default capture configuration!", tmp_config_file); } } if (add_flags & WIMLIB_ADD_FLAG_WINCONFIG) { /* Use Windows default. */ if (config_file) return WIMLIB_ERR_INVALID_PARAM; ret = read_capture_config(T("wincfg"), wincfg, sizeof(wincfg) - 1, config); } else if (config_file) { /* Use the specified configuration file. */ ret = read_capture_config(config_file, NULL, 0, config); } else { /* ... Or don't use any configuration file at all. No files * will be excluded from capture, all files will be compressed, * etc. */ ret = 0; } FREE(tmp_config_file); return ret; }
inline CValue::CValue(const CString& sValue) : m_eType(MDST_STRING) , m_bNull(false) , m_sValue(new tchar[tstrlen(sValue)+1]) { tstrcpy(m_sValue, sValue); }
void CRow::Write(WCL::IOutputStream& rStream) { // Get the row data size and start address. size_t nSize = m_oTable.m_vColumns.AllocSize(); byte* pData = reinterpret_cast<byte*>(m_aFields + m_nColumns); // Write the null values. for (size_t i=0; i < m_nColumns; ++i) rStream.Write(&m_aFields[i].m_bNull, sizeof(bool)); // Write the data values. rStream.Write(pData, nSize); // Write any MDCT_VARSTR field values. for (size_t i = 0; i < m_nColumns; ++i) { if (m_aFields[i].m_oColumn.ColType() == MDCT_VARSTR) { size_t nChars = tstrlen(m_aFields[i].m_pString); size_t nBytes = Core::numBytes<tchar>(nChars+1); // Read the string length. rStream.Write(&nChars, sizeof(size_t)); // Write the string. rStream.Write(m_aFields[i].m_pString, nBytes); } } // Reset status flag. m_eStatus = ORIGINAL; }
DynStr *DynStrFromCharP__(const char_t *str, ulong_t initBufSize, const char* file, int line) { ulong_t strLen = tstrlen(str); ulong_t bufSize = (strLen+1)*sizeof(char_t); DynStr * dstr; if (bufSize < initBufSize) bufSize = initBufSize; //TODO: need to figure this for wince //dstr = (DynStr*)malloc__(sizeof(DynStr), file, line); dstr = (DynStr*)malloc(sizeof(DynStr)); if (NULL == dstr) return NULL; if (NULL == DynStrInit(dstr, bufSize)) { free(dstr); return NULL; } dstr->strLen = strLen; memmove( dstr->str, str, strLen + 1); return dstr; }
inline void Convertor<T>::getArrayData(ExecutionContext *context, BYTE * cBuf, BYTE *pbBuf, int &strLen, DataCharset charset) { dprintf("+%s::getArrayData cBuf=%p, strLen=%i\n", TypeName.c_str(), cBuf ,strLen); if (cBuf == NULL) throw RuntimeException(context, TypeName + "::getArrayData cBuf == NULL"); type_t *strValue = (type_t*)cBuf; dprintf("strLen=%i, strValue=%p, strValue='%s'\n", strLen, strValue, strValue); int len; if (charset == INV_CHARSET) { len = strlenStoT(context, strValue); } else if (charset == CHARSET) { len = tstrlen(strValue); } else { // DC_BINARY len = strLen; } if (strLen > 0) { if (len > strLen) // copy max strLen chars len = strLen; dprintf("len=%i\n", len); if (charset == INV_CHARSET) { convertStoT(context, strValue, len, /*out*/(inv_type_t*)pbBuf); } else { memcpy(pbBuf, strValue, len * sizeof(type_t)); } } strLen = len; dprintf("-%s::getArrayData\n", TypeName.c_str()); }
size_t CIniFile::ReadSection(const tchar* pszSection, CStrArray& astrEntries) { ASSERT(pszSection); // Allocate initial buffer. size_t nChars = 1024; tchar* pszEntries = static_cast<tchar*>(alloca(Core::numBytes<tchar>(nChars+1))); // Read all entries, reallocating if necessary... while (::GetPrivateProfileSection(pszSection, pszEntries, static_cast<DWORD>(nChars), m_strPath) >= (nChars-2)) { // Double the buffer size. nChars *= 2; pszEntries = static_cast<tchar*>(alloca(Core::numBytes<tchar>(nChars+1))); } // For all strings. while (*pszEntries != TXT('\0')) { astrEntries.Add(pszEntries); pszEntries += tstrlen(pszEntries) + 1; } return astrEntries.Size(); }
/* * canonicalize_wim_path() - Given a user-provided path to a file within a WIM * image, translate it into a "canonical" path. * * - Translate both types of slash into a consistent type (WIM_PATH_SEPARATOR). * - Collapse path separators. * - Add leading slash if missing. * - Strip trailing slashes. * * Examples (with WIM_PATH_SEPARATOR == '/'): * * => / [ either NULL or empty string ] * / => / * \ => / * hello => /hello * \hello => /hello * \hello => /hello * /hello/ => /hello * \hello/ => /hello * /hello//1 => /hello/1 * \\hello\\1\\ => /hello/1 */ tchar * canonicalize_wim_path(const tchar *wim_path) { const tchar *in; tchar *out; tchar *result; in = wim_path; if (!in) in = T(""); result = MALLOC((1 + tstrlen(in) + 1) * sizeof(result[0])); if (!result) return NULL; out = result; /* Add leading slash if missing */ if (!is_any_path_separator(*in)) *out++ = WIM_PATH_SEPARATOR; do_canonicalize_path(in, out); return result; }
bool StringSelectForm::handleOpen() { bool res = MoriartyForm::handleOpen(); if ((NULL==subtitle_) || (0==tstrlen(subtitle_))) subtitleField_.hide(); else { subtitleField_.setText(subtitle_); subtitleField_.show(); } setTitle(title_); assert(NULL != itemRenderer_); choicesList_.setItemHeight(13); choicesList_.setUpBitmapId(upBitmap); choicesList_.setDownBitmapId(downBitmap); choicesList_.setItemRenderer(itemRenderer_, ExtendedList::redrawNot); if (0 != choicesList_.itemsCount()) choicesList_.setSelection(0); RectangleType r; getScreenBounds(r); resize(r); return res; }
void StringSelectForm::resize(const ArsRectangle& screenBounds) { ArsRectangle bounds(screenBounds.x() + 2, screenBounds.y() + 2, screenBounds.width() - 4, screenBounds.height() - 4); setBounds(bounds); bounds.x() = 0; bounds.width() = screenBounds.width() - 4; if ((NULL == subtitle_) || (0==tstrlen(subtitle_))) { bounds.y() = 16; bounds.height() = screenBounds.height() - 40; } else { bounds.y() = 32; bounds.height() = screenBounds.height() - 56; } choicesList_.setBounds(bounds); subtitleField_.anchor(screenBounds, anchorRightEdge, 6, anchorNot, 0); okButton_.anchor(screenBounds, anchorNot, 0, anchorTopEdge, 18); cancelButton_.anchor(screenBounds, anchorNot, 0, anchorTopEdge, 18); update(); }
bool onStartTestCase(const tchar* name) { ASSERT(tstrlen(name) != 0); ASSERT(s_currentTestCase.empty()); ASSERT(s_currentTestCaseAsserts.empty()); ASSERT(!exists<tstring>(s_executed, name)); if (s_verbose) tcout << TXT(" > ") << name << std::endl; s_currentResult = UNKNOWN; s_currentTestCase = name; if (s_setup != nullptr) { try { s_setup(); } catch(const Core::Exception& e) { processSetupTeardownException(TXT("SetUp"), e.twhat()); return false; } catch (...) { processSetupTeardownException(TXT("SetUp"), TXT("UNKNOWN")); return false; } } return true; }
//------------------------------------------------------------------------ void StringListParameter::appendString (const String128 string) { int32 length = tstrlen (string); TChar* buffer = (TChar*)malloc ((length + 1) * sizeof (TChar)); memcpy (buffer, string, length * sizeof (TChar)); buffer[length] = 0; strings.add (buffer); info.stepCount++; }
bool CTextReport::SendText(const tchar* pszText) { size_t nChars = tstrlen(pszText); // Write string. m_rStream.Write(pszText, Core::numBytes<tchar>(nChars)); // Add CR/LF to string. SendLineBreak(); return true; }
void PediaMainForm::changeLanguage(const char_t* code) { PediaPreferences& prefs = application().preferences().pediaPrefs; if (0 != tstrcmp(code, prefs.languageCode)) { prefs.articleCount = prefs.articleCountNotChecked; memmove(prefs.languageCode, code, tstrlen(code) * sizeof(char_t)); prefs.dbDate[0] = '\0'; } setDisplayMode(showAbout); update(); }
/* * Given a null-terminated pathname pattern @pat that has been read from line * @line_no of the file @path, validate and canonicalize the pattern. * * On success, returns 0. * On failure, returns WIMLIB_ERR_INVALID_CAPTURE_CONFIG. * In either case, @pat may have been modified in-place (and possibly * shortened). */ int mangle_pat(tchar *pat, const tchar *path, unsigned long line_no) { if (!is_any_path_separator(pat[0]) && pat[0] != T('\0') && pat[1] == T(':')) { /* Pattern begins with drive letter. */ if (!is_any_path_separator(pat[2])) { /* Something like c:file, which is actually a path * relative to the current working directory on the c: * drive. We require paths with drive letters to be * absolute. */ ERROR("%"TS":%lu: Invalid pattern \"%"TS"\":\n" " Patterns including drive letters must be absolute!\n" " Maybe try \"%"TC":%"TC"%"TS"\"?\n", path, line_no, pat, pat[0], OS_PREFERRED_PATH_SEPARATOR, &pat[2]); return WIMLIB_ERR_INVALID_CAPTURE_CONFIG; } WARNING("%"TS":%lu: Pattern \"%"TS"\" starts with a drive " "letter, which is being removed.", path, line_no, pat); /* Strip the drive letter. */ tmemmove(pat, pat + 2, tstrlen(pat + 2) + 1); } /* Collapse consecutive path separators, and translate both / and \ into * / (UNIX) or \ (Windows). * * Note: we expect that this function produces patterns that can be used * for both filesystem paths and WIM paths, so the desired path * separators must be the same. */ BUILD_BUG_ON(OS_PREFERRED_PATH_SEPARATOR != WIM_PATH_SEPARATOR); do_canonicalize_path(pat, pat); /* Relative patterns can only match file names, so they must be * single-component only. */ if (pat[0] != OS_PREFERRED_PATH_SEPARATOR && tstrchr(pat, OS_PREFERRED_PATH_SEPARATOR)) { ERROR("%"TS":%lu: Invalid pattern \"%"TS"\":\n" " Relative patterns can only include one path component!\n" " Maybe try \"%"TC"%"TS"\"?", path, line_no, pat, OS_PREFERRED_PATH_SEPARATOR, pat); return WIMLIB_ERR_INVALID_CAPTURE_CONFIG; } return 0; }
bool registerTestSet(const tchar* name, TestSetFn runner) { ASSERT(tstrlen(name) != 0); ASSERT(runner != nullptr); TestSets& sets = getTestSetCollection(); ASSERT(sets.find(name) == sets.end()); sets.insert(std::make_pair(name, runner)); return true; }
static String GetDbPath(const char_t *dbName) { String dirPath; bool fOk = GetSpecialFolderPath(dirPath); if (!fOk) return _T(""); String fullPath(dirPath); fullPath.append(_T("\\")); char_t *tmpDbName = new char_t[tstrlen(dbName)+1]; wcscpy(tmpDbName, dbName); for (unsigned int i=0; i<tstrlen(tmpDbName); i++) { if(tmpDbName[i]==' ') tmpDbName[i]='_'; } fullPath.append(tmpDbName); delete [] tmpDbName; return fullPath; }
inline CValue::CValue(const CValue& oValue) : m_eType(oValue.m_eType) , m_bNull(oValue.m_bNull) { if (m_eType != MDST_STRING) { memcpy(m_uValue, oValue.m_uValue, sizeof(m_uValue)); } else { m_sValue = new tchar[tstrlen(oValue.m_sValue)+1]; tstrcpy(m_sValue, oValue.m_sValue); } }
// return a C-compatible copy of the string. It might be different // than real data if the data has embedded 0, which for C means // end of string char_t * DynStrCharPCopy(DynStr *dstr) { ulong_t strLen; char_t *result; if (NULL == dstr->str) strLen = 0; else strLen = tstrlen(dstr->str); result = (char_t*)malloc((strLen+1) * sizeof(char_t)); if (NULL == result) return NULL; if (strLen > 0) memmove(result, dstr->str, strLen); result[strLen] = _T('\0'); return result; }
inline const CValue& CValue::operator=(const CValue& oValue) { m_eType = oValue.m_eType; m_bNull = oValue.m_bNull; if (m_eType != MDST_STRING) { memcpy(m_uValue, oValue.m_uValue, sizeof(m_uValue)); } else { m_sValue = new tchar[tstrlen(oValue.m_sValue)+1]; tstrcpy(m_sValue, oValue.m_sValue); } return *this; }
void MoviesMainForm::prepareTheatreInfo(uint_t theatreRow) { assert(NULL != theatres); theatreRow *= 2; assert(theatreRow < theatres->getItemsCount()); const char_t* theatreName = theatres->getItemText(theatreRow, theatreNameIndex); const char_t* theatreAddress = theatres->getItemText(theatreRow, theatreAddressIndex); DefinitionModel* model = new_nt DefinitionModel(); if (NULL == model) { application().alert(notEnoughMemoryAlert); return; } Definition::Elements_t& elems = model->elements; TextElement* text; elems.push_back(text=new TextElement(theatreName)); text->setStyle(StyleGetStaticStyle(styleNamePageTitle)); if (0 != tstrlen(theatreAddress)) { elems.push_back(new LineBreakElement()); elems.push_back(text=new TextElement(theatreAddress)); } elems.push_back(new LineBreakElement()); const uint_t moviesRow = theatreRow + 1; const uint_t moviesCount = theatres->getItemElementsCount(moviesRow)/2; for (uint_t i = 0; i<moviesCount; ++i) { const char_t* movieTitle = theatres->getItemText(moviesRow, i*2); const char_t* movieHours = theatres->getItemText(moviesRow, i*2+1); BulletElement* bull; elems.push_back(bull = new BulletElement()); bull->setStyle(StyleGetStaticStyle(styleNameHeader)); elems.push_back(text=new TextElement(movieTitle)); text->setParent(bull); text->setStyle(StyleGetStaticStyle(styleNameHeader)); text->setHyperlink(buildUrl(urlSchemaMovie, movieTitle), hyperlinkUrl); elems.push_back(new LineBreakElement()); elems.push_back(text=new TextElement(movieHours)); text->setParent(bull); } infoRenderer_.setModel(model, Definition::ownModel); }
static int getPrefItemSize(PrefItem& item) { switch (item.type) { case pitBool: return sizeof(bool); case pitInt: return sizeof(int); case pitLong: return sizeof(long); case pitUInt16: return sizeof(ushort_t); case pitUInt32: return sizeof(ulong_t); case pitStr: return tstrlen(item.value.strVal)*2+2; } return 0; }
bool CTextReport::SendHeading(const tchar* pszText) { size_t nChars = tstrlen(pszText); // Write string. m_rStream.Write(pszText, Core::numBytes<tchar>(nChars)); // Add CR/LF to string. SendLineBreak(); // Underline string. for(size_t i = 0; i < nChars; i++) m_rStream.Write(TXT("="), Core::numBytes<tchar>(1)); // Add CR/LF to underline. SendLineBreak(); return true; }
void CTrayIcon::Add(const CWnd& oWnd, uint nTrayID, uint nMsgID, uint nRscID, const tchar* pszToolTip) { ASSERT(m_hWnd == NULL); ASSERT(m_nTrayID == 0); ASSERT(m_nMsgID == 0); ASSERT(oWnd.Handle() != NULL); ASSERT(nTrayID != 0); ASSERT((pszToolTip == nullptr) || (tstrlen(pszToolTip) < MAX_TIP_LEN)); // Save parameters. m_hWnd = oWnd.Handle(); m_nTrayID = nTrayID; m_nMsgID = nMsgID; // Load the icon resource. CIcon oIcon(nRscID, ICON_WIDTH, ICON_HEIGHT); uint nFlags = NIF_ICON; // Work out which other fields to set. if (m_nMsgID != 0) nFlags |= NIF_MESSAGE; if (pszToolTip != nullptr) nFlags |= NIF_TIP; NOTIFYICONDATA oData = { 0 }; // Fill in the message structure. oData.cbSize = sizeof(oData); oData.hWnd = m_hWnd; oData.uID = m_nTrayID; oData.uFlags = nFlags; oData.uCallbackMessage = m_nMsgID; oData.hIcon = oIcon.Handle(); if (pszToolTip != nullptr) tstrncpy(oData.szTip, pszToolTip, MAX_TIP_LEN-1); // Send message. ::Shell_NotifyIcon(NIM_ADD, &oData); }
void wimlib_debug(const tchar *file, int line, const char *func, const tchar *format, ...) { va_list va; tchar buf[tstrlen(file) + strlen(func) + 30]; static bool debug_enabled = false; if (!debug_enabled) { char *value = getenv("WIMLIB_DEBUG"); if (!value || strcmp(value, "0")) debug_enabled = true; else return; } tsprintf(buf, T("[%"TS" %d] %s(): "), file, line, func); va_start(va, format); wimlib_vmsg(buf, format, va, false); va_end(va); }
void onStartTestSet(const tchar* name) { ASSERT(tstrlen(name) != 0); ASSERT(s_currentTestCase.empty()); ASSERT(s_currentTestCaseAsserts.empty()); if (!s_quiet) { tcout << name << std::endl; if (!s_verbose) tcout << TXT(" "); } s_currentTestSet = name; s_failures.clear(); s_failuresAsserts.clear(); s_executed.clear(); s_setup = nullptr; s_teardown = nullptr; }
/* Change the name of @dentry to @new_name_tstr. * * This is the journaled version, so it can be rolled back. */ static int journaled_change_name(struct update_command_journal *j, struct wim_dentry *dentry, const tchar *new_name_tstr) { int ret; utf16lechar *new_name; size_t new_name_nbytes; struct update_primitive prim; /* Set the long name. */ ret = tstr_to_utf16le(new_name_tstr, tstrlen(new_name_tstr) * sizeof(tchar), &new_name, &new_name_nbytes); if (ret) return ret; prim.type = CHANGE_FILE_NAME; prim.name.subject = dentry; prim.name.old_name = dentry->file_name; ret = record_update_primitive(j, prim); if (ret) { FREE(new_name); return ret; } dentry->file_name = new_name; dentry->file_name_nbytes = new_name_nbytes; /* Clear the short name. */ prim.type = CHANGE_SHORT_NAME; prim.name.subject = dentry; prim.name.old_name = dentry->short_name; ret = record_update_primitive(j, prim); if (ret) return ret; dentry->short_name = NULL; dentry->short_name_nbytes = 0; return 0; }
void CTrayIcon::Modify(uint nRscID, const tchar* pszToolTip) { ASSERT(m_hWnd != NULL); ASSERT(m_nTrayID != 0); ASSERT(nRscID != 0 || pszToolTip != nullptr); ASSERT((pszToolTip == nullptr) || (tstrlen(pszToolTip) < MAX_TIP_LEN)); uint nFlags = 0; // Work out which fields we're setting. if (nRscID != 0) nFlags |= NIF_ICON; if (pszToolTip != nullptr) nFlags |= NIF_TIP; NOTIFYICONDATA oData = { 0 }; // Fill in the message structure. oData.cbSize = sizeof(oData); oData.hWnd = m_hWnd; oData.uID = m_nTrayID; oData.uFlags = nFlags; oData.uCallbackMessage = m_nMsgID; if (nRscID != 0) { CIcon oIcon(nRscID, ICON_WIDTH, ICON_HEIGHT); oData.hIcon = oIcon.Handle(); } if (pszToolTip != nullptr) tstrncpy(oData.szTip, pszToolTip, MAX_TIP_LEN-1); // Send message. ::Shell_NotifyIcon(NIM_MODIFY, &oData); }