| 12234 | |
| 12235 | |
| 12236 | LPTSTR Line::LogToText(LPTSTR aBuf, int aBufSize) // aBufSize should be an int to preserve negatives from caller (caller relies on this). |
| 12237 | // aBufSize is an int so that any negative values passed in from caller are not lost. |
| 12238 | // Translates sLog into its text equivalent, putting the result into aBuf and |
| 12239 | // returning the position in aBuf of its new string terminator. |
| 12240 | // Caller has ensured that aBuf is non-NULL and that aBufSize is reasonable (at least 256). |
| 12241 | { |
| 12242 | LPTSTR aBuf_orig = aBuf; |
| 12243 | |
| 12244 | // Store the position of where each retry done by the outer loop will start writing: |
| 12245 | LPTSTR aBuf_log_start = aBuf + sntprintf(aBuf, aBufSize, _T("Script lines most recently executed (oldest first).") |
| 12246 | _T(" Press [F5] to refresh. The seconds elapsed between a line and the one after it is in parentheses to") |
| 12247 | _T(" the right (if not 0). The bottommost line's elapsed time is the number of seconds since it executed.\r\n\r\n")); |
| 12248 | |
| 12249 | int i, lines_to_show, line_index, line_index2, space_remaining; // space_remaining must be an int to detect negatives. |
| 12250 | #ifndef AUTOHOTKEYSC |
| 12251 | int last_file_index = -1; |
| 12252 | #endif |
| 12253 | DWORD elapsed; |
| 12254 | bool this_item_is_special, next_item_is_special; |
| 12255 | |
| 12256 | // In the below, sLogNext causes it to start at the oldest logged line and continue up through the newest: |
| 12257 | for (lines_to_show = LINE_LOG_SIZE, line_index = sLogNext;;) // Retry with fewer lines in case the first attempt doesn't fit in the buffer. |
| 12258 | { |
| 12259 | aBuf = aBuf_log_start; // Reset target position in buffer to the place where log should begin. |
| 12260 | for (next_item_is_special = false, i = 0; i < lines_to_show; ++i, ++line_index) |
| 12261 | { |
| 12262 | if (line_index >= LINE_LOG_SIZE) // wrap around, because sLog is a circular queue |
| 12263 | line_index -= LINE_LOG_SIZE; // Don't just reset it to zero because an offset larger than one may have been added to it. |
| 12264 | if (!sLog[line_index]) // No line has yet been logged in this slot. |
| 12265 | continue; // ACT_LISTLINES and other things might rely on "continue" instead of halting the loop here. |
| 12266 | this_item_is_special = next_item_is_special; |
| 12267 | next_item_is_special = false; // Set default. |
| 12268 | if (i + 1 < lines_to_show) // There are still more lines to be processed |
| 12269 | { |
| 12270 | if (this_item_is_special) // And we know from the above that this special line is not the last line. |
| 12271 | // Due to the fact that these special lines are usually only useful when they appear at the |
| 12272 | // very end of the log, omit them from the log-display when they're not the last line. |
| 12273 | // In the case of a high-frequency SetTimer, this greatly reduces the log clutter that |
| 12274 | // would otherwise occur: |
| 12275 | continue; |
| 12276 | |
| 12277 | // Since above didn't continue, this item isn't special, so display it normally. |
| 12278 | elapsed = sLogTick[line_index + 1 >= LINE_LOG_SIZE ? 0 : line_index + 1] - sLogTick[line_index]; |
| 12279 | if (elapsed > INT_MAX) // INT_MAX is about one-half of DWORD's capacity. |
| 12280 | { |
| 12281 | // v1.0.30.02: Assume that huge values (greater than 24 days or so) were caused by |
| 12282 | // the new policy of storing WinWait/RunWait/etc.'s line in the buffer whenever |
| 12283 | // it was interrupted and later resumed by a thread. In other words, there are now |
| 12284 | // extra lines in the buffer which are considered "special" because they don't indicate |
| 12285 | // a line that actually executed, but rather one that is still executing (waiting). |
| 12286 | next_item_is_special = true; // Override the default. |
| 12287 | if (i + 2 == lines_to_show) // The line after this one is not only special, but the last one that will be shown, so recalculate this one correctly. |
| 12288 | elapsed = GetTickCount() - sLogTick[line_index]; |
| 12289 | else // Neither this line nor the special one that follows it is the last. |
| 12290 | { |
| 12291 | // Refer to the line after the next (special) line to get this line's correct elapsed time. |
| 12292 | line_index2 = line_index + 2; |
| 12293 | if (line_index2 >= LINE_LOG_SIZE) |