Revert "wc: Count last line even if it doesn't end in newline"

This reverts commit f356c4ab91.

According to Dr. POSIX, `wc -l` should print the number of *newlines*
in the input.
This commit is contained in:
Andreas Kling 2021-10-31 16:24:11 +01:00
parent aff2b42f82
commit 472401a51e
Notes: sideshowbarker 2024-07-18 01:39:54 +09:00

View File

@ -55,9 +55,7 @@ static Count get_count(const String& file_specifier)
}
bool start_a_new_word = true;
int last_ch = EOF;
for (int ch = fgetc(file_pointer); ch != EOF; ch = fgetc(file_pointer)) {
last_ch = ch;
count.bytes++;
if (isspace(ch)) {
start_a_new_word = true;
@ -68,8 +66,6 @@ static Count get_count(const String& file_specifier)
count.words++;
}
}
if (last_ch != '\n')
count.lines++;
if (file_pointer != stdin)
fclose(file_pointer);