bool KeyboardLayout::_GetPair(const parse_state& state, const char*& data, BString& name, BString& value) { // Get name name = ""; while (data[0] != '\0' && data[0] != '=') { name += data[0]; data++; } if (data[0] != '=') { _Error(state, "no valid pair"); return false; } // Skip sign data++; // Get value value = ""; while (data[0] != '\0' && data[0] != '\n') { value += data[0]; data++; } _Trim(name, false); _Trim(value, true); return true; }
void SFStatement::TrimParameter() { for (SQLUSMALLINT i = 0; i < m_usBindParam; i++) { if (m_arrayParamType[i] == SQL_C_CHAR && m_arrayParamInd[i] != SQL_NULL_DATA) { _Trim((LPTSTR)m_arrayParamData[i]); } if (m_arrayParamType[i] == SQL_C_TCHAR && m_arrayParamInd[i] != SQL_NULL_DATA) { _Trim((LPTSTR)m_arrayParamData[i]); } } }
void ESceneLightTools::AppendLightControl(LPCSTR nm, u32* idx) { AnsiString name = nm; _Trim(name); if (name.IsEmpty()) return; if (FindLightControl(name.c_str())) return; lcontrols.push_back (xr_rtoken(name.c_str(),idx?*idx:lcontrol_last_idx++)); }
LPSTR _GetItem(LPCSTR src, int index, LPSTR dst, u32 const dst_size, char separator, LPCSTR def, bool trim) { LPCSTR ptr; ptr = _SetPos(src, index, separator); if (ptr) _CopyVal(ptr, dst, separator); else xr_strcpy(dst, dst_size, def); if (trim) _Trim(dst); return dst; }
LPCSTR _GetItem(LPCSTR src, int index, xr_string& dst, char separator, LPCSTR def, bool trim) { LPCSTR ptr; ptr = _SetPos(src, index, separator); if (ptr) _CopyVal(ptr, dst, separator); else dst = def; if (trim) _Trim(dst); return dst.c_str(); }
void SFStatement::TrimColumn() { for (SQLUSMALLINT i = 0; i < m_usBindCol; i++) { if (m_arrayColType[i] == SQL_C_CHAR && m_arrayColInd[i] != SQL_NULL_DATA) { _Trim((LPTSTR)m_arrayColData[i]); } } }
void _SequenceToList(LPSTRVec& lst, LPCSTR in, char separator) { int t_cnt=_GetItemCount(in,separator); string1024 T; for (int i=0; i<t_cnt; i++){ _GetItem(in,i,T,separator,0); _Trim(T); if (xr_strlen(T)) lst.push_back(xr_strdup(T)); } }
void _SequenceToList(SStringVec& lst, LPCSTR in, char separator) { lst.clear (); int t_cnt = _GetItemCount(in,separator); xr_string T; for (int i=0; i<t_cnt; i++){ _GetItem(in,i,T,separator,0); _Trim (T); if (T.size()) lst.push_back(T.c_str()); } }
void _SequenceToList(AStringVec& lst, LPCSTR in, char separator) { lst.clear(); int t_cnt=_GetItemCount(in,separator); AnsiString T; for (int i=0; i<t_cnt; i++){ _GetItem(in,i,T,separator,0); _Trim(T); if (!T.IsEmpty()) lst.push_back(T); } }
void CEditableObject::VerifyMeshNames() { int idx=0; string1024 nm,pref; for(EditMeshIt m_def=m_Meshes.begin();m_def!=m_Meshes.end();m_def++){ strcpy (pref,(*m_def)->m_Name.size()?(*m_def)->m_Name.c_str():"mesh"); _Trim (pref); strcpy (nm,pref); while (FindMeshByName(nm,*m_def)) sprintf(nm,"%s%2d",pref,idx++); (*m_def)->SetName(nm); } }
bool LexicsCutter::_ProcessLine(char* szLine, std::string& line) const { // Check for UTF8 prefix and comments if (strlen(szLine) >= 3) if (szLine[0] == '\xEF' && szLine[1] == '\xBB' && szLine[2] == '\xBF') strncpy(&szLine[0], &szLine[3], strlen(szLine) - 3); if (strlen(szLine) >= 2) if (szLine[0] == '/' && szLine[1] == '/') return false; // Check for empty string line = szLine; _Trim(line, "\x0A\x0D\x20"); if (line.empty()) return false; // Process line without CR/LF line = szLine; _Trim(line, "\x0A\x0D"); return true; }
bool KeyboardLayout::_GetTerm(const char*& data, const char* delimiter, BString& term, bool closingBracketAllowed) { // Get term term = ""; while (data[0] != '\0' && strchr(delimiter, data[0]) == NULL && data[0] != '\n' && data[0] != '#' && (!closingBracketAllowed || data[0] != ']')) { term += data[0]; data++; } if (data[0] == '\0' && delimiter[0]) return false; _Trim(term, true); return true; }
void CInifile::Load(IReader* F, LPCSTR path) { R_ASSERT(F); Sect *Current = 0; string4096 str; string4096 str2; BOOL bInsideSTR = FALSE; while (!F->eof()) { F->r_string (str,sizeof(str)); _Trim (str); LPSTR comm = strchr(str,';'); LPSTR comm_1 = strchr(str,'/'); if(comm_1 && (*(comm_1+1)=='/') && ((!comm) || (comm && (comm_1<comm) )) ) { comm = comm_1; } #ifdef DEBUG LPSTR comment = 0; #endif if (comm) { //."bla-bla-bla;nah-nah-nah" char quot = '"'; bool in_quot = false; LPCSTR q1 = strchr(str,quot); if(q1 && q1<comm) { LPCSTR q2 = strchr(++q1,quot); if(q2 && q2>comm) in_quot = true; } if(!in_quot) { *comm = 0; #ifdef DEBUG comment = comm+1; #endif } } if (str[0] && (str[0]=='#') && strstr(str,"#include")) //handle includes { string_path inc_name; R_ASSERT (path&&path[0]); if (_GetItem (str,1,inc_name,'"')) { string_path fn,inc_path,folder; strconcat (sizeof(fn),fn,path,inc_name); _splitpath (fn,inc_path,folder, 0, 0 ); strcat (inc_path,folder); IReader* I = FS.r_open(fn); R_ASSERT3(I,"Can't find include file:", inc_name); Load (I,inc_path); FS.r_close (I); } } else if (str[0] && (str[0]=='[')) //new section ? { // insert previous filled section if (Current) { //store previous section RootIt I = std::lower_bound(DATA.begin(),DATA.end(),*Current->Name,sect_pred); if ((I!=DATA.end())&&((*I)->Name==Current->Name)) xrDebug::Fatal(DEBUG_INFO, "Duplicate section '%s' found.", *Current->Name); DATA.insert (I,Current); } Current = new Sect(); Current->Name = 0; // start new section R_ASSERT3(strchr(str,']'),"Bad ini section found: ",str); LPCSTR inherited_names = strstr(str,"]:"); if (0!=inherited_names) { VERIFY2 (m_flags.test(eReadOnly),"Allow for readonly mode only."); inherited_names += 2; int cnt = _GetItemCount(inherited_names); for (int k=0; k<cnt; ++k) { xr_string tmp; _GetItem (inherited_names,k,tmp); Sect& inherited_section = r_section(tmp.c_str()); for (SectIt_ it =inherited_section.Data.begin(); it!=inherited_section.Data.end(); it++) insert_item (Current,*it); } } *strchr(str,']') = 0; Current->Name = strlwr(str+1); } else // name = value { if (Current) { string4096 value_raw; char* name = str; char* t = strchr(name,'='); if (t) { *t = 0; _Trim (name); ++t; strcpy_s (value_raw, sizeof(value_raw), t); bInsideSTR = _parse(str2, value_raw); if(bInsideSTR)//multiline str value { while(bInsideSTR) { strcat_s (value_raw, sizeof(value_raw),"\r\n"); string4096 str_add_raw; F->r_string (str_add_raw, sizeof(str_add_raw)); R_ASSERT2 ( xr_strlen(value_raw) + xr_strlen(str_add_raw) < sizeof(value_raw), make_string( "Incorrect inifile format: section[%s], variable[%s]. Odd number of quotes (\") found, but should be even.", Current->Name.c_str(), name ) ); strcat_s (value_raw, sizeof(value_raw),str_add_raw); bInsideSTR = _parse(str2, value_raw); if(bInsideSTR) { if( is_empty_line_now(F) ) strcat_s (value_raw, sizeof(value_raw),"\r\n"); } } } } else { _Trim (name); str2[0] = 0; } Item I; I.first = (name[0]?name:NULL); I.second = (str2[0]?str2:NULL); #ifdef DEBUG I.comment = m_flags.test(eReadOnly)?0:comment; #endif if (m_flags.test(eReadOnly)) { if (*I.first) insert_item (Current,I); } else { if ( *I.first || *I.second #ifdef DEBUG || *I.comment #endif ) insert_item (Current,I); } } } } if (Current) { RootIt I = std::lower_bound(DATA.begin(),DATA.end(),*Current->Name,sect_pred); if ((I!=DATA.end())&&((*I)->Name==Current->Name)) xrDebug::Fatal(DEBUG_INFO, "Duplicate section '%s' found.", *Current->Name); DATA.insert (I,Current); } }
void ProcessLTX(LPCSTR tgt_name, LPCSTR params, BOOL bFast) { xr_string ltx_name; LPCSTR ltx_nm = strstr(params,".ltx"); VERIFY(ltx_nm!=0); string_path ltx_fn; string_path tmp; strncpy (tmp,params,ltx_nm-params); tmp[ltx_nm-params]=0; _Trim (tmp); strcat (tmp,".ltx"); strcpy (ltx_fn,tmp); // append ltx path (if exist) string_path fn,dr,di; _splitpath (ltx_fn,dr,di,0,0); strconcat (sizeof(fn),fn,dr,di); if (0!=fn[0]) FS.append_path ("ltx_path",fn,0,false); if (!FS.exist(ltx_fn)&&!FS.exist(ltx_fn,"$app_root$",tmp)) Debug.fatal (DEBUG_INFO,"ERROR: Can't find ltx file: '%s'",ltx_fn); CInifile ltx (ltx_fn); printf ("Processing LTX...\n"); BOOL make_pack = ltx.line_exist("options","make_pack") ? ltx.r_bool("options","make_pack") : true; LPCSTR copy_path= ltx.line_exist("options","copy_path") ? ltx.r_string("options","copy_path") : 0; if (ltx.line_exist("options","exclude_exts")) _SequenceToList(exclude_exts,ltx.r_string("options","exclude_exts")); xr_vector<char*> list; xr_vector<char*> fl_list; if(ltx.section_exist("include_folders")) { CInifile::Sect& if_sect = ltx.r_section("include_folders"); for (CInifile::SectCIt if_it=if_sect.Data.begin(); if_it!=if_sect.Data.end(); if_it++) { BOOL ifRecurse = CInifile::IsBOOL(if_it->second.c_str()); u32 folder_mask = FS_ListFolders | (ifRecurse?0:FS_RootOnly); string_path path; LPCSTR _path = 0==xr_strcmp(if_it->first.c_str(),".\\")?"":if_it->first.c_str(); strcpy (path,_path); u32 path_len = xr_strlen(path); if ((0!=path_len)&&(path[path_len-1]!='\\')) strcat(path,"\\"); Log (""); OUT_LOG ("Processing folder: '%s'",path); BOOL efRecurse; BOOL val = IsFolderAccepted(ltx,path,efRecurse); if (val || (!val&&!efRecurse)) { if (val) ProcessFolder (list,path); xr_vector<char*>* i_fl_list = FS.file_list_open ("$target_folder$",path,folder_mask); if (!i_fl_list) { Log ("ERROR: Unable to open folder list:", path); continue; } xr_vector<char*>::iterator it = i_fl_list->begin(); xr_vector<char*>::iterator itE = i_fl_list->end(); for (;it!=itE;++it){ xr_string tmp_path = xr_string(path)+xr_string(*it); bool val = IsFolderAccepted(ltx,tmp_path.c_str(),efRecurse); if (val) { fl_list.push_back(xr_strdup(tmp_path.c_str())); Msg ("+F: %s",tmp_path.c_str()); // collect files if (ifRecurse) ProcessFolder (list,tmp_path.c_str()); }else { Msg ("-F: %s",tmp_path.c_str()); } } FS.file_list_close (i_fl_list); }else { Msg ("-F: %s",path); } } }//if(ltx.section_exist("include_folders")) // compress { if(ltx.section_exist("include_files")) { CInifile::Sect& if_sect = ltx.r_section("include_files"); for (CInifile::SectCIt if_it=if_sect.Data.begin(); if_it!=if_sect.Data.end(); if_it++) { list.push_back (xr_strdup(if_it->first.c_str())); } } } CompressList (tgt_name,&list,&fl_list,bFast,make_pack,copy_path); // free xr_vector<char*>::iterator it = list.begin(); xr_vector<char*>::iterator itE = list.end(); for (;it!=itE;++it) xr_free(*it); it = fl_list.begin(); itE = fl_list.end(); for (;it!=itE;++it) xr_free(*it); exclude_exts.clear_and_free(); }
void CInifile::Load(IReader* F, LPCSTR path) { R_ASSERT(F); Sect *Current = 0; string4096 str; string4096 str2; while (!F->eof()) { F->r_string (str,sizeof(str)); _Trim (str); LPSTR semi = strchr(str,';'); LPSTR semi_1 = strchr(str,'/'); if(semi_1 && (*(semi_1+1)=='/') && ((!semi) || (semi && (semi_1<semi) )) ){ semi = semi_1; } #ifdef DEBUG LPSTR comment = 0; #endif if (semi) { *semi = 0; #ifdef DEBUG comment = semi+1; #endif } if (str[0] && (str[0]=='#') && strstr(str,"#include")){ string64 inc_name; R_ASSERT (path&&path[0]); if (_GetItem (str,1,inc_name,'"')){ string_path fn,inc_path,folder; strconcat (sizeof(fn),fn,path,inc_name); _splitpath (fn,inc_path,folder, 0, 0 ); strcat (inc_path,folder); IReader* I = FS.r_open(fn); R_ASSERT3(I,"Can't find include file:", inc_name); Load (I,inc_path); FS.r_close (I); } }else if (str[0] && (str[0]=='[')){ // insert previous filled section if (Current){ RootIt I = std::lower_bound(DATA.begin(),DATA.end(),*Current->Name,sect_pred); if ((I!=DATA.end())&&((*I)->Name==Current->Name)) Debug.fatal(DEBUG_INFO,"Duplicate section '%s' found.",*Current->Name); DATA.insert (I,Current); } Current = xr_new<Sect>(); Current->Name = 0; // start new section R_ASSERT3(strchr(str,']'),"Bad ini section found: ",str); LPCSTR inherited_names = strstr(str,"]:"); if (0!=inherited_names){ VERIFY2 (bReadOnly,"Allow for readonly mode only."); inherited_names += 2; int cnt = _GetItemCount(inherited_names); for (int k=0; k<cnt; ++k){ xr_string tmp; _GetItem (inherited_names,k,tmp); Sect& inherited_section = r_section(tmp.c_str()); for (SectIt_ it =inherited_section.Data.begin(); it!=inherited_section.Data.end(); it++) insert_item (Current,*it); } } *strchr(str,']') = 0; Current->Name = strlwr(str+1); } else { if (Current){ char* name = str; char* t = strchr(name,'='); if (t) { *t = 0; _Trim (name); _parse (str2,++t); } else { _Trim (name); str2[0] = 0; } Item I; I.first = (name[0]?name:NULL); I.second = (str2[0]?str2:NULL); #ifdef DEBUG I.comment = bReadOnly?0:comment; #endif if (bReadOnly) { if (*I.first) insert_item (Current,I); } else { if ( *I.first || *I.second #ifdef DEBUG || *I.comment #endif ) insert_item (Current,I); } } } } if (Current) { RootIt I = std::lower_bound(DATA.begin(),DATA.end(),*Current->Name,sect_pred); if ((I!=DATA.end())&&((*I)->Name==Current->Name)) Debug.fatal(DEBUG_INFO,"Duplicate section '%s' found.",*Current->Name); DATA.insert (I,Current); } }
void CTexture::Load () { flags.bLoaded = true; desc_cache = 0; if (pSurface) return; flags.bUser = false; flags.MemoryUsage = 0; if (0==stricmp(*cName,"$null")) return; if (0!=strstr(*cName,"$user$")) { flags.bUser = true; return; } Preload (); //#ifndef DEDICATED_SERVER #ifndef _EDITOR if (!g_dedicated_server) #endif { // Check for OGM string_path fn; if (FS.exist(fn,"$game_textures$",*cName,".ogm")) { // AVI pTheora = new CTheoraSurface(); m_play_time = 0xFFFFFFFF; if (!pTheora->Load(fn)) { xr_delete(pTheora); FATAL ("Can't open video stream"); } else { flags.MemoryUsage = pTheora->Width(true)*pTheora->Height(true)*4; pTheora->Play (TRUE,Device.dwTimeContinual); // Now create texture ID3DTexture2D* pTexture = 0; u32 _w = pTheora->Width(false); u32 _h = pTheora->Height(false); HRESULT hrr = HW.pDevice->CreateTexture( _w, _h, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture, NULL ); pSurface = pTexture; if (FAILED(hrr)) { FATAL ("Invalid video stream"); R_CHK (hrr); xr_delete (pTheora); pSurface = 0; } } } else if (FS.exist(fn,"$game_textures$",*cName,".avi")) { // AVI pAVI = new CAviPlayerCustom(); if (!pAVI->Load(fn)) { xr_delete(pAVI); FATAL ("Can't open video stream"); } else { flags.MemoryUsage = pAVI->m_dwWidth*pAVI->m_dwHeight*4; // Now create texture ID3DTexture2D* pTexture = 0; HRESULT hrr = HW.pDevice->CreateTexture( pAVI->m_dwWidth,pAVI->m_dwHeight,1,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED, &pTexture,NULL ); pSurface = pTexture; if (FAILED(hrr)) { FATAL ("Invalid video stream"); R_CHK (hrr); xr_delete (pAVI); pSurface = 0; } } } else if (FS.exist(fn,"$game_textures$",*cName,".seq")) { // Sequence string256 buffer; IReader* _fs = FS.r_open(fn); flags.seqCycles = FALSE; _fs->r_string (buffer,sizeof(buffer)); if (0==stricmp (buffer,"cycled")) { flags.seqCycles = TRUE; _fs->r_string (buffer,sizeof(buffer)); } u32 fps = atoi(buffer); seqMSPF = 1000/fps; while (!_fs->eof()) { _fs->r_string(buffer,sizeof(buffer)); _Trim (buffer); if (buffer[0]) { // Load another texture u32 mem = 0; pSurface = ::RImplementation.texture_load (buffer,mem); if (pSurface) { // pSurface->SetPriority (PRIORITY_LOW); seqDATA.push_back (pSurface); flags.MemoryUsage += mem; } } } pSurface = 0; FS.r_close (_fs); } else { // Normal texture u32 mem = 0; pSurface = ::RImplementation.texture_load (*cName,mem); // Calc memory usage and preload into vid-mem if (pSurface) { // pSurface->SetPriority (PRIORITY_NORMAL); flags.MemoryUsage = mem; } } //#endif } PostLoad () ; }