diff options
author | John Denker <jsd@av8n.com> | 2012-11-23 12:58:49 -0800 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-11-23 12:58:49 -0800 |
commit | f95fae8eba793751547db6b203f417b6fe7a35f7 (patch) | |
tree | 649e7cf025c5d3116824524627f77a52d249a88b /tools/pipette.c | |
parent | 4134b154839c91f44bb39547af9297f4b6a353d3 (diff) |
we have passable code for reading envelope data
Diffstat (limited to 'tools/pipette.c')
-rw-r--r-- | tools/pipette.c | 78 |
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 ; |