Skip to content

Commit

Permalink
Skip empty lines and newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
soveran committed Mar 15, 2018
1 parent 4cc5405 commit 144a659
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions map.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ int main(int argc, char **argv) {
ssize_t llen;

while ((llen = getline(&line, &lcap, stdin)) > 0) {
setenv(argv[1], line, 1);
system(argv[2]);
if (llen > 1) {
if (line[llen-1] == '\n') {
line[llen-1] = '\0';
}

setenv(argv[1], line, 1);
system(argv[2]);
}
}

return 0;
Expand Down
1 change: 1 addition & 0 deletions test/input
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
foo

bar
baz
2 changes: 1 addition & 1 deletion test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ assert_equal () {
}

assert_equal "foofoo" `printf foo | ./map f 'printf $f$f'`
assert_equal "foobarbaz" `cat ./test/input | ./map f 'printf $f'`
assert_equal "foobarbaz" `cat ./test/input | ./map f 'printf "$f"'`

0 comments on commit 144a659

Please sign in to comment.