Parse filename until first space then print the rest of the line after file

inclusion

This is the same behaviour of heirloom's soelim
This commit is contained in:
Baptiste Daroussin 2015-05-04 18:20:31 +00:00
parent 28315e27a7
commit 2b30fb2639
5 changed files with 25 additions and 6 deletions

View File

@ -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 = walk;
while (*cp != '\0' && !isspace(*cp))
cp++;
*cp = 0;
cp--;
}
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);

View File

@ -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 <bsd.test.mk>

View File

@ -0,0 +1,3 @@
This is a test
.so basic something
end

View File

@ -0,0 +1,4 @@
This is a test
basic has been included
something
end

View File

@ -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()