📄 procedures.cpp
字号:
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@StrStr(,%s): String to search is empty.",
(const char *)strSearchFor);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
if (strSearchFor.IsEmpty())
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@StrStr(%s,): String to search for is empty.",
(const char *)strSearchIn);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
int nIndex = strSearchIn.Find(strSearchFor);
strResult.Format("%d",nIndex);
return(TRUE);
}
BOOL TextColor(CString &strParams, CString &strResult)
{
int nRed = FOREGROUND_RED;
int nGreen = FOREGROUND_GREEN;
int nBlue = FOREGROUND_BLUE;
int nIntensity = FOREGROUND_INTENSITY;
if (!_ptlLastText)
{
strResult = "-1";
return(TRUE);
}
CString strText;
FindParam(strParams, strText);
ReplaceVariables(strText);
if (strText.IsEmpty())
{
if (_config.bDebugMessages)
{
PrintMessage("@TextColor(): Text to search for is empty.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
strResult = "-1";
return(FALSE);
}
char *pszMatch = strstr(_ptlLastText->m_ptrText,strText);
if (!pszMatch)
{
strResult = "-1";
return(TRUE);
}
int nIndex = pszMatch-_ptlLastText->m_ptrText;
if (nIndex < 0 || nIndex >= _ptlLastText->m_nLen)
{
strResult = "-1";
return(TRUE);
}
strResult.Format("%d",_ptlLastText->m_ptrAttr[nIndex] & 0x0F);
return(TRUE);
}
BOOL Time(CString &strParams, CString &strResult)
{
time_t tNow = time(NULL);
strResult.Format("%ld",tNow);
return(TRUE);
}
BOOL TimeToHour(CString &strParams, CString &strResult)
{
CString strTime;
time_t nTime;
struct tm *pTime;
FindParam(strParams,strTime);
ReplaceVariables(strTime);
nTime = atol(strTime);
if (strTime.IsEmpty() || !nTime)
{
if (_config.bDebugMessages)
{
PrintMessage("@TimeToHour(): Missing a time value.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
pTime = localtime(&nTime);
if (!pTime)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@TimeToHour(%ld): Invalid time value.",nTime);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult.Format("%d",pTime->tm_hour);
return(TRUE);
}
BOOL TimeToMinute(CString &strParams, CString &strResult)
{
CString strTime;
time_t nTime;
struct tm *pTime;
FindParam(strParams,strTime);
ReplaceVariables(strTime);
nTime = atol(strTime);
if (strTime.IsEmpty() || !nTime)
{
if (_config.bDebugMessages)
{
PrintMessage("@TimeToMinute(): Missing a time value.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
pTime = localtime(&nTime);
if (!pTime)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@TimeToMinute(%ld): Invalid time value.",nTime);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult.Format("%d",pTime->tm_min);
return(TRUE);
}
BOOL TimeToSecond(CString &strParams, CString &strResult)
{
CString strTime;
time_t nTime;
struct tm *pTime;
FindParam(strParams,strTime);
ReplaceVariables(strTime);
nTime = atol(strTime);
if (strTime.IsEmpty() || !nTime)
{
if (_config.bDebugMessages)
{
PrintMessage("@TimeToSecond(): Missing a time value.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
pTime = localtime(&nTime);
if (!pTime)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@TimeToSecond(%ld): Invalid time value.",nTime);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult.Format("%d",pTime->tm_sec);
return(TRUE);
}
BOOL TimeToDay(CString &strParams, CString &strResult)
{
CString strTime;
time_t nTime;
struct tm *pTime;
FindParam(strParams,strTime);
ReplaceVariables(strTime);
nTime = atol(strTime);
if (strTime.IsEmpty() || !nTime)
{
if (_config.bDebugMessages)
{
PrintMessage("@TimeToDay(): Missing a time value.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
pTime = localtime(&nTime);
if (!pTime)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@TimeToDay(%ld): Invalid time value.",nTime);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult.Format("%d",pTime->tm_mday);
return(TRUE);
}
BOOL TimeToDayOfWeek(CString &strParams, CString &strResult)
{
CString strTime;
time_t nTime;
struct tm *pTime;
FindParam(strParams,strTime);
ReplaceVariables(strTime);
nTime = atol(strTime);
if (strTime.IsEmpty() || !nTime)
{
if (_config.bDebugMessages)
{
PrintMessage("@TimeToDayOfWeek(): Missing a time value.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
pTime = localtime(&nTime);
if (!pTime)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@TimeToDayOfWeek(%ld): Invalid time value.",nTime);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult.Format("%d",pTime->tm_wday);
return(TRUE);
}
BOOL TimeToMonth(CString &strParams, CString &strResult)
{
CString strTime;
time_t nTime;
struct tm *pTime;
FindParam(strParams,strTime);
ReplaceVariables(strTime);
nTime = atol(strTime);
if (strTime.IsEmpty() || !nTime)
{
if (_config.bDebugMessages)
{
PrintMessage("@TimeToMonth(): Missing a time value.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
pTime = localtime(&nTime);
if (!pTime)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@TimeToMonth(%ld): Invalid time value.",nTime);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult.Format("%d",pTime->tm_mon);
return(TRUE);
}
BOOL TimeToYear(CString &strParams, CString &strResult)
{
CString strTime;
time_t nTime;
struct tm *pTime;
FindParam(strParams,strTime);
ReplaceVariables(strTime);
nTime = atol(strTime);
if (strTime.IsEmpty() || !nTime)
{
if (_config.bDebugMessages)
{
PrintMessage("@TimeToYear(): Missing a time value.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
pTime = localtime(&nTime);
if (!pTime)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@TimeToYear(%ld): Invalid time value.",nTime);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult.Format("%d",pTime->tm_year+1900);
return(TRUE);
}
BOOL Upper(CString &strParams, CString &strResult)
{
FindParam(strParams,strResult);
ReplaceVariables(strResult);
strResult.MakeUpper();
return(TRUE);
}
BOOL Val(CString &strParams, CString &strResult)
{
CString strText;
FindParam(strParams,strText);
strResult.Format("%d",atoi(strText));
return(TRUE);
}
BOOL Var(CString &strParams, CString &strResult)
{
CString strName;
FindParam(strParams,strName);
ReplaceVariables(strName);
STRING_MAP *pMap = _mapVars.FindExactByKey(strName);
if (pMap == NULL)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@Var(%s): Cannot find the variable.",
(const char *)strName);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult = pMap->strText;
return(TRUE);
}
BOOL VersionProc(CString &strParams, CString &strResult)
{
strResult = _config.strVersion;
return(TRUE);
}
BOOL Word(CString &strParams, CString &strResult)
{
CString strText;
CString strNum;
FindParam(strParams, strText);
FindParam(strParams, strNum);
ReplaceVariables(strText);
ReplaceVariables(strNum);
// If the text is empty just return and empty string. Don't
// want the function to fail just because you might have an
// emtpy string.
if (strText.IsEmpty())
return(TRUE);
// Numbers less than 1 are invalid.
int nNum = atoi(strNum);
if (strNum.IsEmpty() || nNum < 1)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@Word(%s,%d): Numbers less than 1 are invalid.",
(const char *)strText,nNum);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
// Pull the words off and count them.
int nTokenCount = 1;
char *pszText = strText.GetBuffer(strText.GetLength()+1);
char *ptr = strtok(pszText," ");
while(pszText != NULL && nTokenCount < nNum)
{
ptr = strtok(NULL," ");
nTokenCount++;
}
// If the token count is the same as the number of the word
// we are looking for, we fount it. If not the result string
// will just remain empty and the function still returns
// TRUE. Again, don't want the function to fail.
if (nNum == nTokenCount)
strResult = ptr;
return(TRUE);
}
BOOL WordColor(CString &strParams, CString &strResult)
{
if (!_ptlLastText)
{
strResult = "-1";
return(TRUE);
}
CString strNum;
FindParam(strParams, strNum);
ReplaceVariables(strNum);
// Numbers less than 1 are invalid.
int nNum = atoi(strNum);
if (strNum.IsEmpty() || nNum < 1)
{
strResult = "-1";
return(TRUE);
}
if (nNum == 1)
{
strResult.Format("%d",_ptlLastText->m_ptrAttr[0]);
return(TRUE);
}
int nIndex = 0;
int nWordCount = 1;
while(nIndex < _ptlLastText->m_nLen)
{
if (_ptlLastText->m_ptrText[nIndex] == ' ')
{
nWordCount++;
if (nWordCount == nNum)
{
nIndex++;
if (nIndex == _ptlLastText->m_nLen)
{
strResult = "-1";
return(TRUE);
}
strResult.Format("%d",_ptlLastText->m_ptrAttr[nIndex]);
return(TRUE);
}
}
nIndex++;
}
strResult = "-1";
return(TRUE);
}
BOOL WordCount(CString &strParams, CString &strResult)
{
int nIndex;
int nLen;
int nWordCount;
ReplaceVariables(strParams);
if (strParams.IsEmpty())
{
strResult = "0";
return(TRUE);
}
nIndex = 0;
nWordCount = 0;
nLen = strParams.GetLength();
// Eat up leading spaces.
while(strParams.GetAt(nIndex) == ' ' && nIndex < nLen)
nIndex++;
while(nIndex < nLen)
{
nWordCount++;
// Each up all of the word.
while(nIndex < nLen && strParams.GetAt(nIndex) != ' ')
nIndex++;
if (nIndex == nLen)
break;
// Eat up spaces again.
while(nIndex < nLen && strParams.GetAt(nIndex) == ' ')
nIndex++;
}
strResult.Format("%d",nWordCount);
return(TRUE);
}
BOOL Year(CString &strParams, CString &strResult)
{
CTime tNow = CTime::GetCurrentTime();
strResult.Format("%d",tNow.GetYear());
return(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -