diff options
author | joeyh <joeyh> | 2006-03-03 22:26:20 +0000 |
---|---|---|
committer | joeyh <joeyh> | 2006-03-03 22:26:20 +0000 |
commit | d8e27a6d4d287995a554f27605e912be38d0a75b (patch) | |
tree | 2f53a3af8babc5c1543736608c463cb35cd5cffc | |
parent | ee3eecafa0cc1a4efa0503117144205bedbdf6a1 (diff) | |
download | moreutils-d8e27a6d4d287995a554f27605e912be38d0a75b.tar.gz |
* Switch sponge to a C implementation by mithandir.
* Build dep on docbook-xml.
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | debian/changelog | 12 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | debian/copyright | 35 | ||||
-rwxr-xr-x | sponge | 54 | ||||
-rw-r--r-- | sponge.c | 91 | ||||
-rw-r--r-- | sponge.docbook | 64 |
7 files changed, 189 insertions, 78 deletions
@@ -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 <joeyh@debian.org> Fri, 3 Mar 2006 17:10:43 -0500 + +moreutils (0.2) unstable; urgency=low + + * Build dep on docbook-xml. + + -- Joey Hess <joeyh@debian.org> 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 <joeyh@debian.org> 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 <cjwatson@debian.org>. -# -# 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 @@ -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 <cjwatson@debian.org> - -=cut - -use warnings; -use strict; - -# Copyright (C) 2003 Colin Watson <cjwatson@debian.org>. -# -# 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 = <STDIN>; -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 <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> + +void usage() { + printf("sponge <file>: suck in all input from stdin and write it to <file>"); + 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 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- + +Copyright © 2006 Joey Hess + +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 + +--> + +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.4//EN" +"file:///usr/share/xml/docbook/schema/dtd/4.4/docbookx.dtd" +[]> + +<refentry> + + <refentryinfo> + <author> + <firstname>Joey</firstname> + <surname>Hess</surname> + </author> + <date>2006-02-19</date> + </refentryinfo> + + <refmeta> + <refentrytitle>sponge</refentrytitle> + <manvolnum>1</manvolnum> + </refmeta> + + <refnamediv> + <refname>sponge</refname> + <refpurpose>soak up standard input and write to a file</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <cmdsynopsis> + <command>sed '...' file | grep '...' | sponge file</command> + </cmdsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>DESCRIPTION</title> + + <para><command>sponge</command> 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. + </para> + + </refsect1> + +</refentry> |