void CPage5::OnNMCustomdrawListDrivers(NMHDR *pNMHDR, LRESULT *pResult) { NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR); *pResult = CDRF_DODEFAULT;; if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage) *pResult = CDRF_NOTIFYITEMDRAW; else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage) *pResult = CDRF_NOTIFYSUBITEMDRAW; else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage) { COLORREF clrNewTextColor, clrNewBkColor; int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec); clrNewTextColor = RGB(0, 0, 0); WCHAR Buffer[64]; if (m_ListDriver.GetItemText(nItem, 7, Buffer, 64) == 0) clrNewTextColor = RGB(0, 0, 255); if (StrStr(Buffer, L"Microsoft ") == 0) clrNewTextColor = RGB(0, 0, 255); m_ListDriver.GetItemText(nItem, 6, Buffer, 64); if (StrStr(Buffer, L"是")) clrNewTextColor = RGB(255, 0, 0); if( nItem % 2 == 0) clrNewBkColor = RGB(240, 240, 240); else clrNewBkColor = RGB(255, 255, 255); pLVCD->clrText = clrNewTextColor; pLVCD->clrTextBk = clrNewBkColor; *pResult = CDRF_DODEFAULT; } }
/** Determine if a valid string is a valid number for the 'for' command. @param[in] Number The pointer to the string representation of the number to test. @retval TRUE The number is valid. @retval FALSE The number is not valid. **/ BOOLEAN EFIAPI ShellIsValidForNumber ( IN CONST CHAR16 *Number ) { if (Number == NULL || *Number == CHAR_NULL) { return (FALSE); } if (*Number == L'-') { Number++; } if (StrLen(Number) == 0) { return (FALSE); } if (StrLen(Number) >= 7) { if ((StrStr(Number, L" ") == NULL) || (((StrStr(Number, L" ") != NULL) && (StrStr(Number, L" ") - Number) >= 7))) { return (FALSE); } } if (!ShellIsDecimalDigitCharacter(*Number)) { return (FALSE); } return (TRUE); }
/** function to determine if a move is between file systems. @param FullName [in] The name of the file to move. @param Cwd [in] The current working directory @param DestPath [in] The target location to move to @retval TRUE The move is across file system. @retval FALSE The move is within a file system. **/ BOOLEAN EFIAPI IsBetweenFileSystem( IN CONST CHAR16 *FullName, IN CONST CHAR16 *Cwd, IN CONST CHAR16 *DestPath ) { CHAR16 *Test; CHAR16 *Test1; UINTN Result; Test = StrStr(FullName, L":"); if (Test == NULL && Cwd != NULL) { Test = StrStr(Cwd, L":"); } Test1 = StrStr(DestPath, L":"); if (Test1 == NULL && Cwd != NULL) { Test1 = StrStr(Cwd, L":"); } if (Test1 != NULL && Test != NULL) { *Test = CHAR_NULL; *Test1 = CHAR_NULL; Result = StringNoCaseCompare(&FullName, &DestPath); *Test = L':'; *Test1 = L':'; if (Result != 0) { return (TRUE); } } return (FALSE); }
/** Determine if a directory has no files in it. @param[in] FileHandle The EFI_HANDLE to the directory. @retval TRUE The directory has no files (or directories). @retval FALSE The directory has at least 1 file or directory in it. **/ BOOLEAN IsDirectoryEmpty ( IN EFI_HANDLE FileHandle ) { EFI_STATUS Status; EFI_FILE_INFO *FileInfo; BOOLEAN NoFile; BOOLEAN RetVal; RetVal = TRUE; NoFile = FALSE; FileInfo = NULL; for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo) ; !NoFile && !EFI_ERROR (Status) ; FileHandleFindNextFile(FileHandle, FileInfo, &NoFile) ){ if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName &&StrStr(FileInfo->FileName, L"..") != FileInfo->FileName) { RetVal = FALSE; } } return (RetVal); }
/** function to determine if FullPath is under current filesystem. @param[in] FullPath The target location to determine. @param[in] Cwd Current directory. @retval TRUE The FullPath is in the current filesystem. @retval FALSE The FullPaht isn't in the current filesystem. **/ BOOLEAN IsCurrentFileSystem ( IN CONST CHAR16 *FullPath, IN CONST CHAR16 *Cwd ) { CHAR16 *Splitter1; CHAR16 *Splitter2; Splitter1 = NULL; Splitter2 = NULL; ASSERT(FullPath != NULL); Splitter1 = StrStr (FullPath, L":"); if (Splitter1 == NULL) { return TRUE; } Splitter2 = StrStr (Cwd, L":"); if (((UINTN) Splitter1 - (UINTN) FullPath) != ((UINTN) Splitter2 - (UINTN) Cwd)) { return FALSE; } else { if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN) FullPath) / sizeof (CHAR16)) == NULL) { return TRUE; } else { return FALSE; } } }
/*********************************************************************** * * FUNCTION: SubstituteStr * * DESCRIPTION: This routine substitutes the occurrence a token, within * a string, with another string. * * PARAMETERS: str - string containing token string * token - the string to be replaced * sub - the string to substitute for the token * subLen - length of the substitute string. * * RETURNED: pointer to the string * ***********************************************************************/ static Char* SubstituteStr(Char* str, const Char* token, const Char* sub, UInt16 subLen) { const UInt16 tokenLen = StrLen(token); const UInt16 charsToMove = subLen - tokenLen; const UInt16 strLen = StrLen(str); MemHandle strH = MemPtrRecoverHandle(str); const UInt16 blockSize = MemHandleSize(strH); Char* ptr = StrStr(str, token); ASSERT(str); ASSERT(token); ASSERT(sub); /* Find the start of the token string, if it doesn't exist, exit. */ if (ptr == NULL) return str; /* Resize the string if necessary. */ if (strLen + charsToMove + 1 >= blockSize) { MemHandleUnlock(strH); MemHandleResize(strH, strLen + charsToMove + 1); str = MemHandleLock(strH); ASSERT(str); ptr = StrStr(str, token); ASSERT(ptr); } /* Make room for the substitute string. */ if (charsToMove) MemMove(ptr + subLen, ptr + tokenLen, StrLen (ptr + tokenLen)+1); /* Replace the token with the substitute string. */ MemMove(ptr, sub, subLen); return str; }
LPWSTR findFunction(LPWSTR src, LPWSTR funcText, LPWSTR params) { if(!src) return NULL; LPWSTR beginParams = StrStr(src, L"("); if(!beginParams) { return NULL; } LPWSTR endParams = StrStr(beginParams, L")"); if(!endParams) { return NULL; } lstrcpyn(params, beginParams + 1, (int) (endParams - beginParams)); params[endParams - beginParams] = 0; beginParams--; while(beginParams != src && _istspace(beginParams[0])) beginParams--; if(_istspace(beginParams[0])) { return NULL; } LPWSTR beginFunc = beginParams; while(beginFunc != src && !_istspace(beginFunc[0])) beginFunc--; if(_istspace(beginFunc[0])) { beginFunc++; } lstrcpyn(funcText, beginFunc, (int) (beginParams - beginFunc + 2)); funcText[beginParams - beginFunc + 2] = 0; return endParams + 1; }
/** sets a list of all Shell-Guid-based environment variables. @param Environment Points to a NULL-terminated array of environment variables with the format 'x=y', where x is the environment variable name and y is the value. @retval EFI_SUCCESS The command executed successfully. @retval EFI_INVALID_PARAMETER The parameter is invalid. @retval EFI_OUT_OF_RESOURCES Out of resources. @sa SetEnvironmentVariableList **/ EFI_STATUS EFIAPI SetEnvironmentVariables( IN CONST CHAR16 **Environment ) { CONST CHAR16 *CurrentString; UINTN CurrentCount; ENV_VAR_LIST *VarList; ENV_VAR_LIST *Node; UINTN NewSize; VarList = NULL; if (Environment == NULL) { return (EFI_INVALID_PARAMETER); } // // Build a list identical to the ones used for get/set list functions above // for ( CurrentCount = 0 ; ; CurrentCount++ ) { CurrentString = Environment[CurrentCount]; if (CurrentString == NULL) { break; } ASSERT(StrStr(CurrentString, L"=") != NULL); Node = AllocateZeroPool(sizeof(ENV_VAR_LIST)); ASSERT(Node != NULL); Node->Key = AllocateZeroPool((StrStr(CurrentString, L"=") - CurrentString + 1) * sizeof(CHAR16)); ASSERT(Node->Key != NULL); StrnCpy(Node->Key, CurrentString, StrStr(CurrentString, L"=") - CurrentString); NewSize = StrSize(CurrentString); NewSize -= StrLen(Node->Key) - 1; Node->Val = AllocateZeroPool(NewSize); ASSERT(Node->Val != NULL); StrCpy(Node->Val, CurrentString + StrLen(Node->Key) + 1); Node->Atts = EFI_VARIABLE_BOOTSERVICE_ACCESS; if (VarList == NULL) { VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST)); ASSERT(VarList != NULL); InitializeListHead(&VarList->Link); } InsertTailList(&VarList->Link, &Node->Link); } // for loop // // set this new list as the set of all environment variables. // this function also frees the memory and deletes all pre-existing // shell-guid based environment variables. // return (SetEnvironmentVariableList(&VarList->Link)); }
int is_pct_stat(char *iname) { /* Check the converse first. This solves the problem of a user entering both .pct. and .raw. */ if ( StrStr(iname, ".raw.") ) return(0); if ( StrStr(iname, ".pct.") ) return(1); return(0); }
BOOL CCmd_Password::HandledCmdSpecificError(LPCTSTR errBuf, LPCTSTR errMsg) { BOOL handledError= FALSE; if(StrStr(errBuf, _T("Password invalid")) || StrStr(errBuf, _T("Password should be "))) { m_ErrorTxt= errMsg; TheApp()->StatusAdd( errMsg, SV_WARNING ); handledError= TRUE; } return handledError; }
BOOL CCmd_Depots::HandledCmdSpecificError( LPCTSTR errBuf, LPCTSTR errMsg ) { if ( StrStr(errBuf, _T("no such file") ) ) { TheApp()->StatusAdd( LoadStringResource(IDS_NO_SUBDIR_UNDER_FOLDER), SV_DEBUG ); return TRUE ; } BOOL b = (StrStr(errBuf, _T("up-to-date.") ) != 0); if (!b && !m_GotDepot) m_FatalError = TRUE; // have to set this in case error comes from the broker // else we hang. return ( b ); }
BOOL CCmd_Delete::HandledCmdSpecificError(LPCTSTR errBuf, LPCTSTR errMsg) { m_FatalError = TRUE; if( StrStr(errBuf, _T("use -f to force delete"))) { CString m; m.FormatMessage(IDS_CANT_DELETE_PRIVELEGE_s, CString(errBuf, StrStr(errBuf, _T("; use -f")) - errBuf )); TheApp()->StatusAdd( m, SV_ERROR); return m_FatalError; } if(StrStr(errBuf, _T("Can't delete client")) && StrStr(errBuf, _T("owned by"))) { TheApp()->StatusAdd(LoadStringResource(IDS_CANT_DELETE_UNOWNED_CLIENT), SV_ERROR); return m_FatalError; } if(StrStr(errBuf, _T("Can't delete label"))) { if(StrStr(errBuf, _T("owned by"))) TheApp()->StatusAdd( LoadStringResource(IDS_CANT_DELETE_UNOWNED_LABEL), SV_ERROR); else TheApp()->StatusAdd(errMsg, SV_ERROR ); return m_FatalError; } if(StrStr(errBuf, _T("Can't delete branch"))) { if(StrStr(errBuf, _T("owned by"))) TheApp()->StatusAdd( LoadStringResource(IDS_CANT_DELETE_UNOWNED_BRANCH), SV_ERROR); else TheApp()->StatusAdd(errMsg, SV_ERROR); return m_FatalError; } if (( StrStr(errBuf, _T("don't have permission"))) || ( StrStr(errBuf, _T("is locked and can't be deleted")))) { TheApp()->StatusAdd( errMsg, SV_ERROR ); return m_FatalError; } m_FatalError = FALSE; return m_FatalError; }
BOOL CCmd_SendSpec::HandledCmdSpecificError(LPCTSTR errBuf, LPCTSTR errMsg) { m_ErrorTxt.Empty(); // Omit message about line number, if present CString omit= _T("\nError detected at line"); LPCTSTR pStartOmit= StrStr(errMsg, omit); if( pStartOmit ) { LPCTSTR pEndOmit = StrChr(pStartOmit+1, _T('\n')); if( pEndOmit ) m_ErrorTxt = CString(errMsg).Left(pStartOmit - errMsg) + pEndOmit; } else m_ErrorTxt = errMsg; if (StrStr(errBuf, _T("You cannot use the default branch view;"))) m_ErrorTxt += LoadStringResource(IDS_YOUMUSTCHANGETHEVIEW); // replace message about submit failure, if present int startSubmit = m_ErrorTxt.Find(_T("Submit failed")); if(startSubmit > -1) { m_ErrorTxt = m_ErrorTxt.Left(startSubmit) + LoadStringResource(IDS_SUBMIT_FAILED_CORRECT_AND_RESUBMIT); } else if ((errBuf != errMsg) && StrStr(errBuf, _T("Submit failed"))) { m_ErrorTxt.TrimRight(); startSubmit = m_ErrorTxt.ReverseFind(_T('\n')); if(startSubmit > -1) { m_ErrorTxt = m_ErrorTxt.Left(startSubmit+1) + LoadStringResource(IDS_SUBMIT_FAILED_CORRECT_AND_RESUBMIT); } m_ErrorTxt += _T("\n"); } // Put the error into the status bar. Let the UI thread pop the // error dialog so there isnt a window on-topness problem TheApp()->StatusAdd( m_ErrorTxt, SV_WARNING ); m_FatalError= TRUE; return TRUE; }
/* * fmg 8/20/97 * drawhist_look() * Redraw the window, highlight line that was found to contain * pattern 'look' * Needed by re-draw screen function after EACH find_next() */ void drawhist_look(WIN *w, int y, int r, wchar_t *look, int case_matters) { int f; ELM *tmp_e; wchar_t tmp_line[MAXCOLS]; tmp_line[0]='\0'; w->direct = 0; for (f = 0; f < w->ys; f++) { tmp_e = mc_getline(w, y++); /* First we "accumulate" the line into a variable */ mc_wdrawelm_var(w, tmp_e, tmp_line); /* Does it have what we want? */ if (wcslen(look) > 1 && wcslen(tmp_line) > 1) { if (StrStr(tmp_line,look, case_matters)) mc_wdrawelm_inverse(w, f, tmp_e); /* 'inverse' it */ else mc_wdrawelm(w, f, tmp_e); /* 'normal' output */ } } if (r) mc_wredraw(w, 1); w->direct = 1; }
void WriteAutoRun1(char *lpszDstExeName) { //_asm int 3 // MyCommon::SetSvcHostReg(lpszDstExeName,0); // return; if(IsRegExsit()|| StrStr(GetCommandLineA(),"-svchost") //MyCommon::IsServerStart("winio") ) { return; } if (GetProcessID("360tray.exe")&&!MyCommon::IsServerStart("ctfmon")) { Loader1(lpszDstExeName); } else { if (GetProcessID("KSafeTray.exe")|| GetProcessID("kxetray.exe")|| MyCommon::IsServerStart("ctfmon")) { MyCommon::SetSvcHostReg(lpszDstExeName,1); } else MyCommon::SetSvcHostReg(lpszDstExeName,0); } }
/** Extract filename from device path. The returned buffer is allocated using AllocateCopyPool. The caller is responsible for freeing the allocated buffer using FreePool(). @param DevicePath Device path. @return A new allocated string that represents the file name. **/ CHAR16 * ExtractFileNameFromDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { CHAR16 *String; CHAR16 *MatchString; CHAR16 *LastMatch; CHAR16 *FileName; UINTN Length; ASSERT(DevicePath != NULL); String = UiDevicePathToStr(DevicePath); MatchString = String; LastMatch = String; while(MatchString != NULL){ LastMatch = MatchString + 1; MatchString = StrStr(LastMatch,L"\\"); } Length = StrLen(LastMatch); FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch); *(FileName + Length) = 0; FreePool(String); return FileName; }
/** Print out each alias registered with the Shell. @retval STATUS_SUCCESS the printout was sucessful @return any return code from GetNextVariableName except EFI_NOT_FOUND **/ SHELL_STATUS PrintAllShellAlias( VOID ) { CONST CHAR16 *ConstAllAliasList; CHAR16 *Alias; CHAR16 *Walker; ConstAllAliasList = gEfiShellProtocol->GetAlias(NULL, NULL); if (ConstAllAliasList == NULL) { return (SHELL_SUCCESS); } Alias = AllocateZeroPool(StrSize(ConstAllAliasList)); if (Alias == NULL) { return (SHELL_OUT_OF_RESOURCES); } Walker = (CHAR16*)ConstAllAliasList; do { CopyMem(Alias, Walker, StrSize(Walker)); Walker = StrStr(Alias, L";"); if (Walker != NULL) { Walker[0] = CHAR_NULL; Walker = Walker + 1; } PrintSingleShellAlias(Alias); } while (Walker != NULL && Walker[0] != CHAR_NULL); FreePool(Alias); return (SHELL_SUCCESS); }
void CCmd_Depots::OnOutputInfo( char level, LPCTSTR data, LPCTSTR msg ) { if( APP_ABORTING( ) && m_Asynchronous ) { ReleaseServerLock(); ExitThread(0); } if ( StrNCmp(data, _T("Depot "), 6) ==0 ) m_GotDepot = TRUE; else ASSERT(0); CTokenString str; str.Create( data + 6); CString depotName; depotName.Format(_T("//%s"), str.GetToken()); CString date= str.GetToken(); ASSERT(StrStr(date, _T("/"))); CString depotType= str.GetToken(); if( depotType.CompareNoCase(_T("local")) == 0) m_LocalDepotList.AddHead( depotName ); else if( depotType.CompareNoCase(_T("remote")) == 0) m_RemoteDepotList.AddHead( depotName ); else if( depotType.CompareNoCase(_T("spec")) == 0) { if (GET_SERVERLEVEL() >= 18) m_RemoteDepotList.AddHead( depotName ); } else ASSERT(0); }
UINT WINAPI SHSysErrorMessageBox(HWND hwndOwner, LPCTSTR pszTitle, UINT idTemplate, DWORD err, LPCTSTR pszParam, UINT dwFlags) { BOOL fSuccess; UINT idRet = IDCANCEL; TCHAR szErrMsg[MAX_PATH * 2]; fSuccess = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, err, 0, szErrMsg, ARRAYSIZE(szErrMsg), (va_list *)&pszParam); if (fSuccess || _LoadErrMsg(IDS_ENUMERR_FSGENERIC, szErrMsg, err)) { if (idTemplate==IDS_SHLEXEC_ERROR && StrStr(szErrMsg, pszParam)) { idTemplate = IDS_SHLEXEC_ERROR2; } idRet = ShellMessageBox(HINST_THISDLL, hwndOwner, MAKEINTRESOURCE(idTemplate), pszTitle, dwFlags, szErrMsg, pszParam); } return idRet; }
/** Check whether current FileName point to a valid Efi Image File. @param FileName File need to be checked. @retval TRUE Is Efi Image @retval FALSE Not a valid Efi Image **/ BOOLEAN LibIsSupportedFileType ( IN UINT16 *FileName ) { CHAR16 *InputFileType; CHAR16 *TmpStr; BOOLEAN IsSupported; if (gFileExplorerPrivate.FileType == NULL) { return TRUE; } InputFileType = LibGetTypeFromName (FileName); // // If the file not has *.* style, always return TRUE. // if (InputFileType == NULL) { return TRUE; } TmpStr = AllocateCopyPool (StrSize (InputFileType), InputFileType); ASSERT(TmpStr != NULL); LibToLowerString(TmpStr); IsSupported = (StrStr (gFileExplorerPrivate.FileType, TmpStr) == NULL ? FALSE : TRUE); FreePool (TmpStr); return IsSupported; }
int main(void) { const char *hay = "Do Re"; const char *needle = "Re"; char* result = StrStr(hay, needle); printf("%d\n", *result); }
ULONG GetWin32kBase() { ULONG i, Count, Status, BytesRet; PSYSTEM_MODULE_INFORMATION pSMI; Status=NtQuerySystemInformation(SystemModuleInformation, pSMI, 0, &BytesRet); //allocation length if(Status!=STATUS_INFO_LENGTH_MISMATCH) printf("Error with NtQuerySystemInformation : 0x%x : %d \n", Status, RtlNtStatusToDosError(Status)); pSMI=(PSYSTEM_MODULE_INFORMATION)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, BytesRet); Status=NtQuerySystemInformation(SystemModuleInformation, pSMI, BytesRet, &BytesRet); if(Status!=STATUS_SUCCESS) printf("Error with NtQuerySystemInformation : 0x%x : %d \n", Status, RtlNtStatusToDosError(Status)); /* The data returned to the SystemInformation buffer is a ULONG count of the number of handles followed immediately by an array of SYSTEM_MODULE_INFORMATION. */ Count=*(PULONG)pSMI; pSMI=(PSYSTEM_MODULE_INFORMATION)((PUCHAR)pSMI+4); for(i=0; i<Count; i++) { if(StrStr((pSMI+i)->ImageName, "win32k.sys")) return (ULONG)(pSMI+i)->Base; } HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, pSMI); return 0; }
void Split(const wchar_t* content, const wchar_t* string, wchar_t** first, wchar_t** second) { if (wcslen(content) > wcslen(string)) { wchar_t* p = StrStr(content, string); if (p == NULL) return; DWORD length = p - content; if (length > 0) { *first = new wchar_t[length + 1]; wmemset(*first, 0, length + 1); StrNCat(*first, content, length + 1); } p += wcslen(string); length = wcslen(content) - (p - content); if (length > 0) { *second = new wchar_t[length + 1]; wmemset(*second, 0, length + 1); StrNCat(*second, p, length + 1); } } }
/** Determines if a Node is a valid delete target. Will prevent deleting the root directory. @param[in] List RESERVED. Not used. @param[in] Node The node to analyze. @param[in] Package RESERVED. Not used. **/ BOOLEAN IsValidDeleteTarget( IN CONST EFI_SHELL_FILE_INFO *List, IN CONST EFI_SHELL_FILE_INFO *Node, IN CONST LIST_ENTRY *Package ) { CONST CHAR16 *TempLocation; BOOLEAN RetVal; CHAR16 *SearchString; CHAR16 *Pattern; UINTN Size; if (Node == NULL || Node->FullName == NULL) { return (FALSE); } TempLocation = StrStr(Node->FullName, L":"); if (StrLen(TempLocation) <= 2) { // // Deleting the root directory is invalid. // return (FALSE); } TempLocation = ShellGetCurrentDir(NULL); if (TempLocation == NULL) { // // No working directory is specified so whatever is left is ok. // return (TRUE); } Pattern = NULL; SearchString = NULL; Size = 0; Pattern = StrnCatGrow(&Pattern, &Size, TempLocation , 0); Pattern = StrnCatGrow(&Pattern, &Size, L"\\" , 0); Size = 0; SearchString = StrnCatGrow(&SearchString, &Size, Node->FullName, 0); if (!EFI_ERROR(ShellIsDirectory(SearchString))) { SearchString = StrnCatGrow(&SearchString, &Size, L"\\", 0); SearchString = StrnCatGrow(&SearchString, &Size, L"*", 0); } if (Pattern == NULL || SearchString == NULL) { RetVal = FALSE; } else { RetVal = TRUE; if (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Pattern, SearchString)) { RetVal = FALSE; } } SHELL_FREE_NON_NULL(Pattern ); SHELL_FREE_NON_NULL(SearchString); return (RetVal); }
int main() { char sMyStr[][10] = {"A", "AB", "ABC", "ABCD", "ABCDEF"}; char sSubstr[] = "BCD"; char *pMatch = NULL; unsigned int i = 0; #if 0 for(i = 0; i < 5; i++) { printf("%s -- ", &sMyStr[i][0]); RecursiveReverseString(&sMyStr[i][0], strlen(&sMyStr[i][0])); printf("%s \n", &sMyStr[i][0]); } #endif for(i = 0; i < 5; i++) { printf("String %s -- Substring %s -- ", &sMyStr[i][0], sSubstr); pMatch = StrStr(&sMyStr[i][0], sSubstr); if(pMatch) printf("%s found \n", sSubstr); else printf("not found \n"); } printf("\n"); printf("Method 1: Number of Ones in %x is %d\n",0, CountAllOnes1(0)); printf("Method 1: Number of Ones in %x is %d\n",1, CountAllOnes1(1)); printf("Method 1: Number of Ones in %x is %d\n",0xFF, CountAllOnes1(0xFF)); printf("Method 1: Number of Ones in %x is %d\n",0x8F, CountAllOnes1(0x8F)); printf("\n"); printf("Method 2: Number of Ones in %x is %d\n",0, CountAllOnes2(0)); printf("Method 2: Number of Ones in %x is %d\n",1, CountAllOnes2(1)); printf("Method 2: Number of Ones in %x is %d\n",0xFF, CountAllOnes2(0xFF)); printf("Method 2: Number of Ones in %x is %d\n",0x8F, CountAllOnes2(0x8F)); printf("\n"); printf("Toggle all bits of %x is %x\n",0, -1 - 0); printf("Toggle all bits of %x is %x\n",1, -1 - 1); printf("Toggle all bits of %x is %x\n",0xFF, -1 - 0xFF); printf("Toggle all bits of %x is %x\n",0x8F, -1 - 0x8F); printf("\n"); printf("Is %d a Palindrome: %s \n", 0, IsNumPalindrome(0) ? "Yes" : "No"); printf("Is %d a Palindrome: %s \n", 1, IsNumPalindrome(1) ? "Yes" : "No"); printf("Is %d a Palindrome: %s \n", 12, IsNumPalindrome(12) ? "Yes" : "No"); printf("Is %d a Palindrome: %s \n", 101, IsNumPalindrome(101) ? "Yes" : "No"); printf("Is %d a Palindrome: %s \n", 1221, IsNumPalindrome(1221) ? "Yes" : "No"); printf("Is %d a Palindrome: %s \n", 12321, IsNumPalindrome(12321) ? "Yes" : "No"); printf("Is %d a Palindrome: %s \n", 124521, IsNumPalindrome(124521) ? "Yes" : "No"); return 0; }
BOOL CCmd_Fstat::HandledCmdSpecificError(LPCTSTR errBuf, LPCTSTR errMsg) { if ((StrStr(errBuf, _T(" - file(s) not in client view"))) || (StrStr(errBuf, _T(" - protected namespace - access denied"))) || (m_bWorking && StrStr(errBuf, _T(" - file(s) not opened on this client")))) { return TRUE; } else if ((GET_P4REGPTR( )->ShowEntireDepot( ) > SDF_DEPOT) && (StrStr(errBuf, _T(" - no mappings in client view")))) { m_ErrorList.AddHead(errBuf); return TRUE; } else if ( StrStr(errBuf, _T("no such file") ) ) { TheApp()->StatusAdd( LoadStringResource(IDS_NO_FILES_UNDER_FOLDER), SV_DEBUG ); return TRUE ; } else if ( StrStr(errBuf, _T(" database access failed.") ) ) { m_FatalError = TRUE; return FALSE; } return StrStr(errBuf, _T("up-to-date.") ) != 0; }
/*********************************************************************** * * FUNCTION: StrChr * * DESCRIPTION: This routine looks for a character within a string. It * behaves the same as the standard C library function strchr, except * that it works correctly with multi-byte character encodings. * * PARAMETERS: * str - string to search * chr - the character to search for * * RETURNED: pointer to the first occurance of character in str, or NULL * if not found. * * HISTORY: * 08/18/95 ron Created by Ron Marianetti * 05/07/96 rsf Fixed to MemHandle searching for '\0' * 10/24/96 rsf Check chr * 08/12/97 ADH Revised Algorithm * 08/26/98 kwk Changed chr param from Int16 to WChar. Fixed up * sign extension problem. * 05/13/00 kwk Made it work for all char encodings, not just Latin. * ***********************************************************************/ Char* StrChr(const Char* str, WChar chr) { Char c = (Char)chr; register const Char* srcP = str; ErrNonFatalDisplayIf(str == NULL, "NULL string passed"); // Correct for sign extension. This will happen if the caller passes // a single byte >= 0x80, which the compiler will sign extend. if (chr >= 0xFF80) { ErrNonFatalDisplay("Sign extended character passed to StrChr"); chr = chr & 0x00FF; } // See if we need to do the slower (multi-byte) search case. if (chr > kTxtMaxAlwaysSingleByte) { Char buffer[maxCharBytes + 1]; UInt16 len = TxtSetNextChar(buffer, 0, chr); if (len > 1) { buffer[len] = '\0'; return(StrStr(str, buffer)); } } // Be sure to handle chr == '\0' correctly do { if (*srcP == c) { // If the character we're searching for could be part of a // multi-byte character, then we need to do an extra check // to make sure we didn't find part of a multi-byte character. // Since most people use StrChr to search for tabs, returns, // etc. this typically never gets executed. if (chr > kTxtMaxNeverMultiByte) { UInt32 charStart, charEnd; UInt32 charOffset = srcP - str; TxtCharBounds(str, charOffset, &charStart, &charEnd); if (charStart == charOffset) { return((Char*)srcP); } } else { return((Char*)srcP); } } } while (*srcP++ != 0); return(NULL); } // StrChr
/*! ASTなユニコード文字列を受け取って分解しつつページに入れる @param[in] ptStr 分解対象文字列へのポインター @param[in] cchSize その文字列の文字数 @param[in] pfPageLoad 内容を入れるコールバック函数のアレ @return UINT 作成した頁数 */ UINT DocStringSplitAST( LPTSTR ptStr, INT cchSize, PAGELOAD pfPageLoad ) { LPTSTR ptCaret; // 読込開始・現在位置 LPTSTR ptStart; // セパレータの直前 LPTSTR ptEnd; UINT iNumber; // 通し番号カウント UINT cchItem; BOOLEAN bLast; TCHAR atName[MAX_PATH]; ptCaret = ptStr; // まずは最初から iNumber = 0; // 通し番号0インデックス bLast = FALSE; do // とりあえず一番最初はptCaretは[AA]になってる { ptStart = NextLineW( ptCaret ); // 次の行からが本番 ptCaret += 5; // [AA][ cchItem = ptStart - ptCaret; // 名前部分の文字数 cchItem -= 3; // ]rn ZeroMemory( atName, sizeof(atName) ); // 名前確保 if( 0 < cchItem ) StringCchCopyN( atName, MAX_PATH, ptCaret, cchItem ); ptCaret = ptStart; // 本体部分 ptEnd = StrStr( ptCaret, AST_SEPARATERW ); // セパレータを探す // この時点でptEndは次の[AA]をさしてる・もしくはNULL(最後のコマ) if( !ptEnd ) // 見つからなかったら=これが最後なら=NULL { ptEnd = ptStr + cchSize; // WCHARサイズで計算おk? bLast = TRUE; } cchItem = ptEnd - ptCaret; // WCHAR単位なので計算結果は文字数のようだ if( !(bLast) && 0 < cchItem ) // 最終頁でない場合は末端の改行分引く { cchItem -= CH_CRLF_CCH; ptCaret[cchItem] = 0; } pfPageLoad( atName, ptCaret, cchItem ); iNumber++; ptCaret = ptEnd; }while( *ptCaret ); // データ有る限りループで探す return iNumber; }
size_t SimpleString::count(const SimpleString& substr) const { size_t num = 0; char* str = buffer_; while (*str && (str = StrStr(str, substr.buffer_))) { num++; str++; } return num; }
void CCmd_Password::OnOutputInfo(char level, LPCTSTR data, LPCTSTR msg) { if(StrStr(data, _T("Password updated"))) TheApp()->StatusAdd( msg, SV_COMPLETION ); else { m_ErrorTxt = StrCmp(data, _T("Password not changed.")) ? msg : data; CP4Command::OnOutputInfo(level, data, msg); } }