summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2008-11-07 16:34:49 (GMT)
committer Jaromil <jaromil@dyne.org>2008-11-07 16:34:49 (GMT)
commitc8014448be4b0a0ec6f4672e78036c83c40c51e3 (patch)
tree472898bd3f531a43b6fa30f000ec0ab0d466e1c4
parentb5832c35ccbd157c6f4253f26fcad9659fe13516 (diff)
fix for input from stdin (pipe from other applications)
-rw-r--r--cmdline.cpp33
-rw-r--r--tbt.cpp65
-rw-r--r--tbt.h3
3 files changed, 26 insertions, 75 deletions
diff --git a/cmdline.cpp b/cmdline.cpp
index bef0d3e..16578bd 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -22,6 +22,7 @@
//// system includes
#include <stdio.h>
#include <stdlib.h>
+#include <termios.h>
#include <time.h>
#include <errno.h>
#include <string.h>
@@ -449,24 +450,42 @@ int main(int argc, char** argv)
switch(operation){
case REC:
- // append from 0 (stdin) each 1 byte
- tbt.fdappend(0, 1);
-
+
+ {
+ // OMFG
+ struct termios stty;
+ tcgetattr(0,&stty);
+ stty.c_lflag ^= ICANON|ECHO;
+ stty.c_cc[VTIME] = 100; // 10 seconds minute timeout
+ stty.c_cc[VMIN] = 0;
+ tcsetattr(0,TCSANOW,&stty);
+
+ while(!tbt.quit) {
+
+ read(0,(void*)&key,1);
+
+ tbt.append((int64_t)key);
+
+ write(1, (void*)&key, 1);
+
+ }
+
+ stty.c_lflag |= ICANON|ECHO;
+ tcsetattr(0,TCSANOW,&stty);
+ }
+
switch(render) {
case BIN:
tbt.save_bin( filename );
- act("TBT file %s rendered in binary format",filename);
break;
case ASCII:
tbt.save_ascii( filename );
- act("TBT file %s rendered in ascii format",filename);
break;
case HTML:
tbt.save_html( filename );
- act("TBT file %s rendered in html format",filename);
break;
}
@@ -480,7 +499,7 @@ int main(int argc, char** argv)
// tbt.getkey is a blocking call
// will wait N time before returning
key = tbt.getkey();
-
+
// print out on stdout
write(1, (void*)&key, 1);
}
diff --git a/tbt.cpp b/tbt.cpp
index 7331f15..5795df2 100644
--- a/tbt.cpp
+++ b/tbt.cpp
@@ -254,71 +254,6 @@ void TBT::append(uint64_t key) {
-// keysize is in bytes here, because if it would be in bits
-// we wouldn't be able to fread() single bits at precise timing
-
-int TBT::fdappend(int filedes, int keysize) {
-
- TBTEntry *ent;
- uint64_t entmask;
- uint64_t bitmask;
- FILE *fd;
- int c, len;
-
- fd = fdopen(filedes, "r");
- if(!fd) {
- error("can't open file descriptor %u: %s", filedes, strerror(errno));
- return 0;
- }
-
- // max bytes for an entry here
- if(!keysize) keysize = 4;
- else if(keysize > 4) keysize = 4;
-
- // render the bitmask
- bitmask = 0xff;
- for( c=keysize ; c>1; c--)
- bitmask |= bitmask<<8;
-
-
- act("appending from file descriptor %u", filedes);
-
- c = 0;
-
- quit = false;
-
- while( ! quit ) {
-
- if( feof(fd) ) break;
-
- len = fread((void*)&entmask, keysize, 1, fd);
- if(!len) break;
- else if(len != keysize) {
- warning("truncated entry, %u bytes read: %s", len, strerror(errno));
- continue;
- }
-
- func("appending new entry %c", entmask);
-
- ent = new TBTEntry();
-
- // compute time delay since last key
- // the NOW is WHEN this operation is executed
- compute_delta( ent );
-
- ent->key = (entmask & bitmask);
-
- buffer->append(ent);
- c++;
-
- }
-
- act("appended %u entries from file descriptor %u", c, filedes);
-
- return c;
-
-}
-
uint64_t TBT::getkey() {
diff --git a/tbt.h b/tbt.h
index 7a481b2..2a05a22 100644
--- a/tbt.h
+++ b/tbt.h
@@ -74,9 +74,6 @@ class TBT {
void append(uint64_t key); ///< append a single key at the time this function is called
- int fdappend(int filedes, int keysize); ///< append keys read from a file descriptor
-
-
// playback functions: time based feed of keys loaded