summaryrefslogtreecommitdiff
path: root/tools/pipette.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pipette.c')
-rw-r--r--tools/pipette.c78
1 files changed, 77 insertions, 1 deletions
diff --git a/tools/pipette.c b/tools/pipette.c
index 1eda2d0..c76b9e5 100644
--- a/tools/pipette.c
+++ b/tools/pipette.c
@@ -26,6 +26,7 @@ using namespace std;
#include <vector>
#include <sstream>
#include <map>
+#include <string.h> /* for strlen() */
#include <sys/types.h> /* for fstat */
#include <sys/stat.h> /* .. */
@@ -438,11 +439,84 @@ void play() {
dumpstat(tube[rEnd]);
dumpstat(tube[wEnd]);
sleep(1.5);
+ int plus = dup(tube[wEnd]);
close(tube[rEnd]);
dumpstat(tube[rEnd]);
dumpstat(tube[wEnd]);
+ dumpstat(plus);
}
+void test_read(){
+// test with:
+// cat envelope.dat | 1<&0 ./pipette
+ char buf[1024];
+ list<string> rslt;
+ int didsome(0);
+ for (;;){ // loop over all read buffers
+ int nr = read(1, buf, sizeof(buf));
+ if (nr == 0) break;
+ if (nr < 0) {
+ cerr << "read failed " << strError() << endl;
+ exit(1);
+ }
+ for (;;){ // loop over all strings
+ for (int ii = 0; ii < nr; ii++) {
+ char ch = buf[ii];
+ if (ch == 0) {
+ if (!didsome) goto done;
+ didsome = 0;
+ continue;
+ }
+ if (!didsome) {
+ rslt.push_back("");
+ }
+ rslt.back() += ch;
+ didsome++;
+ }
+ }
+ }
+done:;;;;
+ for (list<string>::const_iterator ptr = rslt.begin();
+ ptr != rslt.end(); ptr++) {
+ cerr << *ptr << endl;
+ }
+}
+
+#if 0
+void old_test_read(){
+// test with:
+// echo asfd | 1<&0 ./pipette
+// cat pipette.c | 1<&0 ./pipette
+ char buf[1024];
+ for (;;){
+ int nr = read(1, buf, sizeof(buf));
+ if (nr == 0) break;
+ if (nr < 0) {
+ cerr << "read failed " << strError() << endl;
+ exit(1);
+ }
+// unit 1 fails: bad file descriptor:
+// int nw = write(1, buf, nr);
+ for (int ii = 0; ii < nr; ii++) {
+ char* foo;
+ char out[2] = {0, 0};
+ char ch = buf[ii];
+ if (ch) {
+ foo = out;
+ *foo = ch;
+ } else {
+ foo = "␀\n";
+ }
+ int nw = write(2, foo, strlen(foo));
+ if (nw < 0) {
+ cerr << "write failed " << strError() << endl;
+ exit(1);
+ }
+ }
+ }
+}
+#endif
+
int main(int argc, char** argv) {
{
progname = *argv;
@@ -452,7 +526,9 @@ int main(int argc, char** argv) {
progid = binder.str();
}
- play();
+// play();
+ test_read();
+ cerr << "<BuhBye>" << endl;
exit(0);
#define foo(name, num) codemap[num] = #name ;