void Prompt_LoadHistory(commandPrompt_t *prompt, const char *filename) { char buffer[MAX_FIELD_TEXT]; qhandle_t f; int i; ssize_t len; FS_FOpenFile(filename, &f, FS_MODE_READ | FS_TYPE_REAL | FS_PATH_BASE); if (!f) { return; } for (i = 0; i < HISTORY_SIZE; i++) { if ((len = FS_ReadLine(f, buffer, sizeof(buffer))) < 1) { break; } if (prompt->history[i]) { Z_Free(prompt->history[i]); } prompt->history[i] = memcpy(Z_Malloc(len + 1), buffer, len + 1); } FS_FCloseFile(f); prompt->historyLineNum = i; prompt->inputLineNum = i; }
void NV_LoadConfig(){ int read, i; int error = 0; char buf[256]; char filename[MAX_QPATH]; *buf = 0; fileHandle_t file; if( nvEntered == qtrue ){ return; } nvEntered = qtrue; Auth_ClearAdminList(); Q_strncpyz(filename, NV_CONFIGFILE, sizeof(filename)); FS_SV_FOpenFileRead(filename, &file); if(!file) { /* Legacy nvconfig fallback */ Q_strncpyz(filename, NV_CONFIGFILEOLD, sizeof(filename)); FS_SV_FOpenFileRead(filename, &file); } if(!file){ Com_DPrintf("Couldn't open %s for reading\n", filename); nvEntered = qfalse; return; } Com_Printf( "loading %s\n", filename); i = 0; while(qtrue){ read = FS_ReadLine(buf,sizeof(buf),file); if(read == 0){ FS_FCloseFile(file); Com_Printf("Loaded %s %i errors\n", filename, error); nvEntered = qfalse; return; } if(read == -1){ Com_Printf("Can not read from %s\n", filename); FS_FCloseFile(file); nvEntered = qfalse; return; } i++;//linecouter if(!*buf || *buf == '/' || *buf == '\n'){ continue; } if(!NV_ParseConfigLine(buf, i)){ error++; } } }
qboolean HStorage_LoadDataFromFile(varStorage_t* vobj, const char* filename) { char buf[8192]; buf[0] = 0; fileHandle_t file; int read; int error; int i; vsMemObj_t* obj; if(vobj->memObj == NULL) { obj = HStorage_NewObjectInternal( VSINITIAL_STORAGE_SIZE ); if(obj == NULL) { return qfalse; } vobj->memObj = obj; } FS_SV_FOpenFileRead(filename, &file); if(!file){ Com_DPrintf("HStorage_LoadDataFromFile: Can not open %s for reading\n", filename); return qfalse; } for(i = 0, error = 0 ;error < 32 ;i++){ read = FS_ReadLine(buf, sizeof(buf), file); if(read == 0) { Com_Printf("%i lines parsed from %s, %i errors occured\n",i , filename, error); FS_FCloseFile(file); return qtrue; } if(read == -1) { Com_Printf("Can not read from %s\n", filename); FS_FCloseFile(file); return qfalse; } if(!*buf || *buf == '/' || *buf == '\n') { continue; } if(!HStorage_ParseLine(vobj, buf, i+1)) error++; //Executes the function given as argument in execute } Com_PrintWarning("More than 32 errors occured by reading from %s\n", filename); FS_FCloseFile(file); return qfalse; }
void G_SayCensor_Init() { fileHandle_t file; int read; badwordsList_t *this; qboolean exactmatch; char buff[24]; char line[24]; char* linept; register int i=0; FS_SV_FOpenFileRead("badwords.txt",&file); if(!file){ Com_DPrintf("censor_init: Can not open badwords.txt for reading\n"); return; } for(i = 0; ;i++){ read = FS_ReadLine(buff,sizeof(buff),file); if(read == 0){ Com_Printf("%i lines parsed from badwords.txt\n",i); FS_FCloseFile(file); return; } if(read == -1){ Com_Printf("Can not read from badwords.txt\n"); FS_FCloseFile(file); return; } Q_strncpyz(line,buff,sizeof(line)); linept = line; if(*linept == '#'){ exactmatch = qtrue; linept++; }else{ exactmatch = qfalse; } this = Z_Malloc(sizeof(badwordsList_t)); if(this){ this->next = svse.badwords; this->exactmatch = exactmatch; Q_strncpyz(this->word,linept,strlen(linept)); svse.badwords = this; } } }
void SV_LoadBanlist(){ time_t aclock; time(&aclock); char buf[256]; buf[0] = 0; fileHandle_t file; int read; int error; int i; FS_SV_FOpenFileRead(banlistfile->string,&file); if(!file){ Com_DPrintf("SV_ReadBanlist: Can not open %s for reading\n",banlistfile->string); return; } for(i = 0, error = 0 ;error < 32 ;i++){ read = FS_ReadLine(buf,sizeof(buf),file); if(read == 0){ Com_Printf("%i lines parsed from %s, %i errors occured\n",i,banlistfile->string,error); FS_FCloseFile(file); return; } if(read == -1){ Com_Printf("Can not read from %s\n",banlistfile->string); FS_FCloseFile(file); return; } if(!*buf || *buf == '/' || *buf == '\n'){ continue; } if(!SV_ParseBanlist(buf, aclock, i+1)) error++; //Executes the function given as argument in execute } Com_PrintWarning("More than 32 errors occured by reading from %s\n",banlistfile->string); FS_FCloseFile(file); }
void CheckLiblistForFallbackDir(const char *pGameDir, bool bLanguage, const char *pLanguage, bool bLowViolenceBuild_) { char szTemp[512]; FileHandle_t hFile; Q_snprintf(szTemp, sizeof(szTemp) - 1, "%s/liblist.gam", pGameDir); COM_FixSlashes(szTemp); g_pFileSystem->GetLocalCopy(szTemp); if (Q_stricmp(com_gamedir, pGameDir)) { Q_snprintf(szTemp, 511, "../%s/liblist.gam", pGameDir); COM_FixSlashes(szTemp); hFile = FS_Open(szTemp, "rt"); } else hFile = FS_Open("liblist.gam", "rt"); if (!hFile) return; if (FS_EndOfFile(hFile)) { FS_Close(hFile); return; } char szFallback[128]; char szLine[512]; char *end; char *start; int bytesToCopy; while (1) { szLine[0] = 0; FS_ReadLine(szLine, sizeof(szLine) - 1, hFile); szLine[511] = 0; if (!Q_strnicmp(szLine, "fallback_dir", Q_strlen("fallback_dir"))) { start = Q_strchr(szLine, '"'); if (!start) { FS_Close(hFile); return; } end = Q_strchr(start + 1, '"'); if (!end) { FS_Close(hFile); return; } bytesToCopy = (int)(end - start) - 1; if (bytesToCopy > sizeof(szFallback) - 2) { FS_Close(hFile); return; } if (bytesToCopy > 0) break; } if (FS_EndOfFile(hFile)) { FS_Close(hFile); return; } } Q_strncpy(szFallback, start + 1, bytesToCopy); szFallback[bytesToCopy] = 0; if (!Q_stricmp(pGameDir, szFallback) ) { FS_Close(hFile); return; } if (bLowViolenceBuild) { Q_snprintf(szTemp, 511, "%s/%s_lv", GetBaseDirectory(), szFallback); szTemp[511] = 0; COM_FixSlashes(szTemp); g_pFileSystem->AddSearchPathNoWrite(szTemp, "GAME_FALLBACK"); } if (BEnableAddonsFolder()) { Q_snprintf(szTemp, 511, "%s/%s_addon", GetBaseDirectory(), szFallback); szTemp[511] = 0; COM_FixSlashes(szTemp); g_pFileSystem->AddSearchPathNoWrite(szTemp, "GAME_FALLBACK"); } if (bLanguage && pLanguage) { char baseDir[4096]; char *tempPtr; Q_snprintf(szTemp, 511, "%s/%s_%s", GetBaseDirectory(), szFallback, pLanguage); szTemp[511] = 0; COM_FixSlashes(szTemp); g_pFileSystem->AddSearchPath(szTemp, "GAME_FALLBACK"); if (!COM_CheckParm("-steam")) { Q_strncpy(baseDir, GetBaseDirectory(), sizeof(baseDir) - 1); baseDir[sizeof(baseDir) - 1] = 0; tempPtr = Q_strstr(baseDir, "\\game"); if (tempPtr) { *tempPtr = 0; Q_snprintf(szTemp, 511, "%s\\localization\\%s_%s", baseDir, szFallback, pLanguage); szTemp[511] = 0; COM_FixSlashes(szTemp); g_pFileSystem->AddSearchPath(szTemp, "GAME_FALLBACK"); } } } if (BEnabledHDAddon()) { Q_snprintf(szTemp, 511, "%s/%s_hd", GetBaseDirectory(), szFallback); szTemp[511] = 0; COM_FixSlashes(szTemp); g_pFileSystem->AddSearchPathNoWrite(szTemp, "GAME_FALLBACK"); } Q_snprintf(szTemp, 511, "%s/%s", GetBaseDirectory(), szFallback); szTemp[511] = 0; COM_FixSlashes(szTemp); g_pFileSystem->AddSearchPath(szTemp, "GAME_FALLBACK"); if (Q_stricmp(szFallback, "valve")) { const int BufLen = 128; char *szFileName = new char[BufLen]; Q_snprintf(szFileName, BufLen - 1, "Resource/%s_%%language%%.txt", szFallback); szFileName[BufLen - 1] = 0; g_fallbackLocalizationFiles.AddToTail(szFileName); CheckLiblistForFallbackDir(szFallback, bLanguage, pLanguage, bLowViolenceBuild); } FS_Close(hFile); }