diff --git a/usr.bin/soelim/soelim.c b/usr.bin/soelim/soelim.c index 700ae576e227..de6911f3c83c 100644 --- a/usr.bin/soelim/soelim.c +++ b/usr.bin/soelim/soelim.c @@ -108,11 +108,12 @@ soelim_file(FILE *f, int flag) while (isspace(*walk)) walk++; - cp = walk + strlen(walk) - 1; - while (cp > walk && isspace(*cp)) { - *cp = 0; - cp--; - } + cp = walk; + while (*cp != '\0' && !isspace(*cp)) + cp++; + *cp = 0; + if (cp < line + linelen) + cp++; if (*walk == '\0') { printf("%s", line); @@ -122,6 +123,8 @@ soelim_file(FILE *f, int flag) free(line); return (1); } + if (*cp != '\0') + printf("%s", cp); } free(line); diff --git a/usr.bin/soelim/tests/Makefile b/usr.bin/soelim/tests/Makefile index 604e2f46c9f4..4d787cfadc35 100644 --- a/usr.bin/soelim/tests/Makefile +++ b/usr.bin/soelim/tests/Makefile @@ -7,7 +7,9 @@ ATF_TESTS_SH= soelim FILES= nonexisting.in \ basic.in \ basic \ - basic.out + basic.out \ + basic-with-space.in \ + basic-with-space.out FILESDIR= ${TESTSDIR} .include diff --git a/usr.bin/soelim/tests/basic-with-space.in b/usr.bin/soelim/tests/basic-with-space.in new file mode 100644 index 000000000000..971d681f6fa2 --- /dev/null +++ b/usr.bin/soelim/tests/basic-with-space.in @@ -0,0 +1,3 @@ +This is a test +.so basic something +end diff --git a/usr.bin/soelim/tests/basic-with-space.out b/usr.bin/soelim/tests/basic-with-space.out new file mode 100644 index 000000000000..290b2c6e0543 --- /dev/null +++ b/usr.bin/soelim/tests/basic-with-space.out @@ -0,0 +1,4 @@ +This is a test +basic has been included +something +end diff --git a/usr.bin/soelim/tests/soelim.sh b/usr.bin/soelim/tests/soelim.sh index ea46618b5578..69c92e4bab38 100755 --- a/usr.bin/soelim/tests/soelim.sh +++ b/usr.bin/soelim/tests/soelim.sh @@ -87,6 +87,13 @@ files_body() -e empty \ -s exit:0 \ soelim -I$(atf_get_srcdir) $(atf_get_srcdir)/basic.in + + atf_check \ + -o file:$(atf_get_srcdir)/basic-with-space.out \ + -e empty \ + -s exit:0 \ + soelim -I$(atf_get_srcdir) $(atf_get_srcdir)/basic-with-space.in + } atf_init_test_cases()