by boomlinde · 1mo ago · 0 comments
For one, there are a few different ways to terminate lines. All major operating systems now tend to use just \n, but I have older files that use \r\n (Microsoft), \r (Macintosh) or \n\r (RiscOS).
There are also different opinions on how text files end in different operating systems. In POSIX, all lines are terminated by \n, even the last one. Microsoft software still tends to insist that the last line of a file is special case that doesn't need to be terminated even now that they have otherwise adopted POSIX style line endings. In Microsoft's view, it seems that the line ending sequence separates lines rather than terminate them. Files created according to this view don't play well with tools like cat(1) if your intent is to concatenate the lines of two files, but it seems other Unix clone tools have adapted to the possibility that the last line isn't terminated properly.
Finally there's the encoding problem. I don't know of a good tool that determines the original encoding based on heuristics and re-encodes to UTF-8 but if someone does I'd love to know. If I know that the input language is English for example it shouldn't be too hard to determine what encoding the funny byte used in contractions or the funny bytes used in quotes belong to. Still, in English most of the files that use 8-bit encodings remain quite readable if you just box out the invalid bytes.
\r\n was how lines were terminated on the wire for many early devices (for example, the Teletype ASR-33 seen in the famous photograph of Thompson and Ritchie at Bell Labs).
If the carriage is very far to the right, and an LF is sent followed by the CR, then the carriage will still be returning when the next character arrives, which will print at some random location along the return path.
CR followed by the mechanically much faster LF operation gives enough time for the carriage to be fully homed and in proper position for the printable character to be struck.
I wondered what the thought process was at Acorn when they decided on the opposite. It looks like they did this on their 8-bit micros as well. I found this explanation: https://retrocomputing.stackexchange.com/questions/29929/why...
I've only looked briefly but it seems there is a snippet of code in the ASCII output routine that expands just CR to LF+CR which is shorter when the bytes are output in that order. If they did CR first and fell through to the output routine for LF it would clobber the A register and you'd need additional code to restore it after outputting it with OSWRCH, which would also preven the fallthrough. So it saves five bytes three bytes of ROM :)
Still leaves out why they didn't expand LF to CR+LF, but I suppose the specific order was a non-consideration at the time.
0x0 0x0 0x0 0x0 0x2 0x0 0x0 0x0 0x0 0x7 0x1 0x1 0x0 0x0 0x0 0x0 0x3 0x1 0x2
and try to figure out what that is all about.
This is specifically an area that "text" is quite bad and is the source of much woe. Your provided example would be parsed by most parsers today as a string, since it mixes spaces (non-numeric) and surrounds it with quotes.
In fact, given well-defined binary, it is rather simpler to turn it into "text" than the reverse. It seems like you've forgotten that "0x32 0x20 0x37 0x20 0x2A..." is literally what is in that file you would view. Plain text is, after all, just one example of a binary format.
I agree that the string "no" is ambiguous (though infamous as a somewhat pathological case), but at least it can be seen in context without having to spelunk a binary definition.
is_bright_and_shiny: "no"
vs
curt_negative_response: "no"
vs
country_code: "no"
Granted, I knew that all files are UTF-8, so I didn't need to have it "guess" what the encoding was without the BOM.
Same thing for \ and / in path separators: Microsoft never made a consistent push for it, and it depends on the application.