📄 misc.cpp
字号:
// $common\misc.cpp 1.5 milbo$ miscellaneous routines that don't fit into any other category// Warning: this is raw research code -- expect it to be quite messy.// milbo mar 2005 petaluma#include <stdio.h>#include <stdlib.h>#include <io.h>#include <direct.h>#include <time.h>#include "mcommon.hpp"#include "util.hpp"//-----------------------------------------------------------------------------int nFilesMatchingSpec (char sFileSpec[]){struct _finddata_t FileData;long hFile;int nFiles = 1; // assume first file matchesif ((hFile = _findfirst(sFileSpec, &FileData)) == -1L) return 0; // no matcheswhile (_findnext(hFile, &FileData) == 0) nFiles++;_findclose(hFile);return nFiles;}//-----------------------------------------------------------------------------// returns true if directory already existsbool fCreateDirectory (const char sPath[]){bool f = true;if (_access(sPath, 0) == -1) // doesn't exist? { lprintf("Creating directory %s\n", sPath); f = false; }_mkdir(sPath); // if this fails we will know later when we try to write to itreturn f;}//-----------------------------------------------------------------------------void FormatTime (char s[], double Time){int temp1, temp;if (Time >= (60.0 * 60.0 * CLOCKS_PER_SEC)) { temp = (int)(Time / (60.0 * CLOCKS_PER_SEC)); temp1 = temp / 60; sprintf(s, "%d hour%s %d min", temp1, ((temp1==1)? "":"s"), temp - 60 * temp1); }else if (Time >= 60.0 * CLOCKS_PER_SEC) { temp1 = (int)(Time / (60.0 * CLOCKS_PER_SEC)); temp = (int)(Time/CLOCKS_PER_SEC - 60 * temp1); sprintf(s, "%d min %d sec%s", temp1, temp, ((temp==1)? "":"s")); }else sprintf(s, "%.2f secs", Time / CLOCKS_PER_SEC);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -