From: joeyh Date: Fri, 3 Mar 2006 22:26:20 +0000 (+0000) Subject: * Switch sponge to a C implementation by mithandir. X-Git-Tag: 0.3~2 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8e27a6d4d287995a554f27605e912be38d0a75b;p=moreutils * Switch sponge to a C implementation by mithandir. * Build dep on docbook-xml. --- diff --git a/Makefile b/Makefile index cf5c6b1..dddb950 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -BINS=isutf8 -PERLSCRIPTS=sponge vidir vipe ts -MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 +BINS=isutf8 sponge +PERLSCRIPTS=vidir vipe ts +MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 sponge.1 CFLAGS=-O2 -g -Wall all: $(BINS) $(MANS) @@ -22,5 +22,8 @@ check: isutf8 isutf8.1: isutf8.docbook docbook2x-man isutf8.docbook +sponge.1: sponge.docbook + docbook2x-man sponge.docbook + %.1: % pod2man --center=" " --release="moreutils" $< > $@; diff --git a/debian/changelog b/debian/changelog index b6a1039..a4c701e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +moreutils (0.3) UNRELEASED; urgency=low + + * Switch sponge to a C implementation by mithandir. + + -- Joey Hess Fri, 3 Mar 2006 17:10:43 -0500 + +moreutils (0.2) unstable; urgency=low + + * Build dep on docbook-xml. + + -- Joey Hess Sun, 19 Feb 2006 18:40:56 -0500 + moreutils (0.1) unstable; urgency=low * First release. diff --git a/debian/control b/debian/control index a8e93f3..4685379 100644 --- a/debian/control +++ b/debian/control @@ -1,7 +1,7 @@ Source: moreutils Section: utils Priority: optional -Build-Depends: debhelper (>= 4), dpkg-dev (>= 1.9.0), docbook2x +Build-Depends: debhelper (>= 4), dpkg-dev (>= 1.9.0), docbook2x, docbook-xml Maintainer: Joey Hess Standards-Version: 3.6.2 diff --git a/debian/copyright b/debian/copyright index 9d7c710..5814b0d 100644 --- a/debian/copyright +++ b/debian/copyright @@ -6,26 +6,21 @@ the GPL. sponge: -# Copyright (C) 2003 Colin Watson . -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation files -# (the "Software"), to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, merge, -# publish, distribute, sublicense, and/or sell copies of the Software, -# and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * Copyright © 2006 Tollef Fog Heen + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA Everything else is copyright 2006 by Joey Hess, under the terms of GPL. The full text of the GNU GPL can be found in /usr/share/common-licenses/GPL diff --git a/sponge b/sponge deleted file mode 100755 index 324970b..0000000 --- a/sponge +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/perl - -=head1 NAME - -sponge - soak up standard input and write to a file - -=head1 SYNOPSIS - -sed '...' file | grep '...' | sponge file - -=head1 DESCRIPTION - -sponge reads standard input and writes it out to the specified file. -Unlike a shell redirect, sponge soaks up all its input before opening the -output file. This allows for constructing pipelines that read from and write -to the same file. - -=head1 AUTHOR - -Colin Watson - -=cut - -use warnings; -use strict; - -# Copyright (C) 2003 Colin Watson . -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation files -# (the "Software"), to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, merge, -# publish, distribute, sublicense, and/or sell copies of the Software, -# and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -my $file=shift || die "usage: sponge file\n"; -binmode STDIN; -undef $/; -my $input = ; -open OUT, ">$file" or die "couldn't open $file: $!"; -print OUT $input or die "couldn't write to $file: $!"; -close OUT or die "couldn't close $file: $!"; diff --git a/sponge.c b/sponge.c new file mode 100644 index 0000000..db5e04e --- /dev/null +++ b/sponge.c @@ -0,0 +1,91 @@ +/* + * sponge.c - read in all available info from stdin, then output it to + * file named on the command line + * + * Copyright © 2006 Tollef Fog Heen + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +void usage() { + printf("sponge : suck in all input from stdin and write it to "); + exit(0); +} + +int main(int argc, char **argv) { + char *buf, *bufstart; + size_t bufsize = 8192; + size_t bufused = 0; + ssize_t i = 0; + int outfd; + if (argc != 2) { + usage(); + } + + bufstart = buf = malloc(bufsize); + if (!buf) { + perror("malloc"); + exit(1); + } + + while ((i = read(0, buf, bufsize - bufused)) > 0) { + bufused = bufused+i; + if (bufused == bufsize) { + bufsize *= 2; + bufstart = realloc(bufstart, bufsize); + if (!bufstart) { + perror("realloc"); + exit(1); + } + + buf = bufstart + bufused; + } + } + if (i == -1) { + perror("read"); + exit(1); + } + + outfd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, + 0666); + if (outfd == -1) { + fprintf(stderr, "Can't open %s: %s\n", argv[1], strerror(errno)); + exit(1); + } + + i = write(outfd, bufstart, bufused); + if (i == -1) { + perror("write"); + exit(1); + } + + i = close(outfd); + if (i == -1) { + perror("close"); + exit(1); + } + + return 0; +} diff --git a/sponge.docbook b/sponge.docbook new file mode 100644 index 0000000..39bf77e --- /dev/null +++ b/sponge.docbook @@ -0,0 +1,64 @@ + + + + + + + + + + + Joey + Hess + + 2006-02-19 + + + + sponge + 1 + + + + sponge + soak up standard input and write to a file + + + + + sed '...' file | grep '...' | sponge file + + + + + DESCRIPTION + + sponge reads standard input and writes it + out to the specified file. Unlike a shell redirect, sponge soaks up + all its input before opening the output file. This allows for + constructing pipelines that read from and write to the same file. + + + + +