intptr_t WINAPI GetContentDataW(struct GetContentDataInfo *Info) { if (!Info) return FALSE; LPCWSTR FilePath = Info->FilePath; wchar_t** CustomData = NULL; for (size_t i = 0; i < Info->Count; i++) { if (!fsf.LStricmp(Info->Names[i], L"diz") || !fsf.LStricmp(Info->Names[i], L"C0")) { CustomData = (wchar_t**)(Info->Values + i); } } if (!FilePath || !CustomData) return FALSE; const wchar_t* pszSlash = wcsrchr(FilePath, L'\\'); if (!pszSlash || pszSlash <= FilePath) return FALSE; if (pszSlash[1] == 0) return FALSE; // Если хотят диз именно для папки - то нужно без слеша string strPath(FilePath, pszSlash-FilePath); // оптимизацией чтения диз-файла занимается сам diz if (diz.Read(strPath) == 0) { // Если диз пустой - сразу выходим return FALSE; } const wchar_t* pszDiz = diz.GetDizTextAddr(pszSlash+1, L"", 0/*???*/); //if (!pszDiz || pszDiz[0] == 0) -- ConvertNameToShort занимает очень много времени //{ // string strShort; // ConvertNameToShort(FilePath, strShort); // pszDiz = diz.GetDizTextAddr(pszSlash+1, strShort, 0/*???*/); //} if (!pszDiz || pszDiz[0] == 0) { return FALSE; } size_t nLen = wcslen(pszDiz)+1; *CustomData = (wchar_t*)malloc(nLen*2); wcscpy(*CustomData, pszDiz); // Заменить некоторые символы wchar_t* pszTab = wcspbrk(*CustomData, L"\t"); while (pszTab) { *pszTab = L' '; pszTab = wcspbrk(pszTab+1, L"\t"); } return TRUE; }
bool CBackgroundInfo::PollBackgroundFile() { bool lbChanged = false; if (gpSet->isShowBgImage && ms_BgImage[0] && ((GetTickCount() - nBgModifiedTick) > BACKGROUND_FILE_POLL) && wcspbrk(ms_BgImage, L"%\\.")) // только для файлов! { WIN32_FIND_DATA fnd = {0}; HANDLE hFind = FindFirstFile(ms_BgImage, &fnd); if (hFind != INVALID_HANDLE_VALUE) { if (fnd.ftLastWriteTime.dwHighDateTime != ftBgModified.dwHighDateTime || fnd.ftLastWriteTime.dwLowDateTime != ftBgModified.dwLowDateTime) { //NeedBackgroundUpdate(); -- поставит LoadBackgroundFile, если у него получится файл открыть lbChanged = LoadBackgroundFile(false); nBgModifiedTick = GetTickCount(); } FindClose(hFind); } } return lbChanged; }
string &QuoteSpace(string &strStr) { if (wcspbrk(strStr, Opt.strQuotedSymbols) ) InsertQuote(strStr); return strStr; }
posix_errno_t efile_altname(ErlNifEnv *env, const efile_path_t *path, ERL_NIF_TERM *result) { ErlNifBinary result_bin; ASSERT_PATH_FORMAT(path); if(is_path_root(path)) { /* Root paths can't be queried so we'll just return them as they are. */ if(!enif_alloc_binary(path->size, &result_bin)) { return ENOMEM; } sys_memcpy(result_bin.data, path->data, path->size); } else { WIN32_FIND_DATAW data; HANDLE handle; WCHAR *name_buffer; int name_length; /* Reject path wildcards. */ if(wcspbrk(&((const WCHAR*)path->data)[LP_PREFIX_LENGTH], L"?*")) { return ENOENT; } handle = FindFirstFileW((const WCHAR*)path->data, &data); if(handle == INVALID_HANDLE_VALUE) { return windows_to_posix_errno(GetLastError()); } FindClose(handle); name_length = wcslen(data.cAlternateFileName); if(name_length > 0) { name_buffer = data.cAlternateFileName; } else { name_length = wcslen(data.cFileName); name_buffer = data.cFileName; } /* Include NUL-terminator; it will be removed after normalization. */ name_length += 1; if(!enif_alloc_binary(name_length * sizeof(WCHAR), &result_bin)) { return ENOMEM; } sys_memcpy(result_bin.data, name_buffer, name_length * sizeof(WCHAR)); } if(!normalize_path_result(&result_bin)) { enif_release_binary(&result_bin); return ENOMEM; } (*result) = enif_make_binary(env, &result_bin); return 0; }
FILE *wfopen(const wchar_t *filename, const wchar_t *mode) { if(!mode || !filename || !*filename) return NULL; //_D(SysLog("fopen: filename[%s], mode[%s] strpbrk%c=NULL", // filename, mode, strpbrk(mode, "rwa")?'!':'=')); if(wcspbrk(mode, L"rwa")==NULL) return NULL; DWORD dwDesiredAccess=0, dwCreationDistribution=0; BOOL R, W, A; R=W=A=FALSE; /* r Open for reading only. w Create for writing. If a file by that name already exists, it will be overwritten. a Append; open for writing at end-of-file or create for writing if the file does not exist. r+ Open an existing file for update (reading and writing). w+ Create a new file for update (reading and writing). If a file by that name already exists, it will be overwritten. a+ Open for append; open (or create if the file does not exist) for update at the end of the file. */ if(wcschr(mode, L'r')) { //_D(SysLog("r - GENERIC_READ")); dwDesiredAccess|=GENERIC_READ; dwCreationDistribution=OPEN_EXISTING; R=TRUE; } if(wcschr(mode, L'w')) { //_D(SysLog("w - GENERIC_WRITE")); dwDesiredAccess|=GENERIC_WRITE; dwCreationDistribution=CREATE_ALWAYS; W=TRUE; } if(wcschr(mode, L'a')) { //_D(SysLog("a - GENERIC_WRITE")); dwDesiredAccess|=GENERIC_WRITE; dwCreationDistribution=OPEN_ALWAYS; A=TRUE; } if(wcschr(mode, L'+')) { //_D(SysLog("+++")); dwDesiredAccess|=GENERIC_WRITE; dwCreationDistribution=CREATE_ALWAYS; if(R) dwDesiredAccess|=GENERIC_WRITE; if(W) dwDesiredAccess|=GENERIC_READ; } HANDLE hFile=CreateFile(filename, dwDesiredAccess, FILE_SHARE_READ, NULL, dwCreationDistribution, 0, NULL); //_D(SysLog("hFile%c=INVALID_HANDLE_VALUE", hFile==INVALID_HANDLE_VALUE?'=':'!')); if(hFile==INVALID_HANDLE_VALUE) return NULL; if(A) fseek((FILE *)hFile, 0, SEEK_END); return (FILE *)hFile; };
/** * Get the length that the string will take and takes into account the * additional length if the string needs to be quoted and if characters need to * be escaped. */ static int ArgStrLen(const wchar_t *s) { int backslashes = 0; int i = wcslen(s); BOOL hasDoubleQuote = wcschr(s, L'"') != nullptr; // Only add doublequotes if the string contains a space or a tab BOOL addDoubleQuotes = wcspbrk(s, L" \t") != nullptr; if (addDoubleQuotes) { i += 2; // initial and final duoblequote } if (hasDoubleQuote) { while (*s) { if (*s == '\\') { ++backslashes; } else { if (*s == '"') { // Escape the doublequote and all backslashes preceding the doublequote i += backslashes + 1; } backslashes = 0; } ++s; } } return i; }
string &QuoteSpace(string &strStr) { if (wcspbrk(strStr, Global->Opt->strQuotedSymbols) ) InsertQuote(strStr); return strStr; }
wchar_t* QuoteSpace(wchar_t *Str) { if (wcspbrk(Str, Global->Opt->strQuotedSymbols) ) InsertQuote(Str); return Str; }
bool CBackgroundInfo::LoadBackgroundFile(bool abShowErrors) { // Пустой путь - значит БЕЗ обоев if (!*ms_BgImage) { return true; } //_ASSERTE(gpConEmu->isMainThread()); _ASSERTE(gpConEmu->isMainThread()); bool lRes = false; BY_HANDLE_FILE_INFORMATION inf = {0}; BITMAPFILEHEADER* pBkImgData = NULL; if (wcspbrk(ms_BgImage, L"%\\.") == NULL) { // May be "Solid color" COLORREF clr = (COLORREF)-1; if (GetColorRef(ms_BgImage, &clr)) { pBkImgData = CreateSolidImage(clr, 128, 128); } } if (!pBkImgData) { wchar_t* exPath = ExpandEnvStr(ms_BgImage); if (!exPath || !*exPath) { if (abShowErrors) { wchar_t szError[MAX_PATH*2]; DWORD dwErr = GetLastError(); _wsprintf(szError, SKIPLEN(countof(szError)) L"Can't expand environment strings:\r\n%s\r\nError code=0x%08X\r\nImage loading failed", ms_BgImage, dwErr); MBoxA(szError); } return false; } pBkImgData = LoadImageEx(exPath, inf); } if (pBkImgData) { ftBgModified = inf.ftLastWriteTime; nBgModifiedTick = GetTickCount(); //NeedBackgroundUpdate(); //MSectionLock SBG; SBG.Lock(&mcs_BgImgData); SafeFree(mp_BgImgData); mb_IsBackgroundImageValid = true; mp_BgImgData = pBkImgData; lRes = true; } return lRes; }
wchar_t* WINAPI QuoteSpace(wchar_t *Str) { if (wcspbrk(Str, Opt.strQuotedSymbols) ) InsertQuote(Str); return Str; }
bool CMatch::IsValidFile(LPCWSTR asFrom, int anLen, LPCWSTR pszInvalidChars, LPCWSTR pszSpacing, int& rnLen) { while (anLen > 0) { wchar_t wc = asFrom[anLen-1]; if (wcschr(pszSpacing, wc) || wcschr(pszInvalidChars, wc)) anLen--; else break; } LPCWSTR pszFile, pszBadChar; if ((anLen <= 0) || !(pszFile = ms_FileCheck.Set(asFrom, anLen)) || ms_FileCheck.IsEmpty()) return false; pszBadChar = wcspbrk(pszFile, pszInvalidChars); if (pszBadChar != NULL) return false; pszBadChar = wcspbrk(pszFile, pszSpacing); if (pszBadChar != NULL) return false; // where are you, regexps... if ((anLen <= 1) || !::IsFilePath(pszFile)) return false; if (pszFile[0] == L'.' && (pszFile[1] == 0 || (pszFile[1] == L'.' && (pszFile[2] == 0 || (pszFile[2] == L'.' && (pszFile[3] == 0)))))) return false; CharLowerBuff(ms_FileCheck.ms_Val, anLen); if ((wcschr(pszFile, L'.') == NULL) //&& (wcsncmp(pszFile, L"make", 4) != 0) && (wcspbrk(pszFile, L"abcdefghijklmnopqrstuvwxyz") == NULL)) return false; CEStr szFullPath; if (mp_RCon) { if (!mp_RCon->GetFileFromConsole(pszFile, szFullPath)) return false; } rnLen = anLen; return true; }
bool IsQuotationNeeded(LPCWSTR pszPath) { bool bNeeded = false; if (pszPath) { bNeeded = (wcspbrk(pszPath, QuotationNeededChars) != 0); } return bNeeded; }
/* Replace the last part of the path to long name. We try to avoid to call FindFirstFileW() since it takes long time. */ static inline size_t replace_to_long_name(wchar_t **wfullpath, size_t size, size_t buffer_size) { WIN32_FIND_DATAW find_data; HANDLE find_handle; /* Skip long name conversion if the path is already long name. Short name is 8.3 format. http://en.wikipedia.org/wiki/8.3_filename This check can be skipped for directory components that have file extensions longer than 3 characters, or total lengths longer than 12 characters. http://msdn.microsoft.com/en-us/library/windows/desktop/aa364980(v=vs.85).aspx */ size_t const max_short_name_size = 8 + 1 + 3; size_t const max_extension_size = 3; size_t path_len = 1, extension_len = 0; wchar_t *pos = *wfullpath; if (size == 3 && pos[1] == L':' && pos[2] == L'\\' && pos[3] == L'\0') { /* root path doesn't need short name expansion */ return size; } /* skip long name conversion if path contains wildcard characters */ if (wcspbrk(pos, L"*?")) { return size; } pos = *wfullpath + size - 1; while (!IS_DIR_SEPARATOR_P(*pos) && pos != *wfullpath) { if (!extension_len && *pos == L'.') { extension_len = path_len - 1; } if (path_len > max_short_name_size || extension_len > max_extension_size) { return size; } path_len++; pos--; } find_handle = FindFirstFileW(*wfullpath, &find_data); if (find_handle != INVALID_HANDLE_VALUE) { size_t trail_pos = pos - *wfullpath + IS_DIR_SEPARATOR_P(*pos); size_t file_len = wcslen(find_data.cFileName); size_t oldsize = size; FindClose(find_handle); size = trail_pos + file_len; if (size > (buffer_size ? buffer_size-1 : oldsize)) { wchar_t *buf = ALLOC_N(wchar_t, (size + 1)); wcsncpy(buf, *wfullpath, trail_pos); if (!buffer_size) xfree(*wfullpath); *wfullpath = buf; }
int __cdecl main(int argc, char *argv[]) { WCHAR *string; WCHAR *key1; WCHAR *key2; WCHAR key3[] = {0}; WCHAR *result; if (PAL_Initialize(argc, argv)) { return FAIL; } string = convert("foo bar baz bar"); key1 = convert("z "); key2 = convert("Q"); result = wcspbrk(string, key1); if (result != string + 3) { Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" "Expected to get pointer to %#p, got %#p\n", convertC(string), convertC(key1), string + 3, result); } result = wcspbrk(string, key2); if (result != NULL) { Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" "Expected to get pointer to %#p, got %#p\n", convertC(string), convertC(key2), NULL, result); } result = wcspbrk(string, key3); if (result != NULL) { Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" "Expected to get pointer to %#p, got %#p\n", convertC(string), convertC(key3), NULL, result); } PAL_Terminate(); return PASS; }
int main( void ) { TESTCASE( wcspbrk( wabcde, L"x" ) == NULL ); TESTCASE( wcspbrk( wabcde, L"xyz" ) == NULL ); TESTCASE( wcspbrk( wabcdx, L"x" ) == &wabcdx[4] ); TESTCASE( wcspbrk( wabcdx, L"xyz" ) == &wabcdx[4] ); TESTCASE( wcspbrk( wabcdx, L"zyx" ) == &wabcdx[4] ); TESTCASE( wcspbrk( wabcde, L"a" ) == &wabcde[0] ); TESTCASE( wcspbrk( wabcde, L"abc" ) == &wabcde[0] ); TESTCASE( wcspbrk( wabcde, L"cba" ) == &wabcde[0] ); return TEST_RESULTS; }
static wchar_t * wcfixmode(const wchar_t *mode) { static wchar_t wcfixedmode[6]; wcfixedmode[4] = L'\0'; wcsncpy(wcfixedmode, mode, 4); if (!wcspbrk(wcfixedmode, L"bt")) { wcscat(wcfixedmode, L"t"); } return wcfixedmode; }
int WINAPI GetCustomDataW(const wchar_t *FilePath, wchar_t **CustomData) { *CustomData = NULL; const wchar_t* pszSlash = wcsrchr(FilePath, L'\\'); if (!pszSlash || pszSlash <= FilePath) return FALSE; if (pszSlash[1] == 0) return FALSE; // Если хотят диз именно для папки - то нужно без слеша string strPath(FilePath, pszSlash-FilePath); // оптимизацией чтения диз-файла занимается сам diz if (diz.Read(strPath) == 0) { // Если диз пустой - сразу выходим return FALSE; } const wchar_t* pszDiz = diz.GetDizTextAddr(pszSlash+1, L"", 0/*???*/); //if (!pszDiz || pszDiz[0] == 0) -- ConvertNameToShort занимает очень много времени //{ // string strShort; // ConvertNameToShort(FilePath, strShort); // pszDiz = diz.GetDizTextAddr(pszSlash+1, strShort, 0/*???*/); //} if (!pszDiz || pszDiz[0] == 0) { return FALSE; } size_t nLen = wcslen(pszDiz)+1; *CustomData = (wchar_t*)malloc(nLen*2); wcscpy(*CustomData, pszDiz); // Заменить некоторые символы wchar_t* pszTab = wcspbrk(*CustomData, L"\t"); while (pszTab) { *pszTab = L' '; pszTab = wcspbrk(pszTab+1, L"\t"); } return TRUE; }
//--------------------------------------------------------------------------- // Windows algorithm is as follows (tested on W2k): // right: // is_delimiter(current) // false: // right(left(current) + 1) // true: // right(right(current) + 1) // left: // right(left(current) + 1) int CALLBACK PathWordBreakProc(wchar_t * Ch, int Current, int Len, int Code) { int Result; UnicodeString ACh(Ch, Len); if (Code == WB_ISDELIMITER) { // we return negacy of what WinAPI docs says Result = !IsPathWordDelimiter(ACh[Current + 1]); } else if (Code == WB_LEFT) { // skip consecutive delimiters while ((Current > 0) && IsPathWordDelimiter(ACh[Current])) { Current--; } Result = ACh.SubString(1, Current - 1).LastDelimiter(PathWordDelimiters); } else if (Code == WB_RIGHT) { if (Current == 0) { // will be called again with Current == 1 Result = 0; } else { const wchar_t * P = wcspbrk(ACh.c_str() + Current - 1, PathWordDelimiters); if (P == NULL) { Result = Len; } else { Result = P - ACh.c_str() + 1; // skip consecutive delimiters while ((Result < Len) && IsPathWordDelimiter(ACh[Result + 1])) { Result++; } } } } else { assert(false); Result = 0; } return Result; }
intptr_t WINAPI MkDirDlgProc(HANDLE hDlg,intptr_t Msg,intptr_t Param1,void* Param2) { switch (Msg) { case DN_LISTCHANGE: { if (Param1 == MKDIR_COMBOBOX_LINKTYPE) { SendDlgMessage(hDlg, DM_ENABLE, MKDIR_EDIT_LINKPATH, ToPtr(Param2 != 0)); } } break; case DN_CLOSE: { if (Param1==MKDIR_OK) { string strDirName=reinterpret_cast<LPCWSTR>(SendDlgMessage(hDlg,DM_GETCONSTTEXTPTR,MKDIR_EDIT,0)); Opt.MultiMakeDir=(SendDlgMessage(hDlg,DM_GETCHECK,MKDIR_CHECKBOX,0)==BSTATE_CHECKED); // это по поводу создания одиночного каталога, который // начинается с пробела! Чтобы ручками не заключать // такой каталог в кавычки if (Opt.MultiMakeDir && !wcspbrk(strDirName,L";,\"")) { QuoteSpaceOnly(strDirName); } // нужно создать только ОДИН каталог if (!Opt.MultiMakeDir) { // уберем все лишние кавычки Unquote(strDirName); // возьмем в кавычки, т.к. могут быть разделители InsertQuote(strDirName); } UserDefinedList* pDirList=reinterpret_cast<UserDefinedList*>(SendDlgMessage(hDlg,DM_GETDLGDATA,0,0)); if (!pDirList->Set(strDirName)) { Message(MSG_WARNING,1,MSG(MWarning),MSG(MIncorrectDirList),MSG(MOk)); return FALSE; } } } break; default: break; } return DefDlgProc(hDlg,Msg,Param1,Param2); }
int expand_names( int argc, LPWSTR argv[] ) { HANDLE fh; WIN32_FIND_DATA fd; LPWSTR path, name; int first; int keep; int i; for (i = 0; i < globbed; ++i) free( glob[i] ); globbed = 0; for (i = 0; i < argc; ++i) { if (*argv[i] == '\0') continue; wcscpy( glob_name, argv[i] ); keep = (all && !recurse && glob_name == glob_path && wcspbrk( glob_name, L"*?" ) == NULL); fh = FindFirstFile( glob_path, &fd ); if (fh == INVALID_HANDLE_VALUE) { if (keep) add_name(); continue; } for (path = name = glob_name; *path; ++path) if (*path == '\\' || *path == '/') name = path + 1; first = globbed; do { if (fd.dwFileAttributes & (hidden | FILE_ATTRIBUTE_DIRECTORY)) { if (keep) add_name(); continue; } wcscpy( name, fd.cFileName ); add_name(); } while (FindNextFile( fh, &fd )); FindClose( fh ); qsort( glob + first, globbed - first, sizeof(LPWSTR), glob_sort ); } return (globbed != 0); }
ATF_TC_BODY(wcspbrk, tc) { static const wchar_t s[] = L"abcdefghijklmnop"; ATF_CHECK_EQ(wcspbrk(s, L""), NULL); ATF_CHECK_EQ(wcspbrk(s, L"qrst"), NULL); ATF_CHECK_EQ(wcspbrk(s, L"a"), s); ATF_CHECK_EQ(wcspbrk(s, L"b"), s + 1); ATF_CHECK_EQ(wcspbrk(s, L"ab"), s); ATF_CHECK_EQ(wcspbrk(s, L"cdef"), s + 2); ATF_CHECK_EQ(wcspbrk(s, L"fedc"), s + 2); }
/* return next token in configuration line */ wchar_t * strdelim(wchar_t **s) { wchar_t *old; int wspace = 0; if (*s == NULL) return (NULL); old = *s; *s = wcspbrk(*s, WHITESPACE QUOTE "="); if (*s == NULL) return (old); if (*s[0] == L'\"') { wmemmove(*s, *s + 1, wcslen(*s)); /* move nul too */ /* Find matching quote */ if ((*s = wcspbrk(*s, QUOTE)) == NULL) { return (NULL); /* no matching quote */ } else { *s[0] = L'\0'; return (old); } } /* Allow only one '=' to be skipped */ if (*s[0] == L'=') wspace = 1; *s[0] = L'\0'; /* Skip any extra whitespace after first token */ *s += wcsspn(*s + 1, WHITESPACE) + 1; if (*s[0] == L'=' && !wspace) *s += wcsspn(*s + 1, WHITESPACE) + 1; return (old); }
bool match(const wchar *pattern,const wchar *string,bool ForceCase) { for (;; ++string) { wchar stringc=touppercw(*string,ForceCase); wchar patternc=touppercw(*pattern++,ForceCase); switch (patternc) { case 0: return(stringc==0); case '?': if (stringc == 0) return(false); break; case '*': if (*pattern==0) return(true); if (*pattern=='.') { if (pattern[1]=='*' && pattern[2]==0) return(true); const wchar *dot=wcschr(string,'.'); if (pattern[1]==0) return (dot==NULL || dot[1]==0); if (dot!=NULL) { string=dot; if (wcspbrk(pattern,L"*?")==NULL && wcschr(string+1,'.')==NULL) return(mwcsicompc(pattern+1,string+1,ForceCase)==0); } } while (*string) if (match(pattern,string++,ForceCase)) return(true); return(false); default: if (patternc != stringc) { // Allow "name." mask match "name" and "name.\" match "name\". if (patternc=='.' && (stringc==0 || stringc=='\\' || stringc=='.')) return(match(pattern,string,ForceCase)); else return(false); } break; } } }
bool CmdArg::IsPossibleSwitch() const { // Nothing to compare? if (IsEmpty()) return false; if ((ms_Val[0] != L'-') && (ms_Val[0] != L'/')) return false; // We do not care here about "-new_console:..." or "-cur_console:..." // They are processed by RConStartArgsEx // But ':' removed from checks, because otherwise ConEmu will not warn // on invalid usage of "-new_console:a" for example // Also, support smth like "-inside=\eCD /d %1" LPCWSTR pszDelim = wcspbrk(ms_Val+1, L"=:"); LPCWSTR pszInvalids = wcspbrk(ms_Val+1, L"\\/|.&<>^"); if (pszInvalids && (!pszDelim || (pszInvalids < pszDelim))) return false; // Well, looks like a switch (`-run` for example) return true; }
bool IsNameUsable(const wchar *Name) { #ifndef _UNIX if (Name[0] && Name[1] && wcschr(Name+2,':')!=NULL) return false; for (const wchar *s=Name;*s!=0;s++) { if ((uint)*s<32) return false; if ((*s==' ' || *s=='.') && IsPathDiv(s[1])) return false; } #endif return *Name!=0 && wcspbrk(Name,L"?*<>|\"")==NULL; }
/* * @implemented */ int CHString::FindOneOf(LPCWSTR lpszCharSet) const { WCHAR *Found; // Let's use appropriate helper Found = wcspbrk(m_pchData, lpszCharSet); // We have to return a position, so compute it if (Found) { return (Found - m_pchData); } // Otherwise, return no position return -1; }
// ========================================================================= // Returns TRUE if the mountpoint specified is a valid mountpoint which may // be used BOOL ValidateMountpoint( HWND hWnd, WCHAR* mountpoint, BOOL SkipExistsCheck, BOOL silent ) { BOOL retval = FALSE; if (wcslen(mountpoint) == 0) { if (!(silent)) { MsgError(hWnd, _("Please specify a mountpoint")); } } else if (wcscmp(RESERVED_MOUNTPOINT, mountpoint) == 0) { if (!(silent)) { MsgError(hWnd, _("The mountpoint specified is reserved; please enter a different mountpoint")); } } else if (wcspbrk(mountpoint, RESERVED_MOUNTPOINT_CHARS) != NULL) { if (!(silent)) { MsgError(hWnd, _("The mountpoint specified includes a invalid character; please enter a different mountpoint")); } } else if ( (!(SkipExistsCheck)) && (GetFileAttributes(mountpoint) != INVALID_FILE_ATTRIBUTES) ) { if (!(silent)) { MsgError(hWnd, _("The mountpoint specified already exists; please enter a different mountpoint")); } } else { // Everything OK retval = TRUE; } return retval; }
//------------------------------------------------------------------------------------- LPWSTR Sanitize(LPWSTR szString, WCHAR cReplace = L'-') { //strip off invalid characters for a filename static LPCWSTR szInvalidCharacters = L"\\/:*?\"<>|"; LPWSTR pPos; while ((pPos = wcspbrk(szString, szInvalidCharacters)) != NULL) *pPos = cReplace; //trim trailing spaces pPos = szString + wcslen(szString) - 1; while (pPos >= szString && (*pPos == L' ' || *pPos == L'\t')) *pPos-- = L'\0'; //trim leading spaces pPos = szString; while (*pPos == L' ' || *pPos == L'\t') pPos++; return pPos; }
// Returns 0 if succeeded, otherwise the error code int NextLine(const wchar_t** asLines, CEStr &rsLine, NEXTLINEFLAGS Flags /*= NLF_TRIM_SPACES|NLF_SKIP_EMPTY_LINES*/) { if (!asLines || !*asLines) return CERR_CMDLINEEMPTY; const wchar_t* psz = *asLines; //const wchar_t szSpaces[] = L" \t"; //const wchar_t szLines[] = L"\r\n"; //const wchar_t szSpacesLines[] = L" \t\r\n"; if ((Flags & (NLF_TRIM_SPACES|NLF_SKIP_EMPTY_LINES)) == (NLF_TRIM_SPACES|NLF_SKIP_EMPTY_LINES)) psz = SkipNonPrintable(psz); else if (Flags & NLF_TRIM_SPACES) while (*psz == L' ' || *psz == L'\t') psz++; else if (Flags & NLF_SKIP_EMPTY_LINES) while (*psz == L'\r' || *psz == L'\n') psz++; if (!*psz) { *asLines = psz; return CERR_CMDLINEEMPTY; } const wchar_t* pszEnd = wcspbrk(psz, L"\r\n"); if (!pszEnd) { pszEnd = psz + lstrlen(psz); } const wchar_t* pszTrim = pszEnd; if (*pszEnd == L'\r') pszEnd++; if (*pszEnd == L'\n') pszEnd++; if (Flags & NLF_TRIM_SPACES) { while ((pszTrim > psz) && ((*(pszTrim-1) == L' ') || (*(pszTrim-1) == L'\t'))) pszTrim--; } _ASSERTE(pszTrim >= psz); rsLine.Set(psz, pszTrim-psz); psz = pszEnd; *asLines = psz; return 0; }
int wexpand(wchar_t* name, int expand_wildcards) { wchar_t* s; WIN32_FIND_DATAW fd; HANDLE hFile; BOOLEAN first = TRUE; wchar_t buffer[256]; uintptr_t pos; if (expand_wildcards && (s = wcspbrk(name, L"*?"))) { hFile = FindFirstFileW(name, &fd); if (hFile != INVALID_HANDLE_VALUE) { while(s != name && *s != L'/' && *s != L'\\') s--; pos = s - name; if (*s == L'/' || *s == L'\\') pos++; wcsncpy(buffer, name, pos); do { if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { wcscpy(&buffer[pos], fd.cFileName); if (wadd(_wcsdup(buffer)) < 0) { FindClose(hFile); return -1; } first = FALSE; } } while(FindNextFileW(hFile, &fd)); FindClose(hFile); } } if (first) { if (wadd(name) < 0) return -1; } else free(name); return 0; }