nicolas / debian.moreutils (public) (License: GPL-2, GPL-2+, Expat, BSD-2-Clause, Public Domain) (since 2018-09-25) (hash sha1)
Debian packaging of joeyh's moreutils
List of commits:
Subject Hash Author Date (UTC)
Added -n option to ifne. 4425bfd45edfc4d2be18ce6d2a2eeb7ab80f7a6c Vicho 2008-05-01 10:17:45
update 8c45ad625cf68e210387a08611f775093c3ea49e Joey Hess 2008-05-10 22:05:05
typo b02ae7c9f2237b4e09bceae4b42ec76f0a458ea0 Joey Hess 2008-05-10 22:05:01
eh, I didn't mean to revert that 57961470b587d8e26202ea15beec018dbd07bc6c Joey Hess 2008-05-10 22:02:55
Revert "debhelper v7; rules file minimisation" 64d494126de003b66293268b3be6556a86ff73e8 Joey Hess 2008-05-10 16:37:48
patch for moreutils Makefile 6824744a68f35eb4615b877267922d50a40a1122 Greg KH 2008-05-10 05:49:30
debhelper v7; rules file minimisation 83e8da32e5d3154f1c97e6eb62c30450ff95b5af Joey Hess 2008-04-26 23:27:12
releasing version 0.29 ab100606238850f43106ea7a3c939833efd25378 Joey Hess 2008-04-15 19:37:21
ts improvements decdf6ec49194e5c02fa42c3a235bdefee224175 Joey Hess 2008-04-13 00:37:28
fix mode of new file renamed from temp file c525af9d17aacb226d72495d1bd401ce001b03f6 Joey Hess 2008-04-11 23:11:33
minor changes b6d635bc28bf7d94201bcd167905cebc48abf7cb Joey Hess 2008-04-11 23:03:50
honor TMPDIR f69844b98d71598fbf9ef3f4da137b16eff1621e Joey Hess 2008-04-11 22:55:10
optimize tempfile copying 6f31909ff74c064ea0b5126219b3e8f7b8826bee Joey Hess 2008-04-11 22:34:34
more fixes to tempfile writeback a580bbd17850753746d6d1a2b65817edaf4485c9 Joey Hess 2008-04-11 22:27:40
set umask before calling mkstemp 0595609018095dabd5d1a56cf03ddcc008a9e928 Joey Hess 2008-04-11 21:47:28
update physmem copyright 30746c4357c0ac6110ca7e2a279ce9e82e879581 Joey Hess 2008-04-11 21:44:19
fix two bugs writing the output file 6fa7d9907e7211f06656b296940aaca1d6b4d1df Joey Hess 2008-04-11 21:42:38
move code into a function dcb580b3998a19b112004f23298490a34af59fc8 Joey Hess 2008-04-11 20:15:29
fix edge cases ee4e74dd6a20706f29ef30a2613a1977f6f325fa Joey Hess 2008-04-11 20:10:18
reorder defines 0bf88ea14cda6e6e57e97356862628ae49269c8a Joey Hess 2008-04-11 19:54:30
Commit 4425bfd45edfc4d2be18ce6d2a2eeb7ab80f7a6c - Added -n option to ifne.
With -n, ifne runs the command if the standard input is empty and does
nothing otherwise.
Author: Vicho
Author date (UTC): 2008-05-01 10:17
Committer name: Joey Hess
Committer date (UTC): 2008-05-12 20:00
Parent(s): 8c45ad625cf68e210387a08611f775093c3ea49e
Signer:
Signing key:
Signing status: N
Tree: 29cb9d6316f6583afa04d4c97e9c0033a4b5885f
File Lines added Lines deleted
ifne.c 40 16
ifne.docbook 25 4
File ifne.c changed (mode: 100644) (index 817b1c5..a7abd21)
22 22 #include <unistd.h> #include <unistd.h>
23 23 #include <sys/wait.h> #include <sys/wait.h>
24 24 #include <sys/types.h> #include <sys/types.h>
25 #include <string.h>
26 #define streq(a, b) (!strcmp((a), (b)))
27
28 static void stdin_to_stream(char *buf, ssize_t r, FILE *outf) {
29 while (r > 0) {
30 if (fwrite(buf, r*sizeof(char), 1, outf) < 1) {
31 fprintf(stderr, "Write error\n");
32 exit(EXIT_FAILURE);
33 }
34 r = read(0, buf, BUFSIZ*sizeof(char));
35 }
36 if (r == -1) {
37 perror("read");
38 exit(EXIT_FAILURE);
39 }
40 }
25 41
26 42 int main(int argc, char **argv) { int main(int argc, char **argv) {
27 43 ssize_t r; ssize_t r;
44 int run_if_empty;
45 char **argv_exec;
28 46 int fds[2]; int fds[2];
29 47 int child_status; int child_status;
30 48 pid_t child_pid; pid_t child_pid;
31 49 char buf[BUFSIZ]; char buf[BUFSIZ];
32 50 FILE *outf; FILE *outf;
33 51
34 if (argc < 2) {
52 if ((argc < 2) || ((argc == 2) && streq(argv[1], "-n"))) {
35 53 /* Noop */ /* Noop */
36 54 return EXIT_SUCCESS; return EXIT_SUCCESS;
37 55 } }
38 56
57 if (streq(argv[1], "-n")) {
58 run_if_empty = 1;
59 argv_exec = &argv[2];
60 } else {
61 run_if_empty = 0;
62 argv_exec = &argv[1];
63 }
64
39 65 r = read(0, buf, BUFSIZ*sizeof(char)); r = read(0, buf, BUFSIZ*sizeof(char));
40 66
41 if (r == 0)
67 if ((r == 0) && !run_if_empty)
42 68 return EXIT_SUCCESS; return EXIT_SUCCESS;
43 69 else if (r == -1) { else if (r == -1) {
44 70 perror("read"); perror("read");
 
... ... int main(int argc, char **argv) {
50 76 return EXIT_FAILURE; return EXIT_FAILURE;
51 77 } }
52 78
79 if (r && run_if_empty) {
80 /* don't run the subcommand if we read something from stdin and -n was set */
81 /* But write stdin to stdout so ifne -n can be piped without sucking the stream */
82 stdin_to_stream(buf, r, stdout);
83 return EXIT_SUCCESS;
84 }
85
53 86 child_pid = fork(); child_pid = fork();
54 87 if (!child_pid) { if (!child_pid) {
55 88 /* child process: rebind stdin and exec the subcommand */ /* child process: rebind stdin and exec the subcommand */
 
... ... int main(int argc, char **argv) {
57 90 if (dup2(fds[0], 0)) { if (dup2(fds[0], 0)) {
58 91 perror("dup2"); perror("dup2");
59 92 return EXIT_FAILURE; return EXIT_FAILURE;
60 }
93 }
61 94
62 execvp(argv[1], &argv[1]);
63 perror(argv[1]);
95 execvp(*argv_exec, argv_exec);
96 perror(*argv_exec);
64 97 close(fds[0]); close(fds[0]);
65 98 return EXIT_FAILURE; return EXIT_FAILURE;
66 99 } else if (child_pid == -1) { } else if (child_pid == -1) {
 
... ... int main(int argc, char **argv) {
75 108 perror("fdopen"); perror("fdopen");
76 109 exit(1); exit(1);
77 110 } }
78 do {
79 if (fwrite(buf, r*sizeof(char), 1, outf) < 1) {
80 fprintf(stderr, "Write error to %s\n", argv[1]);
81 exit(EXIT_FAILURE);
82 }
83 r = read(0, buf, BUFSIZ*sizeof(char));
84 } while (r > 0);
85 if (r == -1) {
86 perror("read");
87 exit(EXIT_FAILURE);
88 }
111
112 stdin_to_stream(buf, r, outf);
89 113 fclose(outf); fclose(outf);
90 114
91 115 if (waitpid(child_pid, &child_status, 0) != child_pid) { if (waitpid(child_pid, &child_status, 0) != child_pid) {
File ifne.docbook changed (mode: 100644) (index 92c7f48..38e3889)
... ... with this program; if not, write to the Free Software Foundation, Inc.,
33 33 <firstname>Javier</firstname> <firstname>Javier</firstname>
34 34 <surname>Merino</surname> <surname>Merino</surname>
35 35 </author> </author>
36 <date>2008-03-19</date>
36 <date>2008-05-01</date>
37 37 </refentryinfo> </refentryinfo>
38 38
39 39 <refmeta> <refmeta>
 
... ... with this program; if not, write to the Free Software Foundation, Inc.,
48 48
49 49 <refsynopsisdiv> <refsynopsisdiv>
50 50 <cmdsynopsis> <cmdsynopsis>
51 <command>ifne command</command>
51 <command>ifne [-n] command</command>
52 52 </cmdsynopsis> </cmdsynopsis>
53 53 </refsynopsisdiv> </refsynopsisdiv>
54 54
55 55 <refsect1> <refsect1>
56 56 <title>DESCRIPTION</title> <title>DESCRIPTION</title>
57 57
58 <para><command>ifne</command> runs the following command if and only if
59 the standard input is not empty.</para>
58 <para><command>ifne</command> runs the following command if and only if
59 the standard input is not empty.</para>
60 60 </refsect1> </refsect1>
61 61
62 <refsect1>
63 <title>OPTIONS</title>
64
65 <variablelist>
66 <varlistentry>
67 <term><option>-n</option></term>
68 <listitem>
69 <para>Reverse operation. Run the command if the standard input is empty.</para>
70 </listitem>
71 </varlistentry>
72 </variablelist>
73 </refsect1>
74
62 75 <refsect1> <refsect1>
63 76 <title>EXAMPLE</title> <title>EXAMPLE</title>
64 77 <cmdsynopsis> <cmdsynopsis>
65 78 <command>find . -name core | ifne mail -s "Core files found" root</command> <command>find . -name core | ifne mail -s "Core files found" root</command>
66 79 </cmdsynopsis> </cmdsynopsis>
67 80 </refsect1> </refsect1>
81
82 <refsect1>
83 <title>AUTHOR</title>
84
85 <para>Copyright 2008 by Javier Merino &lt;cibervicho@gmail.com&gt;</para>
86 <para>Licensed under the GNU GPL</para>
87 </refsect1>
88
68 89 </refentry> </refentry>
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/nicolas/debian.moreutils

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/nicolas/debian.moreutils

Clone this repository using git:
git clone git://git.rocketgit.com/user/nicolas/debian.moreutils

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main