@@ -16,9 +16,13 @@ int main(int argc, char **argv) {
16
16
};
17
17
18
18
options.add_options ()(" n,name" , " shared memory name (mandatory)" , cxxopts::value<std::string>());
19
+ options.add_options ()(" i,invert" , " invert all input bits" , cxxopts::value<bool >()->default_value (" false" ));
19
20
options.add_options ()(" r,repeat" ,
20
21
" repeat input if input size is smaller than shared memory" ,
21
22
cxxopts::value<bool >()->default_value (" false" ));
23
+ options.add_options ()(" p,passthrough" ,
24
+ " output everything that is written to the shared memory to stdout" ,
25
+ cxxopts::value<bool >()->default_value (" false" ));
22
26
options.add_options ()(" h,help" , " print usage" );
23
27
24
28
// parse arguments
@@ -31,6 +35,7 @@ int main(int argc, char **argv) {
31
35
}
32
36
33
37
const auto REPEAT_INPUT = args[" repeat" ].as <bool >();
38
+ const auto PASSTHROUGH = args[" passthrough" ].as <bool >();
34
39
35
40
// print usage
36
41
if (args.count (" help" )) {
@@ -84,15 +89,23 @@ int main(int argc, char **argv) {
84
89
85
90
auto *shm_data = shm->get_addr <char *>();
86
91
92
+ const int INVERT_MASK = args[" invert" ].as <bool >() ? ~0 : 0 ;
93
+
87
94
// copy file to shm (and buffer)
88
95
std::size_t remaining = SHM_SIZE;
89
96
std::size_t pos = 0 ;
90
97
while (remaining) {
91
- const auto C = std::cin.get ();
92
- if (C == EOF) break ;
98
+ auto c = std::cin.get ();
99
+ if (c == EOF) break ;
93
100
94
- shm_data[pos] = static_cast <char >(C);
95
- if (REPEAT_INPUT) { in_buffer[pos] = static_cast <char >(C); }
101
+ c ^= INVERT_MASK;
102
+
103
+ shm_data[pos] = static_cast <char >(c);
104
+ if (PASSTHROUGH) {
105
+ std::cout.put (static_cast <char >(c));
106
+ std::cout.flush ();
107
+ }
108
+ if (REPEAT_INPUT) { in_buffer[pos] = static_cast <char >(c); }
96
109
97
110
pos++;
98
111
remaining--;
@@ -105,6 +118,10 @@ int main(int argc, char **argv) {
105
118
const auto COPY_SIZE = std::min (BUF_SIZE, remaining);
106
119
107
120
memcpy (shm_data + pos, in_buffer.get (), COPY_SIZE);
121
+ if (PASSTHROUGH) {
122
+ std::cout.write (in_buffer.get (), static_cast <std::streamsize>(COPY_SIZE));
123
+ std::cout.flush ();
124
+ }
108
125
109
126
pos += COPY_SIZE;
110
127
remaining -= COPY_SIZE;
0 commit comments