void Lexeme::PrintValue(FILE* F) { if (type == TypeInteger) fprintf_s(F, "\t%s", text.c_str()); if (type == TypeReal) fprintf_s(F, "\t%.4e", atof(text.c_str())); if (type == TypeString) fprintf_s(F, "\t%s", text.substr(1, text.length() - 2).c_str()); if (type == TypeChar) { if (text[0] == '\'') return; if (text[1] == '$') //hex fprintf_s(F, "\t%c", atoi(FromHexToInt(text.substr(2, text.length() - 2)).c_str())); else fprintf(F, "\t%c", atoi(text.substr(1, text.length() - 1).c_str())); } if (type == TypeHex) fprintf_s(F, "\t%s", FromHexToInt(text).c_str()); return; }
// core_list.txt를 쓴다. //int XMain::WriteCoreList( XArrayLinear<_tstring>& aryCore ) int XMain::WriteCoreList( const XVector<_tstring>& aryCore ) { char cPath[ 1024 ]; strcpy_s( cPath, SZ2C( XE::_GetPathPackageRoot() ) ); strcat_s( cPath, "core_list.txt" ); FILE *fp = NULL; fopen_s( &fp, cPath, "wt" ); if( fp == NULL ) return 0; char cBuff[ 1024 ]; // XARRAYLINEAR_LOOP( aryCore, _tstring, strRes ) for( auto& strRes : aryCore ) { strcpy_s( cBuff, SZ2C( strRes.c_str() ) ); strReplace( cBuff, '\\', '/' ); fprintf_s( fp, "\"%s\"\n", cBuff ); // fprintf_s( fp, "\"%s\"\n", SZ2C( strRes.c_str() ) ); } fprintf_s( fp, "// num files %d \n", aryCore.size() ); fclose( fp ); return 1; }
void o_docsect( FILE * f, lay_att curr, ban_docsect * tm ) { const char * p; if( *tm >= no_ban && *tm < max_ban) { p = doc_sections[*tm].name; } else { p = "???"; } fprintf_s( f, " %s = %s\n", att_names[curr], p ); return; }
void o_yes_no( FILE * f, lay_att curr, bool * tm ) { char const * p; if( *tm == 0 ) { p = strno; } else { p = stryes; } fprintf_s( f, " %s = %s\n", att_names[curr], p ); return; }
void memInit(void) { memHeap = (char*)malloc(MAX_HEAP); if (memHeap == NULL) { fprintf_s(stderr,"内存空间不足,无法得到足够多的虚拟内存!\n"); exit(1); } memBrk = (char*)memHeap; memMaxAddr = (char*)(memHeap + MAX_HEAP); }
void ob_flush( void ) { if( fwrite( buffout.text, sizeof( uint8_t ), buffout.current, out_file_fp ) < buffout.current ) { xx_simple_err_c( err_write_out_file, out_file ); return; } buffout.current = 0; #ifdef __UNIX__ if( fprintf_s( out_file_fp, "\n" ) < strlen( "\n" ) ) { xx_simple_err_c( err_write_out_file, out_file ); return; } #else if( fprintf_s( out_file_fp, "\r\n" ) < strlen( "\r\n" ) ) { xx_simple_err_c( err_write_out_file, out_file ); return; } #endif return; }
void save() { FILE* f; char buf[64]; SYSTEMTIME st; GetLocalTime(&st); sprintf_s(buf, "%04d%02d%02d%02d%02d%02d.swr.txt", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); if(fopen_s(&f, buf, "w") == 0) { fprintf_s(f, board->toString().c_str()); fclose(f); MessageBox(hWndMain, TEXT("Saved"), lpszClass, MB_OK); } }
void LogManager::WriteToLogFile(const std::string log) { FILE* file; fopen_s(&file, LOG_FILE, "a+"); if (!file) { fprintf(stderr, "Unable to open log file %s for appending\n", LOG_FILE); return; } fprintf_s(file, log.c_str()); fclose(file); }
void CStackWalker::OnOutput(LPCSTR szText) { std::string s = CommonFunctions::FormatOutputString("logs", "CrashLog", false); FILE * m_file; fopen_s(&m_file, s.c_str(), "a"); if(!m_file) return; printf_s(" %s", szText); fprintf_s(m_file, " %s", szText); fclose(m_file); }
void o_frame( FILE * f, lay_att curr, bool * tm ) { char * p; if( *tm ) { p = "rule"; } else { p = "none"; } fprintf_s( f, " %s = %s\n", att_names[curr], p ); return; }
void Logger::createLogFile(){ ostringstream oss; oss << (int) m_Session_id; string fileName = Log_directory; fileName += log_name + oss.str() + ext; m_CurrentLogFile = fileName; string dynName = Log_directory; dynName += dyn_log_name + oss.str() + ext; m_dynamic_logname = dynName; FILE* file = NULL; fopen_s(&file,fileName.c_str(),"w"); fprintf_s(file,"# Game Session ID \n"); fprintf_s(file,"%d \n",m_Session_id); fprintf_s(file,"### Session Start ### \n"); fclose(file); file = NULL; fopen_s(&file,dynName.c_str(),"w"); fprintf_s(file,"# Game Session ID \n"); fprintf_s(file,"%d \n",m_Session_id); fprintf_s(file,"### Session Start ### \n"); fclose(file); }
void EventReceiver::saveKeyMapping() { FILE* f; errno_t error = fopen_s(&f, keyMappingFilename.c_str(), "w"); if (error) { printf("unable to open file for write %s\n", keyMappingFilename.c_str()); return; } bool first = true; for (keyNameMap_t::const_iterator it = keyNameMap.begin(); it != keyNameMap.end(); it++) { if (keyMap[it->second].primaryKeyConfig || keyMap[it->second].secondaryKeyConfig) { if (first) { first = false; } else { fprintf_s(f, "\n"); } fprintf_s(f, "[%s]\n", it->first.c_str()); } if (keyMap[it->second].primaryKeyConfig) { keyMap[it->second].primaryKeyConfig->writeToFile(f, "primary"); } if (keyMap[it->second].secondaryKeyConfig) { keyMap[it->second].secondaryKeyConfig->writeToFile(f, "secondary"); } } fclose(f); }
void ErrorHandler(PRT_STATUS status, PRT_MACHINEINST *ptr) { if (status == PRT_STATUS_ASSERT) { fprintf_s(stdout, "exiting with PRT_STATUS_ASSERT (assertion failure)\n"); exit(1); } else if (status == PRT_STATUS_EVENT_OVERFLOW) { fprintf_s(stdout, "exiting with PRT_STATUS_EVENT_OVERFLOW\n"); exit(1); } else if (status == PRT_STATUS_EVENT_UNHANDLED) { fprintf_s(stdout, "exiting with PRT_STATUS_EVENT_UNHANDLED\n"); exit(1); } else if (status == PRT_STATUS_QUEUE_OVERFLOW) { fprintf_s(stdout, "exiting with PRT_STATUS_QUEUE_OVERFLOW \n"); exit(1); } else if (status == PRT_STATUS_ILLEGAL_SEND) { fprintf_s(stdout, "exiting with PRT_STATUS_ILLEGAL_SEND \n"); exit(1); } else { fprintf_s(stdout, "unexpected PRT_STATUS in ErrorHandler: %d\n", status); exit(2); } }
void o_default_frame( FILE * f, lay_att curr, def_frame * tm ) { switch( tm->type ) { case none: fprintf_s( f, " %s = none\n", att_names[curr] ); break; case rule_frame: fprintf_s( f, " %s = rule\n", att_names[curr] ); break; case box_frame: fprintf_s( f, " %s = box\n", att_names[curr] ); break; case char_frame: fprintf_s( f, " %s = '%s'\n", att_names[curr], tm->string ); break; default: fprintf_s( f, " %s = ???\n", att_names[curr] ); break; } return; }
void *memSbrk(int incr) { char *oldBrk = memBrk; if ((incr < 0)||((memBrk + incr) > memMaxAddr)) { errno = ENOMEM; fprintf_s(stderr,"错误:memSbrk失败,内存空间不足...\n"); return (void*)-1; } memBrk += incr; return (void*)oldBrk; }
static bool WriteHLSL(string hlslText, AsmTextBlob* asmTextBlob, UINT64 hash, wstring shaderType) { wchar_t fullName[MAX_PATH]; FILE *fw; wsprintf(fullName, L"%ls\\%08lx%08lx-%ls_replace.txt", G->SHADER_PATH, (UINT32)(hash >> 32), (UINT32)hash, shaderType.c_str()); _wfopen_s(&fw, fullName, L"rb"); if (fw) { LogInfoW(L" marked shader file already exists: %s\n", fullName); fclose(fw); _wfopen_s(&fw, fullName, L"ab"); if (fw) { fprintf_s(fw, " "); // Touch file to update mod date as a convenience. fclose(fw); } BeepShort(); // Short High beep for for double beep that it's already there. return true; } _wfopen_s(&fw, fullName, L"wb"); if (!fw) { LogInfoW(L" error storing marked shader to %s\n", fullName); return false; } LogInfoW(L" storing patched shader to %s\n", fullName); fwrite(hlslText.c_str(), 1, hlslText.size(), fw); fprintf_s(fw, "\n\n/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); // Size - 1 to strip NULL terminator fwrite(asmTextBlob->GetBufferPointer(), 1, asmTextBlob->GetBufferSize() - 1, fw); fprintf_s(fw, "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/\n"); fclose(fw); return true; }
void Usage(char * pszProgramName) { fprintf_s(stderr, "Usage: %s\n", pszProgramName); fprintf_s(stderr, " -p protocol_sequence (default is '%s')\n", DEFAULT_PROTOCOL_SEQUENCE); fprintf_s(stderr, " -e endpoint (default is '%s')\n", DEFAULT_ENDPOINT); fprintf_s(stderr, " -a server principal name\n"); fprintf_s(stderr, " -m maxcalls (default is %d)\n", DEFAULT_MAX_CALLS); fprintf_s(stderr, " -n mincalls (default is %d)\n", DEFAULT_MIN_CALLS); fprintf_s(stderr, " -f flag_wait_op (default is %d)\n", DEFAULT_WAIT_FLAG); exit(1); }
DWORD CUsbtestDlg::WaitWaveProc() { while (true) { if (!run) { Sleep(1); continue; } unsigned char* buffer = NULL; if (DEVCTRL_SUCCESS != WaitWavePacket(devID, &buffer, 30000)) { Sleep(0); continue; } static int ifile = 0; if (ifile < 10) { char name[16]; sprintf_s(name, 16, "wave_%d.log", ifile); FILE* pf = fopen(name, "w"); for (int i = 0; i < waveSize*waveCount; i++) { fprintf_s(pf, "%d\n", buffer[i]); } fclose(pf); ifile++; } AddBuffer(devID, m_buffer, waveSize*waveCount); if (buffer) { m_buffer = buffer; curNo++; Invalidate(); UpdateWindow(); } } return 0; }
int CTResultReport::LogDataNF(char* sn,char *datetime,char* filename,char* pData) { FILE *fLog; char PathBuf[256]; char FileName[512]; char nf_log_folder[512]; int iFileOpenErr = 0; if(!GetCurrentDirectory(sizeof(PathBuf), PathBuf)) { return FALSE; } else { sprintf_s(FileName, sizeof(FileName), "%s\\NF_Data\\", PathBuf,sn,datetime); sprintf_s(nf_log_folder, sizeof(nf_log_folder), "%s\\NF_Data\\NF_%s_%s\\", PathBuf,sn,datetime); if(!PathFileExists(FileName)) { if(!CreateDirectory(FileName,NULL)) { amprintf("Create Folder Fail!\n"); return 0; } } if(!PathFileExists(nf_log_folder)) { if(!CreateDirectory(nf_log_folder,NULL)) { amprintf("Create Folder Fail!\n"); return 0; } } strcat_s(nf_log_folder, sizeof(nf_log_folder), filename); //Maxwell 090622 mutex operate log //WaitForSingleObject(hWriteLogMutex, INFINITE); //Sleep(1); iFileOpenErr = fopen_s(&fLog, nf_log_folder, "a+"); if(NULL == fLog) { return FALSE; } fprintf_s(fLog,"%s\n",pData); fclose(fLog); //ReleaseMutex(hWriteLogMutex); } return TRUE; }
void KUVSocket::OnConnectionIncoming(uv_stream_t * pListener, int status) { // do something for fprintf_s(stdout, "some one connection"); ConnectionUserData* pData = (ConnectionUserData*)pListener->data; KUVSocket* pSocket = pData->ServerSocket; if (status != 0) { pSocket->OnError(pData->Conn, status); return; } pSocket->Accept(pListener); }
// Faz a reposicao (Restore) ou guarda uma copia do ficheiro (Backup), conforme o bool recebido. // backupNrestore = true -> Backup // backupNrestore = false -> Restore BOOL CopyFile(BOOL backupNrestore, HBACKUPENTRY copyRequest){ FILE * origin; FILE * destiny; CHAR auxBuffer[MAX_PATH]; DWORD i, ofnIdx; //ofnIdx serve para copiar todos os chars para um char* local, com o nome do ficheiro original CHAR* separator = "\\", *terminator = "\0"; SIZE_T sz, filePathSize = strlen((CHAR*)backupService->fileStoragePath) + strlen(separator) + strlen((CHAR*)copyRequest->file) + 1; CHAR*repoFileName, *originalFileName; repoFileName = (CHAR*)malloc(filePathSize); originalFileName = (CHAR*)malloc(strlen((CHAR*)copyRequest->file) + 1); sz = strlen((CHAR*)backupService->fileStoragePath) + 1; strcpy_s(repoFileName, sz, (CHAR*)backupService->fileStoragePath); sz += strlen(separator); strcat_s(repoFileName, filePathSize, separator); ofnIdx = 0; for (i = 0; i < STR_MAX_SIZE; i++){ CHAR * part = (CHAR*)(copyRequest->file + i*sizeof(CHAR)); if (strcmp(part, terminator) == 0) break; sz++; ofnIdx++; strcat_s(repoFileName, sz, part); if (ofnIdx == 1) strcpy_s(originalFileName, ofnIdx + 1, part); else strcat_s(originalFileName, ofnIdx + 1, part); } if (fopen_s(&origin, backupNrestore?originalFileName : repoFileName, "rb") != 0){// abrir ficheiro origem para ler printf("\nERRO... O ficheiro %s nao existe!", backupNrestore ? originalFileName : repoFileName); return FALSE; } if (fopen_s(&destiny, backupNrestore ? repoFileName : originalFileName, "wb+") != 0){ printf("\nERRO... Nao foi possivel criar o ficheiro %s ! Verifique se o caminho existe!", backupNrestore ? repoFileName : originalFileName); return FALSE; } while (fgets(auxBuffer, sizeof(auxBuffer), origin) != NULL){ fprintf_s(destiny, auxBuffer); } fclose(origin); fclose(destiny); return TRUE; }
void driverProgram(char *inputFile, char *outputFile) { FILE *fin = fopen(inputFile, "r"); FILE *fout = fopen(outputFile, "w"); int source; graph *G = loadGraph(fin); int **cost = alocateMemoryForCost(G->noOfVertices); int *predecesors = allocateMemoryForPredecesors(G->noOfVertices); printf_s("Give the source vertex:"); scanf_s("%d", &source); BellmanFord(G, source, cost, predecesors); for (int i = 0; i < G->noOfVertices; i++) { fprintf_s(fout, "%d\n", cost[1][i]); } while (true) { int destination; printf_s("Give the vertex to which you want to reconstruct the path:"); scanf_s("%d", &destination); if (cost[1][destination] == infinite) { printf_s("there is no path to %d from %d\n", destination, source); } else if (cost[1][destination] == minfinite) { printf_s("it is a negative cycle cannot display path\n"); } else { reconstructPath(source, destination, G, predecesors); } printf_s("Continue? \n1.Yes\n0.No\n"); int dummy; scanf_s("%d",&dummy); if (dummy == 0) { break; } } fclose(fin); fclose(fout); }
void WaveFrontObj_WriteMaterial(const char *texelName, const char *texelFilename, const Material * const mat) { char texelNameCopy[MAX_PATH]; strcpy_s(texelNameCopy, texelName); RemoveSpaces(texelNameCopy); fprintf_s(matFile, "newmtl %s\n", texelNameCopy); fprintf_s(matFile, "Ns 7.843137\n"); D3DXVECTOR4 color = convertColor(mat->m_cBase); fprintf_s(matFile, "Ka 0.000000 0.000000 0.000000\n"); fprintf_s(matFile, "Kd %f %f %f\n", color.x, color.y, color.z); color = convertColor(mat->m_cGlossy); fprintf_s(matFile, "Ks %f %f %f\n", color.x, color.y, color.z); fprintf_s(matFile, "Ni 1.500000\n"); fprintf_s(matFile, "d %f\n", mat->m_fOpacity); fprintf_s(matFile, "illum 5\n"); if (texelFilename != NULL) { strcpy_s(texelNameCopy, texelFilename); RemoveSpaces(texelNameCopy); fprintf_s(matFile, "map_kd %s\n", texelNameCopy); fprintf_s(matFile, "map_ka %s\n\n", texelNameCopy); } }
/* static */ bool RaceManager::writeGlobalObjects(const std::string& fileName, const RaceManager::globalObjectList_t& globalObjectList) { FILE* f; errno_t error = fopen_s(&f, fileName.c_str(), "w"); if (error) { printf("unable to open file for write %s\n", fileName.c_str()); return false; } unsigned int id = 1; char fillZero[5] = {'0', '0', '0', '0', 0}; assert(globalObjectList.size() < 100000); for (globalObjectList_t::const_iterator it = globalObjectList.begin(); it != globalObjectList.end(); it++) { if (id != 1) { fprintf_s(f, "\n"); } if (id < 10) { fillZero[4] = 0; } else if (id < 100) { fillZero[3] = 0; } else if (id < 1000) { fillZero[2] = 0; } else if (id < 10000) { fillZero[1] = 0; } else { fillZero[0] = 0; } fprintf_s(f, "[%s%u]\n", fillZero, id); fprintf_s(f, "type=%s\n", (*it)->getObjectPool()->getName().c_str()); fprintf_s(f, "pos=%f %f %f\n", (*it)->getPos().X, (*it)->getPos().Y, (*it)->getPos().Z); fprintf_s(f, "rot=%f %f %f\n", (*it)->getRot().X, (*it)->getRot().Y, (*it)->getRot().Z); fprintf_s(f, "scale=%f %f %f\n", (*it)->getScale().X, (*it)->getScale().Y, (*it)->getScale().Z); id++; } fclose(f); return true; }
// Use when log one info // same as startLogWrite();writeToLog(log);void endLogWrite(); void Logger::saveToLogFile(const char* log){ if(m_CurrentLogFile != ""){ FILE* file = NULL; fopen_s(&file, m_CurrentLogFile.c_str(), "r+"); if(file != NULL){ endOffile(file); fprintf_s(file,"%s",log); fclose(file); } } }
void Logger::saveEndInfo(){ FILE* file = NULL; fopen_s(&file, m_CurrentLogFile.c_str(),"r+"); endOffile(file); fprintf_s(file,"# Game End Date and Time \n"); struct tm Today; time_t now; time(&now); localtime_s(&Today, &now); saveTimeDate(file,&Today); fprintf_s(file,"# ---------------------------------------------------------- # \n\n "); fclose(file); }
void SaveFile(LPCTSTR lpszFormat,...) { if(!lpszFormat) return; char _buf[409600]; va_list args; va_start(args, lpszFormat); _vsnprintf_s(_buf,(sizeof(_buf)/sizeof(_buf[0])),lpszFormat,args); va_end(args); FILE *fp=fopen("\\packet.txt","a"); fprintf_s(fp,"%s\n",_buf); fclose(fp); return; }
/////////////////////////////////////////////////////////////////////////////// // Log - Logs the given string to the file associated with Type void Debug::Debugger::Log( LogType::LogType Type, const char* Format, va_list ArgList ) { if(!m_bLogging) return; ASSERT( m_LogFiles[ Type ].FileHandle ); // Write to the appropriate log file vfprintf( m_LogFiles[ Type ].FileHandle, Format, ArgList ); fflush( m_LogFiles[ Type ].FileHandle ); // Format the string char Buffer[ MAX_STRING_LENGTH ]; vsprintf_s( Buffer, MAX_STRING_LENGTH, Format, ArgList ); OutputDebugStringA( Buffer ); // If this is a system specific log file, also log it to the general log if( Type != LogType::e_Debug ) { ASSERT( m_LogFiles[ LogType::e_Debug ].FileHandle ); #if defined ( WIN32 ) || defined ( WIN64 ) // Try to enter the critical section u32 Index; for( Index = 0; Index < 1000; Index++ ) { if( TryEnterCriticalSection( m_CsFileWrite ) ) { break; } Sleep(1); } // If we failed to enter, call the full EnterCriticalSection and wait if( Index == 1000 ) { EnterCriticalSection( m_CsFileWrite ); } // Print the string fprintf_s( m_LogFiles[ LogType::e_Debug ].FileHandle, "[%s] %s", m_LogFiles[ Type ].SystemName, Buffer ); fflush( m_LogFiles[ LogType::e_Debug ].FileHandle ); // Leave the critical section LeaveCriticalSection( m_CsFileWrite ); #endif } }
void Usage(char * pszProgramName) { fprintf_s(stderr, "%s", PURPOSE); fprintf_s(stderr, "Usage: %s\n", pszProgramName); fprintf_s(stderr, " -d\n"); fprintf_s(stderr, " -e\n"); fprintf_s(stderr, " -ffilename\n"); fprintf_s(stderr, " -i \n"); exit(1); }
int CTResultReport::LogDataCAL(char* sn,char *datetime,char* filename,char* pData) { FILE *fLog; char PathBuf[256]=""; char FileName[512]=""; char cal_log_folder[512]=""; int iFileOpenErr = 0; if(!GetCurrentDirectory(sizeof(PathBuf), PathBuf)) { return FALSE; } else { sprintf_s(FileName, sizeof(FileName), "%s\\NF_Data\\", PathBuf,sn,datetime); sprintf_s(cal_log_folder, sizeof(cal_log_folder), "%s\\NF_Data\\NF_%s_%s\\", PathBuf,sn,datetime); if(!PathFileExists(FileName)) { if(!CreateDirectory(FileName,NULL)) { amprintf("Create Folder Fail!\n"); return 0; } } if(!PathFileExists(cal_log_folder)) { if(!CreateDirectory(cal_log_folder,NULL)) { amprintf("Create Folder Fail!\n"); return 0; } } strcat_s(cal_log_folder, sizeof(cal_log_folder), filename); iFileOpenErr = fopen_s(&fLog, cal_log_folder, "a+"); if(NULL == fLog) { return FALSE; } fprintf_s(fLog,"%s\n",pData); fclose(fLog); } return TRUE; }