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

Method VicinityToText

source/script.cpp:12339–12388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12337
12338
12339LPTSTR Line::VicinityToText(LPTSTR aBuf, int aBufSize) // aBufSize should be an int to preserve negatives from caller (caller relies on this).
12340// aBufSize is an int so that any negative values passed in from caller are not lost.
12341// Caller has ensured that aBuf isn't NULL.
12342// Translates the current line and the lines above and below it into their text equivalent
12343// putting the result into aBuf and returning the position in aBuf of its new string terminator.
12344{
12345 LPTSTR aBuf_orig = aBuf;
12346
12347 #define LINES_ABOVE_AND_BELOW 7
12348
12349 // Determine the correct value for line_start and line_end:
12350 int i;
12351 Line *line_start, *line_end;
12352 for (i = 0, line_start = this
12353 ; i < LINES_ABOVE_AND_BELOW && line_start->mPrevLine != NULL
12354 ; ++i, line_start = line_start->mPrevLine);
12355
12356 for (i = 0, line_end = this
12357 ; i < LINES_ABOVE_AND_BELOW && line_end->mNextLine != NULL
12358 ; ++i, line_end = line_end->mNextLine);
12359
12360 if (!g_AllowMainWindow) // Override the above to show only a single line, to conceal the script's source code.
12361 {
12362 line_start = this;
12363 line_end = this;
12364 }
12365
12366 // Now line_start and line_end are the first and last lines of the range
12367 // we want to convert to text, and they're non-NULL.
12368 aBuf += sntprintf(aBuf, BUF_SPACE_REMAINING, _T("\tLine#\n"));
12369
12370 int space_remaining; // Must be an int to preserve any negative results.
12371
12372 // Start at the oldest and continue up through the newest:
12373 for (Line *line = line_start;;)
12374 {
12375 if (line == this)
12376 tcslcpy(aBuf, _T("--->\t"), BUF_SPACE_REMAINING);
12377 else
12378 tcslcpy(aBuf, _T("\t"), BUF_SPACE_REMAINING);
12379 aBuf += _tcslen(aBuf);
12380 space_remaining = BUF_SPACE_REMAINING; // Resolve macro only once for performance.
12381 // Truncate large lines so that the dialog is more readable:
12382 aBuf = line->ToText(aBuf, space_remaining < 500 ? space_remaining : 500, false);
12383 if (line == line_end)
12384 break;
12385 line = line->mNextLine;
12386 }
12387 return aBuf;
12388}
12389
12390
12391

Callers 1

FormatErrorMethod · 0.80

Calls 2

sntprintfFunction · 0.85
ToTextMethod · 0.45

Tested by

no test coverage detected