comparison toys/posix/tee.c @ 674:7e846e281e38

New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
author Rob Landley <rob@landley.net>
date Mon, 08 Oct 2012 00:02:30 -0500
parents 6df4ccc0acbe
children 786841fdb1e0
comparison
equal deleted inserted replaced
673:c102f31a753e 674:7e846e281e38
19 19
20 -a append to files. 20 -a append to files.
21 -i ignore SIGINT. 21 -i ignore SIGINT.
22 */ 22 */
23 23
24 #define FOR_tee
24 #include "toys.h" 25 #include "toys.h"
25 26
26 DEFINE_GLOBALS( 27 GLOBALS(
27 void *outputs; 28 void *outputs;
28 ) 29 )
29
30 #define TT this.tee
31 30
32 struct fd_list { 31 struct fd_list {
33 struct fd_list *next; 32 struct fd_list *next;
34 int fd; 33 int fd;
35 }; 34 };
46 TT.outputs = temp; 45 TT.outputs = temp;
47 } 46 }
48 47
49 void tee_main(void) 48 void tee_main(void)
50 { 49 {
51 if (toys.optflags&2) signal(SIGINT, SIG_IGN); 50 if (toys.optflags & FLAG_i) signal(SIGINT, SIG_IGN);
52 51
53 // Open output files 52 // Open output files
54 loopfiles_rw(toys.optargs, 53 loopfiles_rw(toys.optargs,
55 O_RDWR|O_CREAT|((toys.optflags&1)?O_APPEND:O_TRUNC), 0666, 0, 54 O_RDWR|O_CREAT|((toys.optflags & FLAG_a)?O_APPEND:O_TRUNC),
56 do_tee_open); 55 0666, 0, do_tee_open);
57 56
58 for (;;) { 57 for (;;) {
59 struct fd_list *fdl; 58 struct fd_list *fdl;
60 int len; 59 int len;
61 60