void SetDefaultValues() /* This uses the defaults from joyd.h */ { config.debug = SHOW_DEBUG; config.syslog = SHOW_SYSLOG; config.std_out = SHOW_STDOUT; config.config_file = AllocString(CONFIG_FILE); config.daemon = DAEMON_MODE; config.shiftkeys=SHIFT_KEYS; config.axes=0; config.buttons=0; config.version=0; config.joy_device=AllocString(JOY_DEVICE); config.joy_name[0]='\0'; config.action_exit=AllocString(ACTION_EXIT); config.action_reread=AllocString(ACTION_REREAD); config.action=NULL; config.action_count=0; config.cal_count=0; config.cal=NULL; config.cal_min_default=CALIBRATION_MIN; config.cal_max_default=CALIBRATION_MAX; }
bool CFileStream::RecursionInsertFile(char* treepath,memory_tree_s* fileTree,memory_tree_s* DirTree) { char TreeRoot[MAX_PATH]; if(treepath[0] == '/') { treepath++; return RecursionInsertFile(treepath,fileTree,&memoryTreeRoot); } if(DirTree) { strcpy(TreeRoot,treepath); char * folderName = GetFolderName(TreeRoot); if(folderName) { int listsize = DirTree->dataList.size(); if(listsize) { DWORD hashvalue = GetHashValue(folderName); for(int i=0;i<listsize;i++) { if(DirTree->dataList[i]->bDirectory && DirTree->dataList[i]->dwHashValue == hashvalue && m_strcmp(DirTree->dataList[i]->nStringIdx,folderName)) { char* nextdir = &treepath[strlen(folderName)+1]; return RecursionInsertFile(nextdir,fileTree,DirTree->dataList[i]); } } memory_tree_s* newdir = new memory_tree_s; newdir->bDirectory = TRUE; newdir->nStringIdx = AllocString(folderName); newdir->dataSize = 0; newdir->dataOffset = 0; newdir->dwHashValue = GetHashValue(folderName); DirTree->dataList.push_back(newdir); char* nextdir = &treepath[strlen(folderName)+1]; return RecursionInsertFile(nextdir,fileTree,newdir); } else { memory_tree_s* newdir = new memory_tree_s; newdir->bDirectory = TRUE; newdir->nStringIdx = AllocString(folderName); newdir->dataSize = 0; newdir->dataOffset = 0; newdir->dwHashValue = GetHashValue(folderName); DirTree->dataList.push_back(newdir); char* nextdir = &treepath[strlen(folderName)+1]; return RecursionInsertFile(nextdir,fileTree,newdir); } } else { DirTree->dataList.push_back(fileTree); return true; } } return false; }
void PSCGIreadvalue(FILE *f, int *count, PSmemobj *aStringObj) /**************************************************/ /* */ /* PSCGIreadvalue */ /* */ /* reads a value (HTTP-format) from a file */ /* and decrements a counter of characters */ /* */ /**************************************************/ { register int j; char c; int wsize; char *value; int EndValue = BOOL_FALSE; InitStringObj(aStringObj); if (( !feof(f) && (*count))) { j=0; wsize = WORDSIZE; value = AllocString(aStringObj, wsize, 1); if (value == NULL) exit(1); do { if ((c = (char) fgetc(f)) == '&') EndValue = BOOL_TRUE; --(*count); if (j==wsize) { wsize *= 2; value = AllocString(aStringObj, wsize, 1); } /* endif */ value[j] = PSCGIChInterpret(f,c,count); j++; } while ((!EndValue) && (!feof(f)) && (*count)); /* enddowhile */ if ( j && (value[j-1] == '&')) value[j-1] = '\0'; else value[j] = '\0'; } else value = NULL; /* endif */ }
CCOMString::CCOMString(LPCTSTR pszString) { m_pszString = NULL; int nLen = _tcslen(pszString); AllocString(nLen); _tcsncpy(m_pszString, pszString, nLen); }
CCOMString::CCOMString(CCOMString& str) { m_pszString = NULL; int nLen = str.GetLength(); AllocString(nLen); _tcsncpy(m_pszString, (LPCTSTR) str, nLen); }
//-------------------------------------------------------------------------------- bool CFileChangeNotificationContextObj::PostChanges() { DWORD nOffset = 0; for(;;) { FILE_NOTIFY_INFORMATION* pOrigInfo = (FILE_NOTIFY_INFORMATION*) (m_pBase + nOffset); CFileChangeNotificationObj* pInfo = new CFileChangeNotificationObj(pOrigInfo, GetPath()); nOffset += pOrigInfo->NextEntryOffset; if(pInfo->m_nAction == FILE_ACTION_RENAMED_OLD_NAME) { delete m_pPrevRenameObj; m_pPrevRenameObj = pInfo; } else { if(pInfo->m_nAction == FILE_ACTION_RENAMED_NEW_NAME) { if(m_pPrevRenameObj == NULL) { delete pInfo; return false; } pInfo->m_pOldFilename = AllocString(m_pPrevRenameObj->m_pFilename); delete m_pPrevRenameObj; m_pPrevRenameObj = NULL; } m_pTarget->PostMessage(GetMessageId(), (WPARAM) pInfo); } if(pOrigInfo->NextEntryOffset == 0) return true; } }
char *MapFile::ReadEncString() { static codecvt_utf8<char16_t> conv; static char16_t ws[0x8000]; static char ns[0x10000]; int32_t len = Read<int8_t>(); if (len == 0) return nullptr; else if (len > 0) { if (len == 127) len = Read<int32_t>(); if (len <= 0) return nullptr; char16_t *ows = reinterpret_cast<char16_t *>(ReadBin(len * 2)); __m128i *m1 = reinterpret_cast<__m128i *>(ws), *m2 = reinterpret_cast<__m128i *>(ows), *m3 = reinterpret_cast<__m128i *>(WZ::WKey); for (int i = 0; i <= len >> 3; ++i) { _mm_store_si128(m1 + i, _mm_xor_si128(_mm_loadu_si128(m2 + i), _mm_load_si128(m3 + i))); } mbstate_t state; const char16_t *fnext; char *tnext; conv.out(state, ws, ws + len, fnext, ns, ns + 0x10000, tnext); char *s = AllocString(tnext - ns + 1); memcpy(s, ns, tnext - ns + 1); s[tnext - ns] = '\0'; return s; } else { if (len == -128)
bool CFileStream::LoadFromStream() { file_header_s* fileHeader = (file_header_s*)memoryData; fileHeader->strData += (DWORD)memoryData; fileHeader->treeData += (DWORD)memoryData; fileHeader->treeList += (DWORD)memoryData; if(strcmp(fileHeader->Sign,SIGN_STRING)==0) { DWORD nCount = 0; DWORD readOffset = 0; for(nCount = 0;nCount < fileHeader->strCount;nCount++) { AllocString((char*)fileHeader->strData + readOffset); readOffset += strlen((char*)fileHeader->strData + readOffset) +1; } DWORD offset=0; if(fileHeader->treeCompSize) { PBYTE pTreeData = new BYTE[fileHeader->treeDataSize]; if(uncompress(pTreeData,&fileHeader->treeDataSize,(PBYTE)fileHeader->treeData,fileHeader->treeCompSize)==Z_OK) { RecursionTreeList((disk_tree_s*)fileHeader->treeList,(void*)pTreeData,&offset); return true; } } else { RecursionTreeList((disk_tree_s*)fileHeader->treeList,(void*)fileHeader->treeData,&offset); return true; } } return false; }
extern "C" __declspec(dllexport) TCHAR * recognizeNumber(INK_DATA_PTR inkData, int baseline, int size) { if (_num_recognizer != NULL) { if (!HWR_RecognizeSymbol(_num_recognizer, inkData, baseline, size)) return NULL; int altCount = HWR_GetResultAlternativeCount(_num_recognizer, 0); if (altCount > 0) { TCHAR * result = new TCHAR[altCount * 2 + 1]; int k = 0; for (int alt = 0; alt < altCount; alt++) { UCHR* number = (UCHR*)HWR_GetResultWord(_num_recognizer, 0, alt); result[k++] = number[0]; result[k++] = ','; } result[k] = 0; TCHAR * ret = AllocString((TCHAR*)result); delete[] result; return ret; } } return NULL; }
bool CFileStream::AddFile(char* pszFilePath,char* treepath) { HANDLE addFileHandle; DWORD fileSize; DWORD readSize; if(FileIsExists(treepath)) return false; addFileHandle = CreateFile(pszFilePath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(addFileHandle != INVALID_HANDLE_VALUE) { memory_tree_s* fileTree = new memory_tree_s; fileSize = GetFileSize(addFileHandle,&fileSize); fileTree->bDirectory = FALSE; fileTree->dataSize = fileSize; fileTree->dataOffset = new BYTE[fileSize]; fileTree->dwHashValue = GetHashValue(GetFileName(treepath)); fileTree->nStringIdx = AllocString(GetFileName(treepath)); ReadFile(addFileHandle,fileTree->dataOffset,fileSize,&readSize,NULL); CloseHandle(addFileHandle); if(RecursionInsertFile(treepath,fileTree)) return true; } return false; }
void RString::SetBuffer(const char *nbuffer) { SafeDealloc(); AllocString(nbuffer); return; }
MissionList::LvlItem *MissionList::AddLvlItem(PdbItem *ppdbi, char *pszLvl) { LvlItem *plvli = new LvlItem; if (plvli == NULL) { return NULL; } plvli->pszFilename = AllocString(pszLvl); if (plvli->pszFilename == NULL) { delete plvli; return NULL; } plvli->mt = GetMissionType(&ppdbi->packid, pszLvl); plvli->plvliNext = NULL; bool fInserted = false; LvlItem **pplvliT = &ppdbi->plvliFirst; while ((*pplvliT) != NULL) { LvlItem *plvliT = *pplvliT; if (strcmp(plvli->pszFilename, plvliT->pszFilename) < 0) { plvli->plvliNext = plvliT; *pplvliT = plvli; fInserted = true; break; } pplvliT = &(*pplvliT)->plvliNext; } if (!fInserted) { *pplvliT = plvli; } ppdbi->clvli++; return plvli; }
void CStringPool :: MakeEmptyString( void ) { // empty string is always should be set at index 0 unsigned short i = AllocString( "" ); if( i != 0 ) ALERT( at_error, "Empty string has bad index %i!\n", i ); }
CCOMStringW::CCOMStringW(CCOMStringW& str) { m_pszString = NULL; int nLen = str.GetLength(); AllocString(nLen); wcsncpy(m_pszString, (const WCHAR* ) str, nLen); }
RString& RString::operator =(const char *str) { SafeDealloc(); if(str != NULL) AllocString(str); return *this; }
CCOMStringW::CCOMStringW(const WCHAR* pszString) { m_pszString = NULL; int nLen = wcslen(pszString); AllocString(nLen); wcsncpy(m_pszString, pszString, nLen); }
ExpressionItem *CopyItem(ExpressionItem *citem, int NeedConst) { if (!citem) return NULL; ExpressionItem *item = NULL; if ((NeedConst) && ((citem->type & ITEMTYPE) != IT_CONST)) { // in case of non constant expression - flat it to const RunTree(citem, item, RTO_NEEDCONST | ITC_INT | ITC_STRING | ITC_FLOAT | ITC_ARRAY); if (item) return item; } item = AllocItem(); item->type = citem->type; if ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_STRING)) { item->param1 = (EIPARAM) AllocString(); lstrcpy((LPSTR) item->param1, (LPSTR) citem->param1); } else if (((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_ARRAY)) || ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_VARIABLE | ITV_ARRITEM))) { item->param1 = citem->param1; ArrayDesc *ad = (ArrayDesc*) item->param1; ad->references++; } else item->param1 = citem->param1; item->param2 = citem->param2; item->next = NULL; return item; }
void RString::CopyFrom(RString &src) { SafeDealloc(); AllocString(src.myString); return; }
char *GetResultStr(SystemProc *proc) { char *buf = AllocString(); if (proc->ProcResult == PR_OK) lstrcpy(buf, "ok"); else if (proc->ProcResult == PR_ERROR) lstrcpy(buf, "error"); else if (proc->ProcResult == PR_CALLBACK) wsprintf(buf, "callback%d", proc->CallbackIndex); return buf; }
CCOMString::CCOMString(BSTR bstrString) { USES_CONVERSION; m_pszString = NULL; int nLen = _tcslen(OLE2T(bstrString)); AllocString(nLen); _tcsncpy(m_pszString, OLE2T(bstrString), nLen); }
MissionList::PdbItem *MissionList::AddPdbItem(const PackId *ppackid) { PdbItem *ppdbi = new PdbItem; if (ppdbi == NULL) { return NULL; } ppdbi->packid = *ppackid; ppdbi->plvliFirst = NULL; ppdbi->ppdbiNext = NULL; ppdbi->clvli = 0; ppdbi->pszTitle = NULL; if (ppackid->id == PACKID_MAIN) { ppdbi->pszTitle = AllocString("Main Game"); } else { const json::JsonMap *map = gppim->GetInfoMap(ppackid); if (map != NULL) { const json::JsonObject *obj = map->GetObject("t"); if (obj != NULL && obj->type() == json::JSONTYPE_STRING) { const json::JsonString *title = (const json::JsonString *)obj; ppdbi->pszTitle = AllocString(title->GetString()); } delete map; } if (ppdbi->pszTitle == NULL) { ppdbi->pszTitle = AllocString(""); } } bool fInserted = false; PdbItem **pppdbiT = &m_ppdbiFirst; while ((*pppdbiT) != NULL) { PdbItem *ppdbiT = *pppdbiT; if (strcmp(ppdbi->pszTitle, ppdbiT->pszTitle) < 0) { ppdbi->ppdbiNext = ppdbiT; *pppdbiT = ppdbi; fInserted = true; break; } pppdbiT = &(*pppdbiT)->ppdbiNext; } if (!fInserted) { *pppdbiT = ppdbi; } return ppdbi; }
char * GetPassword(char *prompt) { int fd; int nc; char buf[BUFSIZ]; int done = 0; if (prompt == (char *)0) prompt = ""; if ((pass = AllocString()) == (STRING *)0) OutOfMem(); BuildString((char *)0, pass); if ((fd = open("/dev/tty", O_RDWR)) == -1) { Error("could not open `/dev/tty': %s", strerror(errno)); return (char *)0; } C2Raw(fd); write(fd, prompt, strlen(prompt)); while (!done) { int i; if ((nc = read(0, buf, sizeof(buf))) == 0) break; for (i = 0; i < nc; ++i) { if (buf[i] == 0x0d || buf[i] == 0x0a) { /* CR, NL */ done = 1; break; } else BuildStringChar(buf[i], pass); } } C2Normal(fd); /* { static STRING *c = (STRING *) 0; if ((c = AllocString()) == (STRING *) 0) OutOfMem(); write(fd, "\n'", 2); if (pass->used) { FmtCtlStr(pass->string, pass->used - 1, c); write(fd, c->string, c->used - 1); } write(fd, "'\n", 2); } */ write(fd, "\n", 1); close(fd); /* this way a (char*)0 is only returned on error */ if (pass->string == (char *)0) return ""; else return pass->string; }
CCOMStringW::CCOMStringW(WCHAR ch, int nRepeat) { m_pszString = NULL; if (nRepeat > 0) { AllocString(nRepeat); for (int i=0; i < nRepeat; i++) m_pszString[i] = ch; } }
char *PSCGIreadname(FILE *f, int *count, PSmemobj *aStringObj) /**************************************************/ /* */ /* PSCGIreadname */ /* */ /* reads a name (HTTP-format) from a file */ /* and decrements a counter of characters */ /* */ /**************************************************/ { register int j; char c; int wsize; char *name; int EndName = BOOL_FALSE; InitStringObj(aStringObj); j = 0; wsize = WORDSIZE; name = AllocString(aStringObj, wsize, 1); if (name == NULL) exit(1); do { if ((c = (char) fgetc(f)) == '=') EndName = BOOL_TRUE; --(*count); if (j==wsize) { wsize *= 2; name = AllocString(aStringObj, wsize, 1); } /* endif */ name[j] = PSCGIChInterpret(f,c,count); j++; } while (!EndName); /* enddowhile */ if (j) name[j-1] = '\0'; }
//-------------------------------------------------------------------------------- void CCertificateMaster::SetIP(LPCTSTR pIP) { CWriteLock lock(this, false); if(! lock.Lock(30000)) return; delete[] m_pIP; m_pIP = NULL; AllocString(m_pIP, pIP); }
void CCOMString::ConcatCopy(LPCTSTR lpszData1, LPCTSTR lpszData2) { ATLASSERT(lpszData1 != NULL); ATLASSERT(lpszData2 != NULL); int nLen1 = _tcslen(lpszData1); int nLen2 = _tcslen(lpszData2); int nLen = nLen1 + nLen2; AllocString(nLen); memcpy(m_pszString, lpszData1, nLen1 * sizeof(TCHAR)); memcpy(m_pszString+nLen1, lpszData2, nLen2 * sizeof(TCHAR)); }
char* DslFile::AllocString(const char* src) { if (0 == src) return 0; int len = (int)strlen(src); char* p = AllocString(len); if (0 != p) { strcpy(p, src); } return p; }
CCOMString::CCOMString(TCHAR ch) { int nRepeat=1; m_pszString = NULL; AllocString(nRepeat); #ifdef _UNICODE for (int i=0; i < nRepeat; i++) m_pszString[i] = ch; #else memset(m_pszString, ch, nRepeat); #endif }
RString& RString::Format(va_list arglist, const char *msg, ...) { if(msg == NULL) return *this; char buf[MAX_FORMATTED_SIZE]; //format can be used to stack overflow if you're a dumbass. so don't be one. SafeDealloc(); vsnprintf(&buf[0], MAX_FORMATTED_SIZE, msg, arglist); AllocString(&buf[0]); //fprintf(stderr,"Formatting RString"); return *this; }
void V_SplitString2( const char *pString, const char **pSeparators, int nSeparators, CUtlVector<char*> &outStrings ) { outStrings.Purge(); const char *pCurPos = pString; while ( 1 ) { int iFirstSeparator = -1; const char *pFirstSeparator = 0; for ( int i=0; i < nSeparators; i++ ) { const char *pTest = V_stristr( pCurPos, pSeparators[i] ); if ( pTest && (!pFirstSeparator || pTest < pFirstSeparator) ) { iFirstSeparator = i; pFirstSeparator = pTest; } } if ( pFirstSeparator ) { // Split on this separator and continue on. int separatorLen = strlen( pSeparators[iFirstSeparator] ); if ( pFirstSeparator > pCurPos ) { outStrings.AddToTail( AllocString( pCurPos, pFirstSeparator-pCurPos ) ); } pCurPos = pFirstSeparator + separatorLen; } else { // Copy the rest of the string if ( strlen( pCurPos ) ) { outStrings.AddToTail( AllocString( pCurPos, -1 ) ); } return; } } }