void showDependents( STRINGLIST *q, // list of dependents STRINGLIST *macros // macros in the dependents ) { char *u, *v; char *w; size_t i; struct _finddata_t finddata; NMHANDLE searchHandle; makeMessage(DEPENDENTS_MESSAGE); for (i = 0; q; q = q->next) { char *szFilename; if (_tcschr(q->text, '$')) { u = expandMacros(q->text, ¯os); for (v = _tcstok(u, " \t"); v; v = _tcstok(NULL, " \t")) { if (_tcspbrk(v, "*?")) { if ((szFilename = findFirst(v, &finddata, &searchHandle))) { do { w = prependPath(v, szFilename); printf("%s ", w); i = checkLineLength(i, w); FREE(w); } while ((szFilename = findNext(&finddata, searchHandle))); } } else { printf("%s ", v); i = checkLineLength(i, v); } } FREE(u); } else if (_tcspbrk(q->text, "*?")) { if ((szFilename = findFirst(q->text, &finddata, &searchHandle))) { do { v = prependPath(q->text, szFilename); printf("%s ", v); i = checkLineLength(i, v); FREE(v); } while ((szFilename = findNext(&finddata, searchHandle))); } } else { printf("%s ", q->text); i = checkLineLength(i, q->text); } } }
//------------------------------------------------------------------* static BOOL CheckInitString(LPCTSTR sInit) { if (sInit == NULL || *sInit == L'\0' || _tcspbrk(sInit, NoGoodChars) != NULL) return FALSE; /* if (lstrcmpi(sInit, _T(".")) == 0 || lstrcmpi(sInit, _T("..")) == 0 || lstrcmpi(sInit, _T("CON")) == 0 || lstrcmpi(sInit, _T("PRN")) == 0 || lstrcmpi(sInit, _T("AUX")) == 0 || lstrcmpi(sInit, _T("NUL")) == 0) return FALSE; if (lstrcmpi(_T("COM1"), sInit) <= 0 && lstrcmpi(sInit, _T("COM9")) <= 0 && lstrlen(sInit) == 4) return FALSE; if (lstrcmpi(_T("LPT1"), sInit) <= 0 && lstrcmpi(sInit, _T("LPT9")) <= 0 && lstrlen(sInit) == 4) return FALSE; */ return TRUE; }
FC_TOAPI const TCHAR* FC_TODECL FC_StringAppendUpTo( FC_StringTYP* pData, const TCHAR* pszFrom, const TCHAR* pszStopCharSet, const TCHAR** ppEndPtr ) { const TCHAR* pc; pc = _tcspbrk(pszFrom, pszStopCharSet); if(!pc) pc = pszFrom + _tcslen(pszFrom); //point to the 0-char if(ppEndPtr) *ppEndPtr = pc; //set *ppEndPtr to the char that stopped the append FC_StringAppendChars(pData, pszFrom, pc - pszFrom); //get the next char in pszFrom that is not a stop char while(*pc && _tcschr(pszStopCharSet, *pc)) pc = _tcsinc(pc); return pc; }
// <?xml version="1.0"?> // ^- return pointer //======================================================== // Name : LoadProcessingInstrunction // Desc : loading processing instruction // Param : pszXml - PI string // pi - parser information // Return : advanced string pointer. (error return NULL) //-------------------------------------------------------- // Coder Date Desc // bro 2004-06-14 //======================================================== LPTSTR _tagXMLNode::LoadProcessingInstrunction( LPCTSTR pszXml, LPPARSEINFO pi /*= &piDefault*/ ) { // find the end of pi LPTSTR end = _tcsenistr( pszXml, szXMLPIClose, sizeof(szXMLPIClose)-1, pi ? pi->escape_value : 0 ); if( end == NULL ) return NULL; // process pi if( doc ) { LPTSTR xml = (LPTSTR)pszXml; LPXNode node = new XNode; node->parent = this; node->doc = doc; node->type = XNODE_PI; xml += sizeof(szXMLPIOpen)-1; TCHAR* pTagEnd = _tcspbrk( xml, _T(" ?>") ); _SetString( xml, pTagEnd, &node->name ); xml = pTagEnd; node->LoadAttributes( xml, end, pi ); doc->childs.push_back( node ); } end += sizeof(szXMLPIClose)-1; return end; }
/* * Curl_load_library() * * This is used to dynamically load DLLs using the most secure method available * for the version of Windows that we are running on. * * Parameters: * * filename [in] - The filename or full path of the DLL to load. If only the * filename is passed then the DLL will be loaded from the * Windows system directory. * * Returns the handle of the module on success; otherwise NULL. */ HMODULE Curl_load_library(LPCTSTR filename) { HMODULE hModule = NULL; LOADLIBRARYEX_FN pLoadLibraryEx = NULL; /* Get a handle to kernel32 so we can access it's functions at runtime */ HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32")); if(!hKernel32) return NULL; /* Attempt to find LoadLibraryEx() which is only available on Windows 2000 and above */ pLoadLibraryEx = (LOADLIBRARYEX_FN) GetProcAddress(hKernel32, LOADLIBARYEX); /* Detect if there's already a path in the filename and load the library if there is. Note: Both back slashes and forward slashes have been supported since the earlier days of DOS at an API level although they are not supported by command prompt */ if(_tcspbrk(filename, TEXT("\\/"))) { /** !checksrc! disable BANNEDFUNC 1 **/ hModule = pLoadLibraryEx ? pLoadLibraryEx(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : LoadLibrary(filename); } /* Detect if KB2533623 is installed, as LOAD_LIBARY_SEARCH_SYSTEM32 is only supported on Windows Vista, Windows Server 2008, Windows 7 and Windows Server 2008 R2 with this patch or natively on Windows 8 and above */ else if(pLoadLibraryEx && GetProcAddress(hKernel32, "AddDllDirectory")) { /* Load the DLL from the Windows system directory */ hModule = pLoadLibraryEx(filename, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); } else { /* Attempt to get the Windows system path */ UINT systemdirlen = GetSystemDirectory(NULL, 0); if(systemdirlen) { /* Allocate space for the full DLL path (Room for the null terminator is included in systemdirlen) */ size_t filenamelen = _tcslen(filename); TCHAR *path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen)); if(path && GetSystemDirectory(path, systemdirlen)) { /* Calculate the full DLL path */ _tcscpy(path + _tcslen(path), TEXT("\\")); _tcscpy(path + _tcslen(path), filename); /* Load the DLL from the Windows system directory */ /** !checksrc! disable BANNEDFUNC 1 **/ hModule = pLoadLibraryEx ? pLoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : LoadLibrary(path); } free(path); } } return hModule; }
bool IsBaseName(const TCHAR *path) { assert(path != nullptr); #ifdef WIN32 return _tcspbrk(path, _T("/\\")) == nullptr; #else return StringFind(path, _T('/')) == nullptr; #endif }
bool IsBaseName(const TCHAR *path) { assert(path != NULL); #ifdef WIN32 return _tcspbrk(path, _T("/\\")) == NULL; #else return _tcschr(path, _T('/')) == NULL; #endif }
extern "C" FC_CString& CGT_AppendCMDLFileArg( FC_CString& cmdl, const TCHAR* pszFile ) { if(_tcspbrk(pszFile, _T(" \r\n\t"))) cmdl<<'"'<<pszFile<<'"'; else cmdl<<pszFile; return cmdl; }
bool Path::IsBase() const { assert(!IsNull()); #ifdef WIN32 return _tcspbrk(c_str(), _T("/\\")) == nullptr; #else return StringFind(c_str(), _T('/')) == nullptr; #endif }
// <TAG attr1="value1" attr2='value2' attr3=value3 > // </TAG> // or // <TAG /> // ^- return pointer //======================================================== // Desc : load xml plain text // Param : pszXml - plain xml text // pi = parser information // Return : advanced std::string pointer //======================================================== char* _tagXMLNode::load( const char* pszXml, LPPARSEINFO pi /*= &piDefault*/ ) { char* xml = (char*)pszXml; // initilize parent = NULL; childs.clear(); attrs.clear(); xml = _tcschr( xml, chXMLTagOpen ); if( xml == NULL ) return xml; // Close Tag if( *(xml+1) == chXMLTagPre ) // </Close return xml; // XML Node Tag Name Open xml++; char* pTagEnd = _tcspbrk( xml, " />" ); _Setstring( xml, pTagEnd, &name ); xml = pTagEnd; // Generate XML Attributte List if( xml = loadAttributes( xml, pi ) ) { // alone tag <TAG ... /> if( *xml == chXMLTagPre ) { xml++; if( *xml == chXMLTagClose ) // wel-formed tag return ++xml; else { // error: <TAG ... / > if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_ALONE_NOT_CLOSED; pi->error_string = "Element must be closed."; } // not wel-formed tag return xml; } } else // open/close tag <TAG ..> ... </TAG> // ^- current pointer { // insert if no text value if( this->value.empty() ) { // Text Value char* pEnd = _tcsechr( ++xml, chXMLTagOpen, chXMLEscape ); if( pEnd == NULL ) { if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_CLOSED; pi->error_string = "%s must be closed with </%s>", name; pi->error_string += name; } // error cos not exist CloseTag </TAG> return xml; } bool trim = pi->trim_value; _Setstring( xml, pEnd, &value, trim, chXMLEscape ); xml = pEnd; // TEXTVALUE reference if( pi->entity_value && pi->entitys ) value = pi->entitys->ref2Entity(value.c_str()); } // generate child nodes while( xml && *xml ) { LPXNode node = new XNode; node->parent = this; xml = node->load( xml,pi ); if( node->name.empty() == FALSE ) { std::transform( node->name.begin(), node->name.end(), node->name.begin(), static_cast<int(*)(int)>(::tolower) ); //node->name.MakeLower(); childs.push_back( node ); } else { delete node; } // open/close tag <TAG ..> ... </TAG> // ^- current pointer // CloseTag case if( xml && *xml && *(xml+1) && *xml == chXMLTagOpen && *(xml+1) == chXMLTagPre ) { // </Close> xml+=2; // C if( xml = _tcsskip( xml ) ) { std::string closename; char* pEnd = _tcspbrk( xml, " >" ); if( pEnd == NULL ) { if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_CLOSED; pi->error_string = "it must be closed with"; pi->error_string += name; } // error return xml; } _Setstring( xml, pEnd, &closename ); if( closename == this->name ) { // wel-formed open/close xml = pEnd+1; // return '>' or ' ' after pointer return xml; } else { xml = pEnd+1; // not welformed open/close if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_NESTED; pi->error_string = name + "..." + closename + " is not wel-formed."; } return xml; } } } else // Alone child Tag Loaded { if( xml && this->value.empty() && *xml !=chXMLTagOpen ) { // Text Value char* pEnd = _tcsechr( xml, chXMLTagOpen, chXMLEscape ); if( pEnd == NULL ) { // error cos not exist CloseTag </TAG> if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_CLOSED; pi->error_string = "it must be closed with"+ name; } return xml; } bool trim = pi->trim_value; _Setstring( xml, pEnd, &value, trim, chXMLEscape ); xml = pEnd; //TEXTVALUE if( pi->entity_value && pi->entitys ) value = pi->entitys->ref2Entity(value.c_str()); } } } } } return xml; }
// <TAG attr1="value1" attr2='value2' attr3=value3 > // </TAG> // or // <TAG /> // ^- return pointer //======================================================== // Name : Load // Desc : load xml plain text // Param : pszXml - plain xml text // pi = parser information // Return : advanced string pointer (error return NULL) //-------------------------------------------------------- // Coder Date Desc // bro 2002-10-29 //======================================================== LPTSTR _tagXMLNode::Load( LPCTSTR pszXml, LPPARSEINFO pi /*= &piDefault*/ ) { // Close it Close(); LPTSTR xml = (LPTSTR)pszXml; xml = _tcschr( xml, chXMLTagOpen ); if( xml == NULL ) return NULL; // Close Tag if( *(xml+1) == chXMLTagPre ) // </Close return xml; // Load Other Node before <Tag>(pi, comment, CDATA etc) bool bRet = false; LPTSTR ret = NULL; ret = LoadOtherNodes( this, &bRet, xml, pi ); if( ret != NULL ) xml = ret; if( bRet ) return xml; // XML Node Tag Name Open xml++; TCHAR* pTagEnd = _tcspbrk( xml, _T(" />\t\r\n") ); _SetString( xml, pTagEnd, &name ); xml = pTagEnd; // Generate XML Attributte List if( xml = LoadAttributes( xml, pi ) ) { // alone tag <TAG ... /> if( *xml == chXMLTagPre ) { xml++; if( *xml == chXMLTagClose ) // wel-formed tag return ++xml; else { // error: <TAG ... / > if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_ALONE_NOT_CLOSED; pi->error_string = _T("Element must be closed."); } // not wel-formed tag return NULL; } } else // open/close tag <TAG ..> ... </TAG> // ^- current pointer { // if text value is not exist, then assign value //if( this->value.IsEmpty() || this->value == _T("") ) if( XIsEmptyString( value ) ) { // Text Value TCHAR* pEnd = _tcsechr( ++xml, chXMLTagOpen, pi ? pi->escape_value : 0 ); if( pEnd == NULL ) { if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_CLOSED; pi->error_string.Format(_T("%s must be closed with </%s>"), name ); } // error cos not exist CloseTag </TAG> return NULL; } bool trim = pi->trim_value; TCHAR escape = pi->escape_value; //_SetString( xml, pEnd, &value, trim, pi ? pi->escape_value : 0 ); _SetString( xml, pEnd, &value, trim, escape ); xml = pEnd; // TEXTVALUE reference if( pi->entity_value && pi->entitys ) value = pi->entitys->Ref2Entity(value); } // generate child nodes while( xml && *xml ) { LPXNode node = new XNode; node->parent = this; node->doc = doc; node->type = type; xml = node->Load( xml,pi ); if( node->name.IsEmpty() == FALSE ) { childs.push_back( node ); } else { delete node; } // open/close tag <TAG ..> ... </TAG> // ^- current pointer // CloseTag case if( xml && *xml && *(xml+1) && *xml == chXMLTagOpen && *(xml+1) == chXMLTagPre ) { // </Close> xml+=2; // C if( xml = _tcsskip( xml ) ) { HM::String closename; TCHAR* pEnd = _tcspbrk( xml, _T(" >") ); if( pEnd == NULL ) { if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_CLOSED; pi->error_string.Format(_T("it must be closed with </%s>"), name ); } // error return NULL; } _SetString( xml, pEnd, &closename ); if( closename == this->name ) { // wel-formed open/close xml = pEnd+1; // return '>' or ' ' after pointer return xml; } else { xml = pEnd+1; // 2004.6.15 - example <B> alone tag // now it can parse with attribute 'force_arse' if( pi->force_parse == false ) { // not welformed open/close if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_NESTED; pi->error_string.Format(_T("'<%s> ... </%s>' is not wel-formed."), name, closename ); } return NULL; } } } } else // Alone child Tag Loaded // else ÇؾßÇÏ´ÂÁö ¸»¾Æ¾ßÇÏ´ÂÁö Àǽɰ£´Ù. { //if( xml && this->value.IsEmpty() && *xml !=chXMLTagOpen ) if( xml && XIsEmptyString( value ) && *xml !=chXMLTagOpen ) { // Text Value TCHAR* pEnd = _tcsechr( xml, chXMLTagOpen, pi ? pi->escape_value : 0 ); if( pEnd == NULL ) { // error cos not exist CloseTag </TAG> if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_CLOSED; pi->error_string.Format(_T("it must be closed with </%s>"), name ); } return NULL; } bool trim = pi->trim_value; TCHAR escape = pi->escape_value; //_SetString( xml, pEnd, &value, trim, pi ? pi->escape_value : 0 ); _SetString( xml, pEnd, &value, trim, escape ); xml = pEnd; //TEXTVALUE if( pi->entity_value && pi->entitys ) value = pi->entitys->Ref2Entity(value); } } } } } return xml; }
int CCOMString::FindOneOf(LPCTSTR lpszCharSet) const { LPTSTR lpsz = _tcspbrk(m_pszString, lpszCharSet); return (lpsz == NULL) ? -1 : (int)(lpsz - m_pszString); }
// attr1="value1" attr2='value2' attr3=value3 /> // ^- return pointer //======================================================== // Name : LoadAttributes // Desc : loading attribute plain xml text // Param : pszAttrs - xml of attributes // pszEnd - last string // pi = parser information // Return : advanced string pointer. (error return NULL) //-------------------------------------------------------- // Coder Date Desc // bro 2004-06-14 //======================================================== LPTSTR _tagXMLNode::LoadAttributes( LPCTSTR pszAttrs, LPCTSTR pszEnd, LPPARSEINFO pi /*= &piDefault*/ ) { LPTSTR xml = (LPTSTR)pszAttrs; while( xml && *xml ) { if( xml = _tcsskip( xml ) ) { // close tag if( xml >= pszEnd ) // wel-formed tag return xml; // XML Attr Name TCHAR* pEnd = _tcspbrk( xml, _T(" =") ); if( pEnd == NULL ) { // error if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_ATTR_NO_VALUE; pi->error_string.Format( _T("<%s> attribute has error "), name ); } return NULL; } LPXAttr attr = new XAttr; attr->parent = this; // XML Attr Name _SetString( xml, pEnd, &attr->name ); // add new attribute attrs.push_back( attr ); xml = pEnd; // XML Attr Value if( xml = _tcsskip( xml ) ) { //if( xml = _tcschr( xml, '=' ) ) if( *xml == '=' ) { if( xml = _tcsskip( ++xml ) ) { // if " or ' // or none quote int quote = *xml; if( quote == '"' || quote == '\'' ) pEnd = _tcsechr( ++xml, quote, pi ? pi->escape_value : 0 ); else { //attr= value> // none quote mode //pEnd = _tcsechr( xml, ' ', '\\' ); pEnd = _tcsepbrk( xml, _T(" >"), pi ? pi->escape_value : 0 ); } bool trim = pi->trim_value; TCHAR escape = pi->escape_value; //_SetString( xml, pEnd, &attr->value, trim, pi ? pi->escape_value : 0 ); _SetString( xml, pEnd, &attr->value, trim, escape ); xml = pEnd; // ATTRVALUE if( pi->entity_value && pi->entitys ) attr->value = pi->entitys->Ref2Entity(attr->value); if( quote == '"' || quote == '\'' ) xml++; } } } } } // not wel-formed tag return NULL; }
void CDbConnectionDlg::_LoadServersList() { SQLHENV hEnv = 0; SQLHDBC hDbc = 0; CWaitCursor wait; m_cmbServer.ResetContent(); try { SQLRETURN rc; rc = ::SQLAllocEnv(&hEnv); if(rc == SQL_INVALID_HANDLE || rc == SQL_ERROR) throw 1L; rc = ::SQLAllocConnect(hEnv, &hDbc); if(rc == SQL_INVALID_HANDLE || rc == SQL_ERROR) throw 2L; SQLTCHAR tszQuery[] = _T("DRIVER={SQL Server};"); SQLSMALLINT cbSize = 0; SQLTCHAR tszTemp[10]; rc = ::SQLBrowseConnect(hDbc, tszQuery, SQL_NTS, tszTemp, sizeof(tszTemp), &cbSize); if(rc == SQL_INVALID_HANDLE || rc == SQL_ERROR || cbSize == 0) throw 3L; int iSize = cbSize * sizeof(SQLTCHAR); SQLTCHAR *pszBuffer = (SQLTCHAR*)_alloca(iSize); memset(pszBuffer, 0, iSize); rc = ::SQLBrowseConnect(hDbc, tszQuery, SQL_NTS, pszBuffer, iSize, &cbSize); if(rc == SQL_INVALID_HANDLE || rc == SQL_ERROR) throw 4L; static const TCHAR szServer[] = _T("Server={"); LPTSTR pcszStart = _tcsstr((LPTSTR)pszBuffer, szServer); if(pcszStart) { pcszStart += sizeof(szServer) - 1; LPTSTR pcszEnd = _tcspbrk(pcszStart, _T(",}")); while(pcszEnd) { *pcszEnd = 0; m_cmbServer.AddString(pcszStart); pcszStart = pcszEnd + 1; pcszEnd = _tcspbrk(pcszStart, _T(",}")); } } } catch(long) { } if(hDbc) ::SQLFreeConnect(hDbc); if(hEnv) ::SQLFreeEnv(hEnv); m_cmbServer.SetWindowText(m_dbConnSettings.m_strServer); }
BOOL CLauncher::ReadFromFile(LPCTSTR fname) { FILE* fp; TCHAR line_buf[TMP_BUF_SIZE]; LPTSTR p; #ifdef _UNICODE if(_tfopen_s(&fp, fname, _T("rt, ccs=UTF-8"))) return FALSE; #else if(_tfopen_s(&fp, fname, _T("rt"))) return FALSE; #endif CreateParams(); RemoveAll(); TCHAR* context = NULL; for(;;) { if(!_fgetts(line_buf, TMP_BUF_SIZE, fp)) break; p = _tcspbrk(line_buf, _T(";\r\n")); if(p) *p = _T('\0'); p = TrimLeft(line_buf); if(p[0] == _T('@')) { FlashParams(); _tcscpy_s(m_params.title, TMP_BUF_SIZE, p+1); } else if(p[0] == _T('P')) { p = TrimLeft(p+1); _tcscpy_s(m_params.module_path, TMP_BUF_SIZE, p); } else if(p[0] == _T('A')) { p = TrimLeft(p+1); _tcscpy_s(m_params.arg, TMP_BUF_SIZE, p); } else if(p[0] == _T('W')) { p = TrimLeft(p+1); _tcscpy_s(m_params.workdirectory, TMP_BUF_SIZE, p); } else if(p[0] == _T('C')) { p = TrimLeft(p+1); _tcscpy_s(m_params.checkpath, TMP_BUF_SIZE, p); } else if(p[0] == _T('N')) { p = TrimLeft(p+1); _tcscpy_s(m_params.checktitle, TMP_BUF_SIZE, p); } else if(p[0] == _T('I')) { context = NULL; p = TrimLeft(p+1); LPTSTR file = _tcstok_s(p, _T(","), &context); _tcscpy_s(m_params.iconpath, TMP_BUF_SIZE, file); LPTSTR index = _tcstok_s(NULL, _T(","), &context); if(index !=NULL) { int num = _tstoi(index); m_params.iconindex = num; } } } FlashParams(); DestroyParams(); fclose(fp); return TRUE; }
int CStrClass::FindOneOf(LPCTSTR lpszCharSet) const { LPTSTR lpsz = _tcspbrk(m_pchData, lpszCharSet); return (lpsz == NULL) ? -1 : (int)(lpsz - m_pchData); }
void Registry::Export(const TCHAR *szFile) { #ifdef WIN32 TCHAR lpstrName[nMaxKeyNameSize+1]; union { BYTE pValue[nMaxValueValueSize+4]; DWORD dValue; TCHAR string_value[1]; } uValue; // If no file is given -> return if (string_is_empty(szFile)) return; // Try to open the file for writing TextWriter writer(szFile); // ... on error -> return if (writer.error()) return; // Try to open the XCSoar registry key HKEY hkFrom; LONG res = ::RegOpenKeyEx(HKEY_CURRENT_USER, szProfileKey, 0, KEY_ALL_ACCESS, &hkFrom); // ... on error -> return if (ERROR_SUCCESS != res) return; // Iterate through the registry subkeys for (int i = 0;; i++) { DWORD nType; // Reset the buffer sizes DWORD nValueSize = nMaxValueValueSize; DWORD nNameSize = nMaxKeyNameSize; // Reset the key-name buffer lpstrName[0] = _T('\0'); // Get i-th subkey from the registry key defined by hkFrom res = ::RegEnumValue(hkFrom, i, lpstrName, &nNameSize, 0, &nType, uValue.pValue, &nValueSize); // If we iterated to the end of the subkey "array" -> quit the for-loop if (ERROR_NO_MORE_ITEMS == res) break; // If the size of the name is <= 0 or the buffer is to small // -> skip this subkey if ((nNameSize <= 0) || (nNameSize > nMaxKeyNameSize)) continue; // If the string length of the name is smaller then one character // -> skip this subkey if (_tcslen(lpstrName) <= 1) continue; if (nType == REG_DWORD) { // If the subkey type is DWORD writer.printfln(_T("%s=%d"), lpstrName, uValue.dValue); } else if (nType == REG_SZ) { // If the subkey type is STRING // If the value is empty if (nValueSize <= 0) { // -> write ="" to the output file an continue with the next subkey writer.printfln(_T("%s=\"\""), lpstrName); continue; } // does it contain invalid characters? if (_tcspbrk(uValue.string_value, _T("\r\n\"")) != NULL) { // -> write ="" to the output file an continue with the next subkey writer.printfln(_T("%s=\"\""), lpstrName); continue; } /// @todo SCOTT - Check that the output data (lpstrName and pValue) do not contain \r or \n // Force null-termination uValue.pValue[nValueSize] = 0; uValue.pValue[nValueSize + 1] = 0; // If the value string is not empty if (!string_is_empty(uValue.string_value)) // -> write the value to the output file writer.printfln(_T("%s=\"%s\""), lpstrName, uValue.pValue); else // otherwise -> write ="" to the output file writer.printfln(_T("%s=\"\""), lpstrName); } } // Close the XCSoar registry key ::RegCloseKey(hkFrom); #else /* !WIN32 */ // XXX implement #endif /* !WIN32 */ }
// attr1="value1" attr2='value2' attr3=value3 /> // ^- return pointer //======================================================== // Desc : loading attribute plain xml text // Param : pszAttrs - xml of attributes // pi = parser information // Return : advanced std::string pointer. //======================================================== char* _tagXMLNode::loadAttributes( const char* pszAttrs , LPPARSEINFO pi /*= &piDefault*/) { char* xml = (char*)pszAttrs; while( xml && *xml ) { if( xml = _tcsskip( xml ) ) { if ( xml = _tctskip(xml) ) { if ( xml = _tcrskip(xml) ) { // close tag if( *xml == chXMLTagClose || *xml == chXMLTagPre ) // wel-formed tag return xml; // XML Attr Name char* pEnd = _tcspbrk( xml, " =" ); if( pEnd == NULL ) { // error if( pi->erorr_occur == false ) { pi->erorr_occur = true; pi->error_pointer = xml; pi->error_code = PIE_ATTR_NO_VALUE; pi->error_string = "<%s> attribute has error "; pi->error_string += name; } return xml; } LPXAttr attr = new XAttr; attr->parent = this; // XML Attr Name _Setstring( xml, pEnd, &attr->name ); // add new attribute attrs.push_back( attr ); xml = pEnd; // XML Attr Value if( xml = _tcsskip( xml ) ) { //if( xml = _tcschr( xml, '=' ) ) if( *xml == '=' ) { if( xml = _tcsskip( ++xml ) ) { // if " or ' // or none quote int quote = *xml; if( quote == '"' || quote == '\'' ) pEnd = _tcsechr( ++xml, quote, chXMLEscape ); else { //attr= value> // none quote mode //pEnd = _tcsechr( xml, ' ', '\\' ); pEnd = _tcsepbrk( xml, " >", chXMLEscape ); } bool trim = pi->trim_value; _Setstring( xml, pEnd, &attr->value, trim, chXMLEscape ); xml = pEnd; // ATTRVALUE if( pi->entity_value && pi->entitys ) attr->value = pi->entitys->ref2Entity(attr->value.c_str()); if( quote == '"' || quote == '\'' ) xml++; } } } } } } } // not wel-formed tag return NULL; }
UCHAR processIncludeFile( char *s ) { MACRODEF *m; struct _finddata_t finddata; NMHANDLE searchHandle; char *t, *p, *u; int c = 0; int i; if (!*s || *s == '#') { makeError(line, SYNTAX_NO_NAME); } if ((t = _tcspbrk(s,"\t#"))) { if (*t == '#') { c = *t; } *t = '\0'; if (!c) { for (u = t; *++u;) { // check for extra if (*u == '#') { break; // text on line } if (!WHITESPACE(*u)) { makeError(line, SYNTAX_UNEXPECTED_TOKEN, u); } } } } else { t = s + _tcslen(s); } // remove trailing white space while (t > s) { char *prev; prev = _tcsdec(s, t); if (!WHITESPACE(*prev)) break; t = prev; } *t = '\0'; if (*s == '<' && *(t-1) == '>') { char *pt; *--t = '\0'; p = removeMacros(++s); p = p == s ? makeString(s) : p; t = (m = findMacro("INCLUDE")) ? m->values->text : (char*) NULL; if (t != NULL) { // expand INCLUDE macro before passing it on char * pt1; pt1= makeString(t); pt = removeMacros(pt1); if (pt != pt1) { FREE(pt1); // we've got a new string, free old one } } else { pt = NULL; } if (!(u = searchPath(pt, p, &finddata, &searchHandle))) { makeError(line, CANT_OPEN_FILE, p); } if (pt) { FREE(pt); } FREE(p); s = u; } else { if (*s == '"' && *(t-1) == '"') { *--t = '\0'; ++s; } p = removeMacros(s); p = p == s ? makeString(s) : p; if (!findFirst(p, &finddata, &searchHandle)) { if (!_tcspbrk(p, "\\/:")) { //use C sematics for include for (i = incTop;i >= 0;i--) { t = (i == incTop) ? fName : incStack[i].name; if (!(t = getPath(t))) continue; u = (char *)allocate(_tcslen(t) + 1 + _tcslen(p) + 1); _tcscat(_tcscat(_tcscpy(u, t), PATH_SEPARATOR), p); if (findFirst(u, &finddata, &searchHandle)) { s = u; FREE(t); break; } FREE(t); FREE(u); } FREE(p); if (i < 0) { makeError(line, CANT_OPEN_FILE, s); } } else { makeError(line, CANT_OPEN_FILE, p); } } } for (i = 0; i < incTop; ++i) { // test for cycles if (!_tcsicmp(s,incStack[i].name)) { makeError(line, CYCLE_IN_INCLUDES, s); } } incStack[incTop].file = file; // push info on stack incStack[incTop].line = line; incStack[incTop++].name = fName; currentLine = 0; if (!(file = OpenValidateMakefile(s,"rt"))) { // read, text mode makeError(line,CANT_OPEN_FILE,s); } fName = makeString(s); line = 1; colZero = TRUE; // parser needs to see some kind of c = lgetc(); // newline to initialize it for this if ((colZero = (BOOL) !WHITESPACE(c))) { // file UngetTxtChr(c,file); line=0; // We did not start reading the file return(NEWLINE); } return(NEWLINESPACE); }
int CString::FindOneOf(LPCTSTR lpszCharSet) const { ASSERT(AfxIsValidString(lpszCharSet, FALSE)); LPTSTR lpsz = _tcspbrk(m_pchData, lpszCharSet); return (lpsz == NULL) ? -1 : (int)(lpsz - m_pchData); }
int _RTLENTRY _EXPFUNC _tstati64 (const _TCHAR *pathP, struct stati64 *bufP) { WIN32_FIND_DATA ff; HANDLE hfile; /* file handle */ _TCHAR curdir[MAX_PATH]; /* current directory */ _TCHAR DriveChar; _TCHAR *full = 0; _TCHAR *ext; /* Assume it is a disk file and try to get the FindFirst info. */ memset(bufP, 0, sizeof(struct stati64)); /* Zero the structure */ bufP->st_nlink = 1; if ((hfile = FindFirstFile(pathP, &ff)) == (HANDLE)-1) { /* Check for special case of ROOT directory */ if ((_tcspbrk(pathP, _TEXT("\\/.")) != NULL) && ((full = _tfullpath(NULL, pathP, 0)) != NULL) && (_tcslen(full) == 3)) { if (GetDriveType(full) < 2) return (__NTerror()); bufP->st_mode = S_IFDIR; bufP->st_dev = bufP->st_rdev = _totupper(full[0]) - _TEXT('A') + 1; free(full); return 0; } else if (full) free (full); /* It may not be a disk file. Try to open the file for reading * so we can find out the type of the file. */ if ((hfile = CreateFile(pathP, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL)) == (HANDLE)-1) return (__NTerror()); /* Get the handle type to see if it is a character device or pipe. */ bufP->st_mode = GetFileType(hfile) == FILE_TYPE_PIPE ? S_IFIFO : S_IFCHR; CloseHandle(hfile); return (0); } /* It it a disk file, convert the NT file info to a stat structure. */ FindClose(hfile); _statcvt_i64(bufP, ff.dwFileAttributes, &ff.ftCreationTime, &ff.ftLastAccessTime, &ff.ftLastWriteTime, ff.nFileSizeHigh, ff.nFileSizeLow); /* If we're not pointing to a directory, then set the exec bit on * "executable" files. */ if ((bufP->st_mode & S_IFDIR) == 0) { if ((ext = _tcsrchr(pathP, _TEXT('.'))) != NULL) { if ( _tcsicmp(ext, _TEXT(".bat")) == NULL || _tcsicmp(ext, _TEXT(".cmd")) == NULL || _tcsicmp(ext, _TEXT(".com")) == NULL || _tcsicmp(ext, _TEXT(".exe")) == NULL ) { /* Microsoft marks these file types as executable, so we will * too. */ bufP->st_mode |= S_IEXEC; } } } /* Determine the disk device by parsing the drive name. * If no drive name, assume current drive. */ if (pathP[1] == _TEXT(':')) DriveChar = pathP[0]; else { if (GetCurrentDirectory(sizeof(curdir), curdir) == 0) DriveChar = _TEXT('A'); /* reasonable default if failure */ else DriveChar = curdir[0]; } if (DriveChar >= 'a' && DriveChar <= 'z') bufP->st_dev = DriveChar - 'a'; else if (DriveChar >= 'A' && DriveChar <= 'Z') bufP->st_dev = DriveChar - 'A'; bufP->st_rdev = bufP->st_dev; return (0); }
HRESULT CG_CConsole::parseConsoleSection(BSTR sResourceName) { const CG_AttribList* al; FC_CString jot10; if (!sResourceName) jot10.load(CG_SEC_4CP_CONSOLE); else jot10.load(CG_SEC_4CP_CONSOLE_BEG) << m_sResourceName; jot10.toLower(); al = m_pIFront->FCPgetSection(jot10); if (!al) return S_OK; const CG_KeyValPair* pair; TCHAR** files; const TCHAR* prjPath = m_pIFront->FCPgetPrjPath(); for (int i = 0; i < al->nAttribs; i++) { pair = &al->pairs[i]; if (!_tcsicmp(pair->pszKey, _T("file"))) { if(FC_StringIsAbsPath(pair->pszVal)) { m_dm.msg1(CG_E_TEXT, &pair->edpVal, m_dm.jot1()<<_T("section [console]: file='") <<pair->pszVal<<_T("' file must be project relative")); } if (_tcspbrk(pair->pszVal, _T("*?")) == NULL) // no wildchar { if (FC_FileExists(prjPath, pair->pszVal) != 1) m_dm.msg1(CG_E_FILE_NOT_EXIST, &pair->edpVal, pair->pszVal); else if (!m_LoaderList.addFile(pair->pszVal, FILE_PRJ_DIR_RELATIVE)) m_dm.msg1(CG_W_TEXT, &pair->edpVal, m_dm.jot1()<<_T("file '")<<pair->pszVal<<_T("' already specified ignoring this one")); } else { files = FC_FileBuildFileList(prjPath, pair->pszVal, 0); if (files) { for (int j = 0; files[j] != NULL; j++) { const TCHAR* pszFileMatch = files[j]; if (!m_LoaderList.addFile(pszFileMatch, FILE_PRJ_DIR_RELATIVE)) m_dm.msg1(CG_W_TEXT, &pair->edpVal, m_dm.jot1()<<_T("file '")<<pszFileMatch<<_T("' already specified ignoring this one")); } if (files[0] == NULL) m_dm.msg1(CG_W_TEXT, &pair->edpVal, m_dm.jot1()<<_T("no such file or folder name '")<<pair->pszVal<<_T("'")); FC_FileDeleteFileList(files); } else { m_dm.msg2(CG_E_FILE_OPEN, &pair->edpVal, pair->pszVal, m_dm.jot1().fmtSysErr(GetLastError())); } } } else m_dm.msg2(CG_E_PRJ_UNKNOWN_KEY, &pair->edpKey, pair->pszKey, jot10); } return S_OK; }
void CProtoSettings::SetMsgFormat(int Flags, TCString Message) { if (Flags & (SMF_TEMPORARY | SMF_PERSONAL) && g_AutoreplyOptPage.GetDBValueCopy(IDC_REPLYDLG_RESETCOUNTERWHENSAMEICON) && GetMsgFormat(Flags & (SMF_TEMPORARY | SMF_PERSONAL)) != (const TCHAR*)Message) ResetSettingsOnStatusChange(szProto); if (Flags & SMF_TEMPORARY) { _ASSERT(!Status || Status == g_ProtoStates[szProto].Status); g_ProtoStates[szProto].TempMsg = (szProto || Message != NULL) ? Message : CProtoSettings(NULL, Status).GetMsgFormat(GMF_LASTORDEFAULT); } if (Flags & SMF_PERSONAL) { // set a "personal" message for a protocol. also it's used to set global status message (hContact = NULL). // if Message == NULL, then we'll use the "default" message - i.e. it's either the global message for szProto != NULL (we delete the per-proto DB setting), or it's just a default message for a given status for szProto == NULL. g_ProtoStates[szProto].TempMsg.Unset(); CString DBSetting(ProtoStatusToDBSetting(DB_STATUSMSG, IDC_MOREOPTDLG_PERSTATUSPROTOMSGS)); if (Message != NULL) db_set_ts(NULL, MOD_NAME, DBSetting, Message); else { if (!szProto) db_set_ts(NULL, MOD_NAME, DBSetting, CProtoSettings(NULL, Status).GetMsgFormat(GMF_LASTORDEFAULT)); // global message can't be NULL; we can use an empty string instead if it's really necessary else db_unset(NULL, MOD_NAME, DBSetting); } } if (Flags & SMF_LAST) { COptPage MsgTreeData(g_MsgTreePage); COptItem_TreeCtrl *TreeCtrl = (COptItem_TreeCtrl*)MsgTreeData.Find(IDV_MSGTREE); TreeCtrl->DBToMem(CString(MOD_NAME)); int RecentGroupID = GetRecentGroupID(Status); if (RecentGroupID == -1) { // we didn't find the group, it also means that we're using per status messages; so we need to create it TreeCtrl->Value.AddElem(CTreeItem(Status ? pcli->pfnGetStatusModeDescription(Status, 0) : MSGTREE_RECENT_OTHERGROUP, g_Messages_RecentRootID, RecentGroupID = TreeCtrl->GenerateID(), TIF_GROUP)); TreeCtrl->SetModified(true); } int i; // try to find an identical message in the same group (to prevent saving multiple identical messages), // or at least if we'll find an identical message somewhere else, then we'll use its title for our new message TCString Title(_T("")); for (i = 0; i < TreeCtrl->Value.GetSize(); i++) { if (!(TreeCtrl->Value[i].Flags & TIF_GROUP) && TreeCtrl->Value[i].User_Str1 == (const TCHAR*)Message) { if (TreeCtrl->Value[i].ParentID == RecentGroupID) { // found it in the same group int GroupOrder = TreeCtrl->IDToOrder(RecentGroupID); TreeCtrl->Value.MoveElem(i, (GroupOrder >= 0) ? (GroupOrder + 1) : 0); // now move it to the top of recent messages list TreeCtrl->SetModified(true); break; // no reason to search for anything else } if (Title.IsEmpty()) // it's not in the same group, but at least we'll use its title Title = TreeCtrl->Value[i].Title; } } if (i == TreeCtrl->Value.GetSize()) { // we didn't find an identical message in the same group, so we'll add our new message here if (Title.IsEmpty()) { // didn't find a title for our message either if (Message.GetLen() > MRM_MAX_GENERATED_TITLE_LEN) Title = Message.Left(MRM_MAX_GENERATED_TITLE_LEN - 3) + _T("..."); else Title = Message; TCHAR *p = Title.GetBuffer(); while (*p) { // remove "garbage" if (!(p = _tcspbrk(p, _T("\r\n\t")))) break; *p++ = ' '; } Title.ReleaseBuffer(); } int GroupOrder = TreeCtrl->IDToOrder(RecentGroupID); TreeCtrl->Value.InsertElem(CTreeItem(Title, RecentGroupID, TreeCtrl->GenerateID(), 0, Message), (GroupOrder >= 0) ? (GroupOrder + 1) : 0); TreeCtrl->SetModified(true); } // now clean up here int MRMNum = 0; int MaxMRMNum = g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_RECENTMSGSCOUNT); for (i = 0; i < TreeCtrl->Value.GetSize(); i++) { if (TreeCtrl->Value[i].ParentID == RecentGroupID) { // found a child of our group if (TreeCtrl->Value[i].Flags & TIF_GROUP || ++MRMNum > MaxMRMNum) { // what groups are doing here?! :)) TreeCtrl->Value.RemoveElem(i); TreeCtrl->SetModified(true); i--; } } } // if we're saving recent messages per status, then remove any messages that were left at the recent messages' root if (g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_PERSTATUSMRM)) { for (i = 0; i < TreeCtrl->Value.GetSize(); i++) { if (TreeCtrl->Value[i].ParentID == g_Messages_RecentRootID) { if (!(TreeCtrl->Value[i].Flags & TIF_GROUP)) { TreeCtrl->Value.RemoveElem(i); TreeCtrl->SetModified(true); i--; } } } } TreeCtrl->MemToDB(CString(MOD_NAME)); } }
BOOL CCmdLineParser::Parse(LPCTSTR sCmdLine) { const stdstring sEmpty = _T(""); //use this as a value if no actual value is given in commandline int nArgs = 0; if(!sCmdLine) return false; m_valueMap.clear(); m_sCmdLine = sCmdLine; LPCTSTR sCurrent = sCmdLine; for(;;) { //format is -Key:"arg" if (_tcslen(sCurrent) == 0) break; // no more data, leave loop LPCTSTR sArg = _tcspbrk(sCurrent, m_sDelims); if(!sArg) break; // no (more) delimiters found sArg = _tcsinc(sArg); if(_tcslen(sArg) == 0) break; // ends with delim LPCTSTR sVal = _tcspbrk(sArg, m_sValueSep); if(sVal == NULL) { stdstring Key(sArg); std::transform(Key.begin(), Key.end(), Key.begin(), ::tolower); m_valueMap.insert(CValsMap::value_type(Key, sEmpty)); break; } else { stdstring Key(sArg, (int)(sVal - sArg)); std::transform(Key.begin(), Key.end(), Key.begin(), ::tolower); LPCTSTR sQuote(NULL), sEndQuote(NULL); if (_tcslen(sVal) > 0) { if (sVal[0] != _T(' ')) sVal = _tcsinc(sVal); else { while (_tcslen(sVal) > 0 && sVal[0] == _T(' ')) sVal = _tcsinc(sVal); } LPCTSTR nextArg = _tcspbrk(sVal, m_sDelims); sQuote = _tcspbrk(sVal, m_sQuotes); if (nextArg == sVal) { // current key has no value, but a next key exist - so don't use next key as value of current one --sVal; sQuote = sVal; sEndQuote = sVal; } else if (nextArg != NULL && nextArg < sQuote) { // current key has a value w/o quotes, but next key one has value in quotes sQuote = sVal; sEndQuote = _tcschr(sQuote, _T(' ')); } else { if(sQuote == sVal) { // string with quotes (defined in m_sQuotes, e.g. '") sQuote = _tcsinc(sVal); sEndQuote = _tcspbrk(sQuote, m_sQuotes); } else { sQuote = sVal; sEndQuote = _tcschr(sQuote, _T(' ')); } } } if(sEndQuote == NULL) { // no end quotes or terminating space, take the rest of the string to its end if (!Key.empty() && sQuote) { stdstring csVal(sQuote); m_valueMap.insert(CValsMap::value_type(Key, csVal)); } break; } else { // end quote if(!Key.empty()) { stdstring csVal(sQuote, (int)(sEndQuote - sQuote)); m_valueMap.insert(CValsMap::value_type(Key, csVal)); } sCurrent = _tcsinc(sEndQuote); continue; } } } return (nArgs > 0); //TRUE if arguments were found }
HRESULT CG_CConsole::addCustomFilesToConsoleLinkFile(const CG_AttribList* al) { if (!al) return S_OK; const CG_KeyValPair* pair; TCHAR** files; const TCHAR* prjPath = m_pIFront->FCPgetPrjPath(); CGT_CDmp dmp; FC_CString sOutPath; sOutPath.load(m_pIFront->FCPgetPrjPath()) << _T("\\gen\\.") << m_sTargetTypeName << _T("\\.link\\"); long lNrChars = dmp.getNChars(); for (int i = 0; i < al->nAttribs; i++) { pair = &al->pairs[i]; if (!_tcsicmp(pair->pszKey, _T("file"))) { if(FC_StringIsAbsPath(pair->pszVal)) { m_dm.msg1(CG_E_TEXT, &pair->edpVal, m_dm.jot1()<<_T("section [console]: file='") <<pair->pszVal<<_T("' file must be project relative")); } if (_tcspbrk(pair->pszVal, _T("\\")) != NULL) // file not in project directory { m_dm.msg1(CG_W_TEXT, &pair->edpVal, m_dm.jot1()<<_T("ignoring file(s) '")<<pair->pszVal<<_T("' because subdirectories are not supported when creating library")); continue; } if (_tcspbrk(pair->pszVal, _T("*?")) == NULL) // no wildchar { if (FC_FileExists(prjPath, pair->pszVal) != 1) m_dm.msg1(CG_E_FILE_NOT_EXIST, &pair->edpVal, pair->pszVal); else dmp << CG_LINK_LIB_PUT _T(";") << prjPath << _T("\\") << pair->pszVal << _T("\n"); } else { files = FC_FileBuildFileList(prjPath, pair->pszVal, 0); if (files) { for (int j = 0; files[j] != NULL; j++) { const TCHAR* pszFileMatch = files[j]; dmp << CG_LINK_LIB_PUT _T(";") << prjPath << _T("\\") << pszFileMatch << _T("\n"); } if (files[0] == NULL) m_dm.msg1(CG_W_TEXT, &pair->edpVal, m_dm.jot1()<<_T("no such file or folder name '")<<pair->pszVal<<_T("'")); FC_FileDeleteFileList(files); } else { m_dm.msg2(CG_E_FILE_OPEN, &pair->edpVal, pair->pszVal, m_dm.jot1().fmtSysErr(GetLastError())); } } } else m_dm.msg2(CG_E_PRJ_UNKNOWN_KEY, &pair->edpKey, pair->pszKey, CG_SEC_4CP_CONSOLE); } if (lNrChars != dmp.getNChars()) if (!CGT_DmpToFile(&m_dm, sOutPath, _T("__console.link"), dmp, false)) return E_FAIL; return S_OK; }
void COXUNC::BuildParts() // --- In : // --- Out : // --- Returns : // --- Effect : Builds the different parts from the full UNC { if (ArePartsBuilt()) { // ... Re-adjust parts data (may have changed) AdjustParts(); return; } if (!IsMainBuilt()) { // Nothing has been built yet, clean everything and set to built Empty(); SetMainBuilt(); return; } // ... Adjust main before we use it ASSERT(IsMainBuilt()); AdjustMain(); // Build the parts // There are three possibilities for server // 1. An actual UNC name (e.g. \\Comp1\Share\Dir\File.ext : \\Comp1, \Share, \Dir\, File.ext) // Always starts with two (back)slashes // 2. A TCP/IP server name (e.g. server.company.com/Dir/File.ext : server.company.com, , /Dir/, File.ext) // m_bURLPart == TRUE // 3. A local file specification (e.g. C:\Dir\File.ext : C:, ,\Dir\, File.ext) // ... First make a copy with only normal slashes (no backslashes) and lowercase characters // Possibility 2 and 3 can be handled the same way // All parts are empty by default m_sServer.Empty(); m_sShare.Empty(); m_sDirectory.Empty(); m_sFile.Empty(); if ((2 <= m_sUNC.GetLength()) && (_tcschr(m_pszSlashes, *(LPCTSTR)m_sUNC) != NULL) && (_tcschr(m_pszSlashes, *((LPCTSTR)m_sUNC + 1)) != NULL) ) { // Possibility 1 : Actual UNC // ... Search for first slash after Server name LPCTSTR pszShare = _tcspbrk((LPCTSTR)m_sUNC + 2, m_pszSlashes); if (pszShare != NULL) { // ... Share found INT_PTR nServerLength = pszShare - (LPCTSTR)m_sUNC; UTBStr::tcsncpy(m_sServer.GetBufferSetLength((int)nServerLength), (int)nServerLength+1, m_sUNC, (int)nServerLength); // ... Search for first slash after Share name LPCTSTR pszDir = _tcspbrk(pszShare + 1, m_pszSlashes); if (pszDir != NULL) { // ... Directory found INT_PTR nShareLength = pszDir - pszShare; UTBStr::tcsncpy(m_sShare.GetBufferSetLength((int)nShareLength), (int)nShareLength+1, pszShare, (int)nShareLength); // ... Search for last slash after Share name LPCTSTR pszLastSlash = _tcsrchr(pszDir + 1, m_cSlash); LPCTSTR pszLastBackslash = _tcsrchr(pszDir + 1, m_cBackslash); LPCTSTR pszFile = pszLastSlash < pszLastBackslash ? pszLastBackslash : pszLastSlash; if (pszFile != NULL) { // ... File found (skip leading slash) pszFile++; INT_PTR nDirLength = pszFile - pszDir; UTBStr::tcsncpy(m_sDirectory.GetBufferSetLength((int)nDirLength), (int)nDirLength+1, pszDir, (int)nDirLength); m_sFile = pszFile; } else { // ... No file found after directory, interpret directory as file // and use root as directory // E.g. \Test -> Dir : \, File : Test // ... First character must be a slash ASSERT(_tcschr(m_pszSlashes, *pszDir) != NULL); UTBStr::tcsncpy(m_sDirectory.GetBufferSetLength(1), 2, pszDir, 1); m_sFile = pszDir + 1; } } else { // ... Directory not found m_sShare = pszShare; } } else { // ... Share not found m_sServer = m_sUNC; } } else if (URLPart() && (_tcschr(m_sUNC, m_cColon) == NULL)) { // Possibility 2 : A TCP/IP URL part // A URL should contain an absolute specification so by checking // for a colon we can see whether it is a TCP/IP name or local name // ... Search for first slash after Server name LPCTSTR pszDir = _tcspbrk(m_sUNC, m_pszSlashes); if (pszDir != NULL) { // ... Directory found INT_PTR nServerLength = pszDir - (LPCTSTR)m_sUNC; UTBStr::tcsncpy(m_sServer.GetBufferSetLength((int)nServerLength), (int)nServerLength+1, m_sUNC, (int)nServerLength); // ... Search for last slash after Directory name LPCTSTR pszLastSlash = _tcsrchr(pszDir + 1, m_cSlash); LPCTSTR pszLastBackslash = _tcsrchr(pszDir + 1, m_cBackslash); LPCTSTR pszFile = pszLastSlash < pszLastBackslash ? pszLastBackslash : pszLastSlash; if (pszFile != NULL) { // ... File found (skip leading slash) pszFile++; INT_PTR nDirLength = pszFile - pszDir; UTBStr::tcsncpy(m_sDirectory.GetBufferSetLength((int)nDirLength), (int)nDirLength+1, pszDir, (int)nDirLength); m_sFile = pszFile; } else { // ... No file found after directory, interpret directory as file // and use root as directory // E.g. \Test -> Dir : \, File : Test // ... First character must be a slash ASSERT(_tcschr(m_pszSlashes, *pszDir) != NULL); UTBStr::tcsncpy(m_sDirectory.GetBufferSetLength(1), 2, pszDir, 1); m_sFile = pszDir + 1; } } else { // ... Directory not found m_sServer = m_sUNC; } } else { // Possibility 3 : A local file CString sBaseName; CString sExtension; // ... _tsplitpath will return the current directory if m_sUNC is empty // We do not want that. if (!m_sUNC.IsEmpty()) { UTBStr::tsplitpath(m_sUNC, m_sServer.GetBuffer(_MAX_DRIVE), _MAX_DRIVE, m_sDirectory.GetBuffer(_MAX_DIR), _MAX_DIR, sBaseName.GetBuffer(_MAX_FNAME), _MAX_FNAME, sExtension.GetBuffer(_MAX_EXT), _MAX_EXT); m_sServer.ReleaseBuffer(); m_sDirectory.ReleaseBuffer(); sBaseName.ReleaseBuffer(); sExtension.ReleaseBuffer(); m_sFile = sBaseName + sExtension; } } // ... Adjust parts after we have built them AdjustParts(); // ... Mark that the parts data has been built now SetPartsBuilt(); return; }
void expandFileNames( char *string, STRINGLIST **sourceList, STRINGLIST **macroList ) { char *s, *t = NULL; STRINGLIST *p; // Main list pointer STRINGLIST *pNew, // Pointer to new list *pBack; // Pointer to one element back char *saveText = NULL; for (pBack = NULL, p = *sourceList; p;) { // If no expand-character is found, continue to next list element. if (!_tcspbrk(p->text, string)) { pBack = p; p = pBack->next; continue; } // Either expand macros or wildcards. if (*string == '$') { t = expandMacros(p->text, macroList); FREE(p->text); } else { // If the wildcard string does not expand to anything, go to // next list elment. Do not remove p from the original list // else we must check for null elsewhere. // -- do not attempt to expand wildcards that // occur in inference rules if (isRule(p->text) || (pNew = expandWildCards(p->text)) == NULL) { pBack = p; p = pBack->next; continue; } saveText = p->text; } // At this point we have a list of expanded names to replace p with. if (pBack) { pBack->next = p->next; FREE_STRINGLIST(p); p = pBack->next; } else { *sourceList = p->next; FREE_STRINGLIST(p); p = *sourceList; } if (*string == '$') { // if expanding macros char *str = t; if ((s = nextComponent(&str))) { do { // put expanded names pNew = makeNewStrListElement(); // at front of list pNew->text = makeString(s); // so we won't try to prependItem(sourceList, pNew); // re-expand them if (!pBack) pBack = pNew; } while ((s = nextComponent(&str))); } FREE(t); continue; } else if (pNew) { // if matches for * ? if (!pBack) for (pBack = pNew; pBack->next; pBack = pBack->next) ; appendItem(&pNew, *sourceList); // put at front of old list *sourceList = pNew; } FREE(saveText); } }