This source file includes following definitions.
- prepare_read
- done_read
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20 #include "pipe-filter.h"
21
22 #include "binary-io.h"
23 #include "c-ctype.h"
24 #include "read-file.h"
25 #include "macros.h"
26
27
28
29
30
31
32 struct locals
33 {
34 const char *input;
35 size_t nread;
36 char buf[19];
37 };
38
39 static void *
40 prepare_read (size_t *num_bytes_p, void *private_data)
41 {
42 struct locals *l = (struct locals *) private_data;
43 *num_bytes_p = sizeof (l->buf);
44 return l->buf;
45 }
46
47 static void
48 done_read (void *data_read, size_t num_bytes_read, void *private_data)
49 {
50 struct locals *l = (struct locals *) private_data;
51 const char *p = l->input + l->nread;
52 const char *q = (const char *) data_read;
53 size_t i;
54
55 for (i = 0; i < num_bytes_read; i++, q++)
56 {
57
58 if (!(O_BINARY && *q == '\r'))
59 {
60 char orig = *p;
61 char expected = c_toupper (orig);
62 ASSERT (*q == expected);
63 p++;
64 }
65 }
66 l->nread = p - l->input;
67 }
68
69 int
70 main (int argc, char *argv[])
71 {
72 const char *tr_program;
73 const char *input_filename;
74 size_t input_size;
75 char *input;
76
77 ASSERT (argc == 3);
78
79 tr_program = argv[1];
80
81
82 input_filename = argv[2];
83 input = read_file (input_filename, RF_BINARY, &input_size);
84 ASSERT (input != NULL);
85
86
87 {
88 const char *argv[4];
89 struct locals l;
90 struct pipe_filter_gi *f;
91 int result;
92
93 l.input = input;
94 l.nread = 0;
95
96 argv[0] = tr_program;
97 argv[1] = "abcdefghijklmnopqrstuvwxyz";
98 argv[2] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
99 argv[3] = NULL;
100
101 f = pipe_filter_gi_create ("tr", tr_program, argv, false, true,
102 prepare_read, done_read, &l);
103 ASSERT (f != NULL);
104 result = pipe_filter_gi_write (f, input, input_size);
105 ASSERT (result == 0);
106 result = pipe_filter_gi_close (f);
107 ASSERT (result == 0);
108 ASSERT (l.nread == input_size);
109 }
110
111 free (input);
112
113 return 0;
114 }