MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / ToText

Method ToText

source/script.cpp:12392–12447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12390
12391
12392LPTSTR Line::ToText(LPTSTR aBuf, int aBufSize, bool aCRLF, DWORD aElapsed, bool aLineWasResumed, bool aLineNumber) // aBufSize should be an int to preserve negatives from caller (caller relies on this).
12393// aBufSize is an int so that any negative values passed in from caller are not lost.
12394// Caller has ensured that aBuf isn't NULL.
12395// Translates this line into its text equivalent, putting the result into aBuf and
12396// returning the position in aBuf of its new string terminator.
12397{
12398 if (aBufSize < 3)
12399 return aBuf;
12400 else
12401 aBufSize -= (1 + aCRLF); // Reserve one char for LF/CRLF after each line (so that it always get added).
12402
12403 LPTSTR aBuf_orig = aBuf;
12404
12405 if (aLineNumber)
12406 aBuf += sntprintf(aBuf, aBufSize, _T("%03u: "), mLineNumber);
12407 if (aLineWasResumed)
12408 aBuf += sntprintf(aBuf, BUF_SPACE_REMAINING, _T("STILL WAITING (%0.2f): "), (float)aElapsed / 1000.0);
12409
12410 if (mActionType == ACT_CASE)
12411 {
12412 if (mArgc)
12413 aBuf += sntprintf(aBuf, BUF_SPACE_REMAINING, _T("%s %s:"), g_act[mActionType].Name
12414 , mArg[0].text);
12415 else
12416 aBuf += sntprintf(aBuf, BUF_SPACE_REMAINING, _T("Default:"));
12417 }
12418 else
12419 {
12420 int i = 0;
12421 if (mActionType == ACT_ASSIGNEXPR)
12422 aBuf += sntprintf(aBuf, BUF_SPACE_REMAINING, _T("%s := "), mArg[i++].text);
12423 else if (mActionType != ACT_EXPRESSION)
12424 aBuf += sntprintf(aBuf, BUF_SPACE_REMAINING, _T("%s"), g_act[mActionType].Name);
12425 for (; i < mArgc; ++i)
12426 {
12427 bool quote = mArg[i].type == ARG_TYPE_NORMAL
12428 && !mArg[i].is_expression && mArg[i].postfix && mArg[i].postfix->symbol == SYM_STRING;
12429 LPCTSTR delim = mActionType <= ACT_EXPRESSION ? _T("") : i == 0 ? _T(" ")
12430 : (i + 1 == mArgc && mActionType == ACT_FOR) ? _T(" in ")
12431 : _T(", ");
12432 // This method is a little more efficient than using snprintfcat().
12433 aBuf += sntprintf(aBuf, BUF_SPACE_REMAINING, quote ? _T("%s\"%s\"") : _T("%s%s"), delim, mArg[i].text);
12434 }
12435 }
12436 if (aElapsed && !aLineWasResumed)
12437 aBuf += sntprintf(aBuf, BUF_SPACE_REMAINING, _T(" (%0.2f)"), (float)aElapsed / 1000.0);
12438 // UPDATE for v1.0.25: It seems that MessageBox(), which is the only way these lines are currently
12439 // displayed, prefers \n over \r\n because otherwise, Ctrl-C on the MsgBox copies the lines all
12440 // onto one line rather than formatted nicely as separate lines.
12441 // Room for LF or CRLF was reserved at the top of this function:
12442 if (aCRLF)
12443 *aBuf++ = '\r';
12444 *aBuf++ = '\n';
12445 *aBuf = '\0';
12446 return aBuf;
12447}
12448
12449

Callers 3

LogToTextMethod · 0.45
VicinityToTextMethod · 0.45
ListVarsHelperFunction · 0.45

Calls 1

sntprintfFunction · 0.85

Tested by

no test coverage detected