HRESULT CComModule::RegisterTypeLib() { USES_CONVERSION; _ASSERTE(m_hInst != NULL); TCHAR szModule[_MAX_PATH+4]; TCHAR szDir[_MAX_PATH]; GetModuleFileName(GetTypeLibInstance(), szModule, _MAX_PATH); CComPtr<ITypeLib> pTypeLib; HRESULT hr = LoadTypeLib(T2OLE(szModule), &pTypeLib); if (!SUCCEEDED(hr)) { // typelib not in module, try <module>.tlb instead LPTSTR lpszExt = szModule + lstrlen(szModule); for (LPTSTR lpsz = szModule; *lpsz != '\0'; lpsz = CharNext(lpsz)) { if (*lpsz == '.') lpszExt = lpsz; } _ASSERTE(lpszExt != NULL); lstrcpy(lpszExt, _T(".tlb")); hr = LoadTypeLib(T2OLE(szModule), &pTypeLib); } if (SUCCEEDED(hr)) { int nLen = lstrlen(szModule) - AtlGetFileName(szModule, NULL, 0); lstrcpy(szDir, szModule); szDir[nLen] = 0; return ::RegisterTypeLib(pTypeLib, T2OLE(szModule), T2OLE(szDir)); } return S_FALSE; }
CString NameFromVKey(UINT nVK) { CString str; if (0x00 == nVK) { str = _T("None"); } else if (VK_SNAPSHOT == nVK) { str = _T("Prt Scr"); } else { UINT nScanCode = MapVirtualKeyEx(nVK, 0, GetKeyboardLayout(0)); switch(nVK) { // Keys which are "extended" (except for Return which is Numeric Enter as extended) case VK_INSERT: case VK_DELETE: case VK_HOME: case VK_END: case VK_NEXT: // Page down case VK_PRIOR: // Page up case VK_LEFT: case VK_RIGHT: case VK_UP: case VK_DOWN: nScanCode |= 0x100; // Add extended bit } // GetKeyNameText() expects the scan code to be on the same format as WM_KEYDOWN // Hence the left shift LPTSTR prb = str.GetBuffer(80); BOOL bResult = GetKeyNameText(nScanCode << 16, prb, 79); // these key names are capitalized and look a bit daft int len = lstrlen(prb); if(len > 1) { LPTSTR p2 = CharNext(prb); CharLowerBuff(p2, len - (p2 - prb) ); } str.ReleaseBuffer(); ATLASSERT(str.GetLength()); } return str; // internationalization ready, sweet! }
LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2) { while (p1 != NULL && *p1 != NULL) { LPCTSTR p = p2; while (p != NULL && *p != NULL) { if (*p1 == *p) return CharNext(p1); p = CharNext(p); } p1 = CharNext(p1); } return NULL; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DWORD Ret; STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0}; char command_line[1024]; char seekchar=' '; char *cmdline; si.cb = sizeof(si); // Make child process use this app's standard files. Not needed because the handles // we created when executing this process were inheritable. //si.dwFlags = STARTF_USESTDHANDLES; //si.hStdInput = GetStdHandle (STD_INPUT_HANDLE); //si.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); //si.hStdError = GetStdHandle (STD_ERROR_HANDLE); lstrcpyn(command_line, GetCommandLine(), 1024); cmdline = command_line; if (*cmdline == '\"') seekchar = *cmdline++; while (*cmdline && *cmdline != seekchar) cmdline=CharNext(cmdline); cmdline=CharNext(cmdline); // skip any spaces before the arguments while (*cmdline && *cmdline == ' ') cmdline++; Ret = CreateProcess (NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi ); if (Ret) { WaitForSingleObject(pi.hProcess, INFINITE); GetExitCodeProcess(pi.hProcess, &Ret); CloseHandle (pi.hProcess); CloseHandle (pi.hThread); ExitProcess(Ret); } else { ExitProcess(STATUS_ILLEGAL_INSTRUCTION); } return 0; // dummy }
static void push_include_cygwin(const char *path, VALUE (*filter)(VALUE)) { const char *p, *s; char rubylib[FILENAME_MAX]; VALUE buf = 0; p = path; while (*p) { unsigned int len; while (*p == ';') p++; if (!*p) break; for (s = p; *s && *s != ';'; s = CharNext(s)); len = s - p; if (*s) { if (!buf) { buf = rb_str_new(p, len); p = RSTRING_PTR(buf); } else { rb_str_resize(buf, len); p = strncpy(RSTRING_PTR(buf), p, len); } } if (cygwin_conv_to_posix_path(p, rubylib) == 0) p = rubylib; push_include(p, filter); if (!*s) break; p = s + 1; } }
VOID ACLStr::RTrim(VOID) { LPTSTR string = CharFirst(); LPTSTR lastWhiteSpace = NULL; // Loop over the string looking // for white spaces. We start at the // front since we want to be DBCS compatible. // At least that's the HOPE! :-) while(*string != '\0') { if (*string == CH_SPACE) { if (lastWhiteSpace == NULL) { lastWhiteSpace = string; } } else lastWhiteSpace = NULL; // Bump our current pointer to the next // character in the stream. // string = CharNext(); } // while. // Move the NULL terminator to the // new location. if (lastWhiteSpace != NULL) { *lastWhiteSpace = '\0'; _length = (lastWhiteSpace - _string); } } // RTrim
/*-------------------------------------------------- --------------------------------------- Check Format --------------------------------------------------*/ DWORD FindFormat(const char* fmt) { DWORD ret = 0; while(*fmt) { if(*fmt == '"') { do{ for(++fmt; *fmt&&*fmt++!='"'; ); }while(*fmt == '"'); if(!*fmt) break; } else if(*fmt == 's') { fmt++; ret |= FORMAT_SECOND; } else if(*fmt == 'T' && strncmp(fmt, "TIME", 4) == 0) { fmt += 4; ret |= FORMAT_SECOND; } else if(*fmt == '@' && fmt[1] == '@' && fmt[2] == '@') { fmt += 3; if(*fmt == '.' && fmt[1] == '@') { ret |= FORMAT_BEAT2; fmt += 2; } else ret |= FORMAT_BEAT1; } else fmt = CharNext(fmt); } return ret; }
/*------------------------------------------- パス名にファイル名をつける ---------------------------------------------*/ void add_title(char *path, char *title) { char *p; p = path; if(*title && *(title + 1) == ':') ; else if(*title == '\\') { if(*p && *(p + 1) == ':') p += 2; } else { while(*p) { if((*p == '\\' || *p == '/') && *(p + 1) == 0) { break; } p = (char *)CharNext(p); } *p++ = '\\'; } while(*title) *p++ = *title++; *p = 0; }
ACLStr ACLStr::Replace ( IN const TCHAR replace, IN const TCHAR replaceWith ) { ACLStr replaceStr; LPTSTR thisString = CharFirst(); // While we have something to work with // continue. while (thisString != NULL) { if (*thisString != replace) { replaceStr.Append(*thisString); } else { replaceStr.Append(replaceWith); } // Grab the next character in the string. // use CharNext so we'll be wide string // aware thisString = CharNext(); } return replaceStr; } // Replace
static int WordCmpI(LPCTSTR psz1, LPCTSTR psz2) throw() { TCHAR c1 = (TCHAR)CharUpper((LPTSTR)*psz1); TCHAR c2 = (TCHAR)CharUpper((LPTSTR)*psz2); while (c1 != NULL && c1 == c2 && c1 != ' ' && c1 != '\t') { psz1 = CharNext(psz1); psz2 = CharNext(psz2); c1 = (TCHAR)CharUpper((LPTSTR)*psz1); c2 = (TCHAR)CharUpper((LPTSTR)*psz2); } if ((c1 == NULL || c1 == ' ' || c1 == '\t') && (c2 == NULL || c2 == ' ' || c2 == '\t')) return 0; return (c1 < c2) ? -1 : 1; }
static inline void translate_char(char *p, int from, int to) { while (*p) { if ((unsigned char)*p == from) *p = to; p = CharNext(p); } }
TCHAR * _get_cmd_arg(TCHAR *pCmdLine) { static TCHAR *pArgs = NULL; TCHAR *pRetArg; BOOL bQuoted; if (!pCmdLine && !pArgs) return NULL; if (!pArgs) pArgs = pCmdLine; /* skip whitespace */ for (pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); pRetArg = CharNext(pRetArg)) ; if (!*pRetArg) { pArgs = NULL; return NULL; } /* check for quote */ if (*pRetArg == TEXT('"')) { bQuoted = TRUE; pRetArg = CharNext(pRetArg); pArgs = _tcschr(pRetArg, TEXT('"')); } else { /* skip to whitespace */ for (pArgs = pRetArg; *pArgs && !_istspace(*pArgs); pArgs = CharNext(pArgs)) ; } if (pArgs && *pArgs) { TCHAR *p; p = pArgs; pArgs = CharNext(pArgs); *p = (TCHAR) 0; } else { pArgs = NULL; } return pRetArg; }
LPTSTR FindChar(LPTSTR lpsz, TCHAR ch) { while (*lpsz != 0) { if (*lpsz == ch) return lpsz; lpsz = CharNext(lpsz); } return NULL; }
LPTSTR FindReverseChar(LPTSTR lpsz, TCHAR ch) { LPTSTR lpszLast = NULL; while (*lpsz != 0) { if (*lpsz == ch) lpszLast = lpsz; lpsz = CharNext(lpsz); } return lpszLast; }
LPTSTR PathFindFileName(LPCTSTR pPath) { LPCTSTR pT; for (pT = pPath; *pPath; pPath = CharNext(pPath)) { if ((pPath[0] == TEXT('\\') || pPath[0] == TEXT(':')) && pPath[1] && (pPath[1] != TEXT('\\'))) pT = pPath + 1; } return (LPTSTR)pT; // const -> non const }
static UINT PASCAL AtlGetFileName(LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax) { _ASSERTE(lpszPathName != NULL); // always capture the complete file name including extension (if present) LPTSTR lpszTemp = (LPTSTR)lpszPathName; for (LPCTSTR lpsz = lpszPathName; *lpsz != '\0'; lpsz = CharNext(lpsz)) { // remember last directory/drive separator if (*lpsz == '\\' || *lpsz == '/' || *lpsz == ':') lpszTemp = (LPTSTR)CharNext(lpsz); } // lpszTitle can be NULL which just returns the number of bytes if (lpszTitle == NULL) return lstrlen(lpszTemp)+1; // otherwise copy it into the buffer provided lstrcpyn(lpszTitle, lpszTemp, nMax); return 0; }
BOOL HasBlanks( LPTSTR psz) { while (*psz) { if (*psz == CHAR_SPACE) return TRUE; else psz = CharNext(psz); } return FALSE; }
static int lstrncmpi (LPCTSTR pszA, LPCTSTR pszB, size_t cch) { if (!pszA || !pszB) { return (!pszB) - (!pszA); // A,!B:1, !A,B:-1, !A,!B:0 } for ( ; cch > 0; cch--, pszA = CharNext(pszA), pszB = CharNext(pszB)) { TCHAR chA = toupper( *pszA ); TCHAR chB = toupper( *pszB ); if (!chA || !chB) return (!chB) - (!chA); // A,!B:1, !A,B:-1, !A,!B:0 if (chA != chB) return (int)(chA) - (int)(chB); // -1:A<B, 0:A==B, 1:A>B } return 0; // no differences before told to stop comparing, so A==B }
static VALUE rubylib_mangled_path(const char *s, unsigned int l) { static char *newp, *oldp; static int newl, oldl, notfound; char *ptr; VALUE ret; if (!newp && !notfound) { newp = getenv("RUBYLIB_PREFIX"); if (newp) { oldp = newp = strdup(newp); while (*newp && !ISSPACE(*newp) && *newp != ';') { newp = CharNext(newp); /* Skip digits. */ } oldl = newp - oldp; while (*newp && (ISSPACE(*newp) || *newp == ';')) { newp = CharNext(newp); /* Skip whitespace. */ } newl = strlen(newp); if (newl == 0 || oldl == 0) { rb_fatal("malformed RUBYLIB_PREFIX"); } translate_char(newp, '\\', '/'); } else { notfound = 1; } } if (!newp || l < oldl || STRNCASECMP(oldp, s, oldl) != 0) { return rb_str_new(s, l); } ret = rb_str_new(0, l + newl - oldl); ptr = RSTRING_PTR(ret); memcpy(ptr, newp, newl); memcpy(ptr + newl, s + oldl, l - oldl); ptr[l + newl - oldl] = 0; return ret; }
MODULEVERSION& ModuleVersion(HINSTANCE instance/* = 0*/) { static bool Initialized = false; static MODULEVERSION g_ModuleVersion = { 0 }; if (!Initialized) { // Initialize Module version information TCHAR szFileName[MAX_PATH]; DWORD dwLen; BOOL bGotModuleVersion = FALSE; if ((dwLen = GetModuleFileName(static_cast<HMODULE>(instance), szFileName, sizeof(szFileName)))) { szFileName[dwLen] = '\0'; DWORD dwHandle, dwInfoLen; if ((dwInfoLen = GetFileVersionInfoSize(szFileName, &dwHandle))) { char *szVersionBuffer = (char *)malloc(dwInfoLen); if (GetFileVersionInfo(szFileName, dwHandle, dwInfoLen, szVersionBuffer)) { VS_FIXEDFILEINFO *fi; UINT uBlockLen; if (VerQueryValue(szVersionBuffer, _T("\\"), reinterpret_cast<LPVOID*>(&fi), &uBlockLen)) { Initialized = true; g_ModuleVersion.Major = fi->dwProductVersionMS >> 16; g_ModuleVersion.Minor = fi->dwProductVersionMS & 0xff; g_ModuleVersion.Release = fi->dwProductVersionLS >> 16; g_ModuleVersion.Build = fi->dwProductVersionLS & 0xff; // Get module path g_ModuleVersion.ModuleFullPath = szFileName; TCHAR *eop = _tcsrchr(szFileName, _T('\\')); // end of path g_ModuleVersion.ModuleFileName = CharNext(eop); // beginning of the file name *CharNext(eop) = _T('\0'); g_ModuleVersion.ModulePath = szFileName; } }
PCTSTR WINAPI pGetFilePart( IN PCTSTR FilePath) { PCTSTR LastComponent = FilePath; TCHAR CurChar; while(CurChar = *FilePath) { FilePath = CharNext(FilePath); if((CurChar == TEXT('\\')) || (CurChar == TEXT('/')) || (CurChar == TEXT(':'))) { LastComponent = FilePath; } } return LastComponent; }
void TrimString(TCHAR *pszStr) { int i; TCHAR *psz,szChars[]=_T(" \r\n\t"); for(i=0;i<SIZEOF(szChars);++i) { /* trim end */ psz=&pszStr[lstrlen(pszStr)-1]; while(pszStr[0] && *psz==szChars[i]) { *psz=0; psz=CharPrev(pszStr,psz); } /* trim beginning */ for(psz=pszStr;(*psz && *psz==szChars[i]);psz=CharNext(psz)); MoveMemory(pszStr,psz,(lstrlen(psz)+1)*sizeof(TCHAR)); } }
/*------------------------------------------- パス名からファイル名をとりのぞく ---------------------------------------------*/ void del_title(char *path) { char *p, *ep; p = ep = path; while(*p) { if(*p == '\\' || *p == '/') { if(p > path && *(p - 1) == ':') ep = p + 1; else ep = p; } p = (char *)CharNext(p); } *ep = 0; }
int WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR cmdLine, int nShow) { char buf[30]; if (!cmdLine || !cmdLine[0]) return 0; LPSTR next = CharNext(cmdLine); if (*next != 0) { OutputDebugString("Yes"); } else { OutputDebugString("No"); } return 0; }
static void push_include(const char *path, VALUE (*filter)(VALUE)) { const char sep = PATH_SEP_CHAR; const char *p, *s; VALUE load_path = GET_VM()->load_path; p = path; while (*p) { while (*p == sep) p++; if (!*p) break; for (s = p; *s && *s != sep; s = CharNext(s)); rb_ary_push(load_path, (*filter)(rubylib_mangled_path(p, s - p))); p = s; } }
char *my_strstr(char *a, char *b) { int l = lstrlen(b); while (lstrlen(a) >= l) { char c = a[l]; a[l] = 0; if (!lstrcmpi(a, b)) { a[l] = c; return a; } a[l] = c; a = CharNext(a); } return NULL; }
static char * strrdirsep(const char *path) { char *last = NULL; while (*path) { if (isdirsep(*path)) { const char *tmp = path++; while (isdirsep(*path)) path++; if (!*path) break; last = (char *)tmp; } else { path = CharNext(path); } } return last; }
TCHAR *my_strstr(TCHAR *a, TCHAR *b) { int l = lstrlen(b); while (lstrlen(a) >= l) { TCHAR c = a[l]; a[l] = 0; if (!lstrcmpi(a, b)) { a[l] = c; return a; } a[l] = c; a = CharNext(a); } return NULL; }
ACLStr ACLStr::Strip(IN const TCHAR chToStrip) { ACLStr tmpStr; LPTSTR thisString = CharFirst(); // While we have something to work with // continue. while (thisString != NULL) { if (*thisString != chToStrip) { tmpStr.Append(*thisString); } thisString = CharNext(); } return tmpStr; } // Strip
int WINAPI ReplaceCharWithNull(LPTSTR psz, int ch) { int cChanged = 0; if (psz == NULL) return -1; while ('\0' != *psz) { if (ch == *psz) { *psz++ = '\0'; cChanged++; continue; } psz = CharNext(psz); } return cChanged; }