Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Inconsistent line counts from 3 methods Date: Wed, 14 Oct 2020 17:25:44 -0700 Organization: None to speak of Lines: 65 Message-ID: <87mu0o49o7.fsf@nosuchdomain.example.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="d0cf0064d9823db556af694dd8f9ef78"; logging-data="18901"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19asjeCBG4EiWIBVR/tvp7c" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:v1voakR4F0GMxJmJvaQ9PO4vTJ8= sha1:5cwlTuWNMzH827iFXHXASkZdK/c= Xref: csiph.com comp.lang.c:155672 Eli the Bearded <*@eli.users.panix.com> writes: > In comp.lang.c, James Kuyper wrote: >> On 10/14/20 4:08 PM, Jorgen Grahn wrote: >>> On Sun, 2020-10-11, James Kuyper wrote: >>>> As a result, if you do put one in, you'll often end >>>> up with two newlines at the end of the file. >>> /That/ is something I have never seen. Which tools do that? Sounds >>> like a bug to me -- and one that's easily fixed. > > As I read the exchange there I imagined James describing an editor > that adds and extra blank line to all files without one. But the demo > here shows something slightly different: > >> I opened a new file with vi, and hit the following keys: >> >> i 1 Enter Esc : x >> >> Here's what I see in the resulting file: >> >> ~(48) od -a linetest >> 0000000 1 nl nl >> 0000003 > > This seems like a misdescription of what the old Unix standard editors > do. For better or worse, ed, vi, and (I think) emacs all treat a new > empty file as being just a new line. What you did is add a second line > there (that "Enter") and so you now have a two line file. The editor > (vi) doesn't let you explicitly modify the final newline. It just _is_. If I open a new file with vim and save it without entering anything, I get an empty file, which is a valid text file with 0 lines. If I do the same thing with busybox vi, I get a file with a single newline, which seems wrong. As for the behavior James observed, if I type i 1 Esc I get a '1' character followed by a single newline, because vim assumes that I meant to have a newline-terminated line. If I type i 1 Enter Esc I get a '1' character followed by two newlines -- i.e., a 2-line text file whose second line is empty. vim has options to handle non-empty files without a trailing newline, but it doesn't make it easy to create them. (It may have an option to do so, but I haven't bothered to find it.) > With vim, you can disable the implicit final newline with > "set nofixendofline", but there are Unix tools that might not like such > files. As one example, I seem to recall no final newline causing a final > "line" to be silently discarded in /etc/sudoers (and files included by > that). > > Elijah > ------ > though sudoers syntax is a right mess from beginning to end -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */