summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <Jiri Olsa jolsa@redhat.com>2010-04-02 19:14:07 +0200
committerJiri Olsa <Jiri Olsa jolsa@redhat.com>2010-04-02 19:14:07 +0200
commit3396568982553a6547b4dca79d1258504c45ac41 (patch)
treeaf6456868be0f236c35c7542ddc8dfca7e81b7df
parent281cc3b98c7112bf0b349e6c32ff50ce1cf2722a (diff)
downloadtsnif-3396568982553a6547b4dca79d1258504c45ac41.tar.gz
tsnif-3396568982553a6547b4dca79d1258504c45ac41.tar.xz
tsnif-3396568982553a6547b4dca79d1258504c45ac41.zip
initial tsnif-replay
-rw-r--r--src/Makefile4
-rw-r--r--src/tsnif-replay.c82
-rw-r--r--src/tsnif.c2
3 files changed, 85 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile
index 2809eb4..db1703d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -22,8 +22,8 @@ $(TSNIF): $(TSNIF_OBJS) $(INTF_OBJS) $(STORAGE_OBJS)
TSNIF_REPLAY=tsnif-replay
TSNIF_REPLAY_OBJS= \
src/tsnif-replay.o
-$(TSNIF_REPLAY): $(TSNIF_REPLAY_OBJS)
- $(QUIET_LD)$(CC) -o $@ $(TSNIF_REPLAY_OBJS)
+$(TSNIF_REPLAY): $(TSNIF_REPLAY_OBJS) $(STORAGE_OBJS)
+ $(QUIET_LD)$(CC) -o $@ $^
TSNIFD=tsnifd
diff --git a/src/tsnif-replay.c b/src/tsnif-replay.c
index 5864387..0f1455f 100644
--- a/src/tsnif-replay.c
+++ b/src/tsnif-replay.c
@@ -1,7 +1,89 @@
#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+
+#include "storage.h"
+
+
+static char *filename;
+struct tsnif_storage_handle storage_handle;
+static struct tsnif_storage_opts storage_opts = {
+ .flags = TSNIF_STORAGE_OPT_READ,
+};
+
+int tsnif_debug = 0;
+
+static void usage()
+{
+ printf("tsnif-replay -f <file>\n");
+ _exit(-1);
+}
+
+static int get_args(int argc, char **argv)
+{
+ while (1) {
+ int c;
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"file", required_argument, 0, 'f'},
+ {"debug", no_argument, 0, 'd'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long(argc, argv, "f:dh",
+ long_options, &option_index);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'f':
+ filename = optarg;
+ break;
+
+ case 'd':
+ tsnif_debug = 1;
+ break;
+
+ case 'h':
+ usage();
+ break;
+
+ default:
+ printf("unknown option '%c'", c);
+ } /* switch(c) */
+ } /* while(1) */
+
+ return 0;
+}
int main(int argc, char **argv)
{
+ int err;
+
+ if (get_args(argc, argv))
+ usage();
+
+ err = tsnif_storage_init(&storage_handle, &storage_opts, filename);
+ if (err)
+ return -1;
+
+ do {
+ struct tsnif_storage_rec rec;
+
+ err = tsnif_storage_read(&storage_handle,
+ TSNIF_STORAGE_READ_NEXT, &rec);
+
+ if (err)
+ break;
+
+ fwrite(rec.ptr, rec.len, 1, stdout);
+ fflush(NULL);
+
+ } while(1);
+
+ tsnif_storage_close(&storage_handle);
return 0;
}
diff --git a/src/tsnif.c b/src/tsnif.c
index 0ae6d5f..57731f2 100644
--- a/src/tsnif.c
+++ b/src/tsnif.c
@@ -17,7 +17,7 @@ static struct tsnif_handle handle;
static struct tsnif_term term;
static struct tsnif_storage_opts storage_opts = {
- .flags = TSNIF_STORAGE_OPT_WRITE | TSNIF_STORAGE_OPT_WRITE,
+ .flags = TSNIF_STORAGE_OPT_WRITE,
.size_max = 1024*1024,
};
static struct tsnif_storage_handle storage_handle;