Products > Programming

Comparing source files

<< < (7/7)

Fixed  :-+

--- Quote from: Nominal Animal on March 30, 2024, 09:03:40 pm ---LF CR ("\n\r"): An error, but invisible on most systems, behaving like a normal newline, and is thus occasionally encountered in the wild.  Can also occur in Unix/BSD/Linux/etc. systems when using tty devices (terminals, serial ports) with termios INLCR and ICRNL set on input with the other side using CR LF newlines.

--- End quote ---

umm, speaking of being invisible, I never noticed it on the DEC VT525(1994) hardware terminal with /usr/bin/screen on /dev/ttyS0
it shouldn't have worked  :-//

Nominal Animal:
LFCR "\n\r" works on Unix, BSD/Linux/etc., and VT terminals because while LF "\n" is a full newline, CR "\r" only returns the cursor to the beginning of the current line.  Thus, the effect of LF CR "\n\r" is exactly the same as LF "\n" only.  Invisible, like I said!

This is often exploited by POSIXy command-line programs that report progress using e.g.
    fprintf(stderr, "\r%.2f%% done", 100.0*i/n);
    fflush(stderr);  // Optional; normally/by default, this is not needed
followed by
    fprintf(stderr, "\r                   \r"); // or "\r\022[K"
    fflush(stderr);  // Optional; normally/by default, this is not needed
where "\033[K" (or "\e[K" where \e represents ASCII/ISO Latin/UTF-8 code 27 = 0x1B = ESC) is the ANSI Control Sequence for clearing the current line from the current cursor position to the end of the line without moving the cursor, when the maximum number of characters needed to "erase" the progress output is unknown.

If the progress is reported to standard output, or there is more information printed to standard error that may have been redirected to a file, often the followup is just a simple fprintf(stderr, "\n"); or fprintf(stderr, "\rCompleted.     \n");, as that way the progress information will look like a single line in the file, but won't otherwise mess up the output.

Araxis Merge. They are in this business was for a long time, and for a reason.


[0] Message Index

[*] Previous page

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod