summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoeyh <joeyh>2006-04-02 22:32:24 +0000
committerjoeyh <joeyh>2006-04-02 22:32:24 +0000
commit830a7b56d7c03e6819e2ccdd65b5015a2606ebd1 (patch)
treebc3f9289a4a439c666b99d34ef2dd98259b64958
parent64f0d162b040d66fd21c4ec8c7b5e9792866febc (diff)
downloadmoreutils-830a7b56d7c03e6819e2ccdd65b5015a2606ebd1.tar.gz
* ifdata: patch from Adam Lackorzynski to translate French error messages
to English and to convert some #defines to enums. * ifdata: patch from Adam Lackorzynski to avoid printing info for bogus interface. Closes: #360433 * Add zrun, contributed by Chung-chieh Shan (you might prefer to alias it to "z").
-rw-r--r--Makefile4
-rw-r--r--README9
-rw-r--r--debian/changelog11
-rw-r--r--debian/control1
-rw-r--r--debian/copyright3
-rwxr-xr-xdebian/rules4
-rw-r--r--ifdata.c130
-rwxr-xr-xzrun82
8 files changed, 163 insertions, 81 deletions
diff --git a/Makefile b/Makefile
index ffed4b9..e8d92ee 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
BINS=isutf8 ifdata pee sponge
-PERLSCRIPTS=vidir vipe ts combine
-MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 pee.1
+PERLSCRIPTS=vidir vipe ts combine zrun
+MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 pee.1 zrun.1
CFLAGS=-O2 -g -Wall
all: $(BINS) $(MANS)
diff --git a/README b/README
index 1f6c287..6cd29f3 100644
--- a/README
+++ b/README
@@ -17,7 +17,8 @@ ifdata
get network interface info without parsing ifconfig output
pee
tee standard input to pipes
-
+zrun
+ automatically uncompress arguments to command
Your suggestions of additional tools to add to this collection are
apprecitated. Here are some that are under consideration but have not yet
@@ -29,12 +30,6 @@ mime
(More useful than file(1) in many cases but would add a lot of
gnome libraries to the package's dependency chain.)
-z
- makes another program understand compressed files
- ex: z zxgv file.bmp.gz
-
- (Dare I take the "z" name?)
-
tmp
puts stdin into a temp file and passes it to the specified program
ex: zcat file.bmp.gz | tmp zxgv
diff --git a/debian/changelog b/debian/changelog
index 3470b9c..df19875 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,14 @@
+moreutils (0.10) UNRELEASED; urgency=low
+
+ * ifdata: patch from Adam Lackorzynski to translate French error messages
+ to English and to convert some #defines to enums.
+ * ifdata: patch from Adam Lackorzynski to avoid printing info for
+ bogus interface. Closes: #360433
+ * Add zrun, contributed by Chung-chieh Shan (you might prefer to alias it to
+ "z").
+
+ -- Joey Hess <joeyh@debian.org> Sun, 2 Apr 2006 16:15:35 -0400
+
moreutils (0.9) unstable; urgency=low
* ifdata: robustness patch from Adam Lackorzynski, in particular deal with
diff --git a/debian/control b/debian/control
index 176a10e..2b2dde0 100644
--- a/debian/control
+++ b/debian/control
@@ -21,3 +21,4 @@ Description: additional unix utilities
- combine: combine the lines in two files using boolean operations
- ifdata: get network interface info without parsing ifconfig output
- pee: tee standard input to pipes
+ - zrun: automatically uncompress arguments to command
diff --git a/debian/copyright b/debian/copyright
index 53ecc6c..b53bfaf 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -13,6 +13,9 @@ http://edgard.dyn.fdn.fr/developpements/ifcfg.shtml
pee is Copyright (c) Miek Gieben, 2006, under the terms of the GPL.
+zrun is Copyright (c) Chung-chieh Shan, under the terms of the GPL, version
+2 or later.
+
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
on Debian systems.
diff --git a/debian/rules b/debian/rules
index 1c0a9b7..10f0e79 100755
--- a/debian/rules
+++ b/debian/rules
@@ -34,5 +34,9 @@ binary-arch: build
dh_md5sums
dh_builddeb
+# Not intended for use by anyone except the author.
+announcedir:
+ @echo ${HOME}/src/joeywiki/code/moreutils/news
+
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary
diff --git a/ifdata.c b/ifdata.c
index c9a4622..b81424c 100644
--- a/ifdata.c
+++ b/ifdata.c
@@ -12,36 +12,37 @@
#include <string.h>
#include <unistd.h>
#include <ctype.h>
-//#include <linux/socket.h>
-#define DO_EXISTS 1
-#define DO_PEXISTS 2
-#define DO_PADDRESS 3
-#define DO_PMASK 4
-#define DO_PMTU 5
-#define DO_PCAST 6
-#define DO_PALL 7
-#define DO_PFLAGS 8
-#define DO_SINPACKETS 9
-#define DO_SINBYTES 10
-#define DO_SINERRORS 11
-#define DO_SINDROPS 12
-#define DO_SINALL 13
-#define DO_SINFIFO 14
-#define DO_SINFRAME 15
-#define DO_SINCOMPRESSES 16
-#define DO_SINMULTICAST 17
-#define DO_SOUTALL 18
-#define DO_SOUTBYTES 19
-#define DO_SOUTPACKETS 20
-#define DO_SOUTERRORS 21
-#define DO_SOUTDROPS 22
-#define DO_SOUTFIFO 23
-#define DO_SOUTCOLLS 24
-#define DO_SOUTCARRIER 25
-#define DO_SOUTMULTICAST 26
-#define DO_PNETWORK 27
-#define DO_PHWADDRESS 28
+enum {
+ DO_EXISTS = 1,
+ DO_PEXISTS,
+ DO_PADDRESS,
+ DO_PMASK,
+ DO_PMTU,
+ DO_PCAST,
+ DO_PALL,
+ DO_PFLAGS,
+ DO_SINPACKETS,
+ DO_SINBYTES,
+ DO_SINERRORS,
+ DO_SINDROPS,
+ DO_SINALL,
+ DO_SINFIFO,
+ DO_SINFRAME,
+ DO_SINCOMPRESSES,
+ DO_SINMULTICAST,
+ DO_SOUTALL,
+ DO_SOUTBYTES,
+ DO_SOUTPACKETS,
+ DO_SOUTERRORS,
+ DO_SOUTDROPS,
+ DO_SOUTFIFO,
+ DO_SOUTCOLLS,
+ DO_SOUTCARRIER,
+ DO_SOUTMULTICAST,
+ DO_PNETWORK,
+ DO_PHWADDRESS,
+};
struct if_stat {
unsigned long long int in_packets;
@@ -152,9 +153,7 @@ void if_hwaddr(char *iface) {
PREPARE_SOCK(iface);
CALL_IOCTL(SIOCGIFHWADDR);
- if (res < 0) {
- CALL_ERROR();
- }
+ CALL_ERROR(return);
hwaddr = (unsigned char *)req.ifr_hwaddr.sa_data;
printf("%02X:%02X:%02X:%02X:%02X:%02X",
hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
@@ -211,42 +210,29 @@ int if_mtu(char *iface) {
return req.ifr_mtu;
}
-#define START 1
-#define SKIP_LINE 2
-#define START_LINE 3
-#define START_IFNAME 4
-#define IFACE_FOUND 5
-#define RX_BYTES 6
-#define WAIT_RX_PACKETS 7
-#define RX_PACKETS 8
-#define WAIT_RX_ERRORS 9
-#define RX_ERRORS 10
-#define WAIT_RX_DROPS 11
-#define RX_DROPS 12
-#define WAIT_RX_FIFO 13
-#define RX_FIFO 14
-#define WAIT_RX_FRAME 15
-#define RX_FRAME 16
-#define WAIT_RX_COMPRESS 17
-#define RX_COMPRESS 18
-#define WAIT_RX_MULTICAST 19
-#define RX_MULTICAST 20
-#define WAIT_TX_BYTES 21
-#define TX_BYTES 22
-#define WAIT_TX_PACKETS 23
-#define TX_PACKETS 24
-#define WAIT_TX_ERRORS 25
-#define TX_ERRORS 26
-#define WAIT_TX_DROPS 27
-#define TX_DROPS 28
-#define WAIT_TX_FIFO 29
-#define TX_FIFO 30
-#define WAIT_TX_COLLS 31
-#define TX_COLLS 32
-#define WAIT_TX_CARRIER 33
-#define TX_CARRIER 34
-#define WAIT_TX_MULTICAST 35
-#define TX_MULTICAST 36
+enum {
+ START = 1,
+ SKIP_LINE,
+ START_LINE,
+ START_IFNAME,
+ IFACE_FOUND,
+ RX_BYTES,
+ WAIT_RX_PACKETS, RX_PACKETS,
+ WAIT_RX_ERRORS, RX_ERRORS,
+ WAIT_RX_DROPS, RX_DROPS,
+ WAIT_RX_FIFO, RX_FIFO,
+ WAIT_RX_FRAME, RX_FRAME,
+ WAIT_RX_COMPRESS, RX_COMPRESS,
+ WAIT_RX_MULTICAST, RX_MULTICAST,
+ WAIT_TX_BYTES, TX_BYTES,
+ WAIT_TX_PACKETS, TX_PACKETS,
+ WAIT_TX_ERRORS, TX_ERRORS,
+ WAIT_TX_DROPS, TX_DROPS,
+ WAIT_TX_FIFO, TX_FIFO,
+ WAIT_TX_COLLS, TX_COLLS,
+ WAIT_TX_CARRIER, TX_CARRIER,
+ WAIT_TX_MULTICAST, TX_MULTICAST,
+};
#define FIRST_DIGIT(val,digit) do {val=digit-'0'; } while(0)
#define NEXT_DIGIT(val,digit) do {val*=10; val+=digit-'0'; } while(0)
@@ -340,7 +326,7 @@ struct if_stat *get_stats(char *iface) {
READ_INT(TX_CARRIER,res->out_carrier,WAIT_TX_MULTICAST);
READ_INT(TX_MULTICAST,res->out_carrier,SKIP_LINE);
default:
- fprintf(stderr,"Mon totomate est po bon!\n");
+ fprintf(stderr,"Internal state machine error!\n");
break;
}
}
@@ -392,7 +378,7 @@ void please_do(int ndo, int *todo, char *ifname) {
struct sockaddr *sadr;
struct if_stat *stats=NULL;
if (!ndo) return;
-// printf("J'ai %d actions a réaliser\n",ndo);
+// printf("I have %d items in my queue.\n",ndo);
for (i=0; i<ndo; i++) {
switch (todo[i]) {
case DO_EXISTS:
@@ -553,7 +539,7 @@ void please_do(int ndo, int *todo, char *ifname) {
stats->out_multicast);
break;
default:
- printf("Je comprends pas ce que je dois faire: %d\n",todo[i]);
+ printf("Unknown command: %d\n",todo[i]);
break;
}
printf("\n");
@@ -649,7 +635,7 @@ int main(int argc, char *argv[]) {
usage(me);
return 1;
}
-// printf("Je travaille sur l'interface %s\n",ifname);
+// printf("Interface %s\n",ifname);
please_do(ndo,todo,ifname);
return 0;
}
diff --git a/zrun b/zrun
new file mode 100755
index 0000000..8e6d159
--- /dev/null
+++ b/zrun
@@ -0,0 +1,82 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+zrun - automatically uncompress arguments to command
+
+=head1 SYNOPSIS
+
+zrun command file.gz [...]
+
+=head1 DESCRIPTION
+
+Prefixing a shell command with "zrun" causes any compressed files that are
+arguments of the command to be transparently uncompressed to temp files
+(not pipes) and the uncompressed files fed to the command.
+
+This is a quick way to run a command that does not itself support
+compressed files, without manually uncompressing the files.
+
+=head1 BUGS
+
+Modifications to the uncompressed temporary file are not fed back into the
+input file, so using this as a quick way to make an editor support
+compressed files won't work.
+
+=head1 AUTHOR
+
+Copyright 2006 by Chung-chieh Shan <ccshan@post.harvard.edu>
+
+=cut
+
+use warnings;
+use strict;
+use IO::Handle;
+use File::Temp qw{tempfile};
+
+my $program = shift;
+
+my @argument;
+my %child;
+foreach my $argument (@ARGV) {
+ if ($argument =~ m{^(.*/)?([^/]*)\.(gz|Z|bz2)$}s) {
+ my $suffix = "-$2";
+ my @preprocess = $3 eq "bz2" ? qw(bzip2 -d -c) : qw(gzip -d -c);
+
+ my ($fh, $tmpname) = tempfile(SUFFIX => $suffix, UNLINK => 1)
+ or die "zrun: cannot create temporary file: $!\n";
+
+ if (my $child = fork) {
+ $child{$child} = $argument;
+ $argument = $tmpname;
+ }
+ elsif (defined $child) {
+ STDOUT->fdopen($fh, "w");
+ exec @preprocess, $argument;
+ }
+ else {
+ die "zrun: cannot fork to handle $argument: $!\n";
+ }
+ }
+ push @argument, $argument;
+}
+
+while (%child and (my $pid = wait) != -1) {
+ if (defined(my $argument = delete $child{$pid})) {
+ if ($? & 255) {
+ die "zrun: preprocessing for $argument terminated abnormally: $?\n";
+ }
+ elsif (my $code = $? >> 8) {
+ die "zrun: preprocessing for $argument terminated with code $code\n";
+ }
+ }
+}
+
+my $status = system $program ($program, @argument);
+if ($status & 255) {
+ die "zrun: $program terminated abnormally: $?\n";
+}
+else {
+ my $code = $? >> 8;
+ exit $code;
+}