Commit 8e28dacd authored by Cedric Roux's avatar Cedric Roux
Browse files

add a small utility to extract a configuration file from a log

parent 99d1328d
...@@ -5,7 +5,7 @@ CFLAGS=-Wall -g -pthread -DT_TRACER -I. ...@@ -5,7 +5,7 @@ CFLAGS=-Wall -g -pthread -DT_TRACER -I.
LIBS=-lX11 -lm -lpng -lXft LIBS=-lX11 -lm -lpng -lXft
all: record replay textlog enb vcd all: record replay extract_config textlog enb vcd
record: utils.o record.o database.o config.o record: utils.o record.o database.o config.o
$(CC) $(CFLAGS) -o record $^ $(LIBS) $(CC) $(CFLAGS) -o record $^ $(LIBS)
...@@ -13,6 +13,9 @@ record: utils.o record.o database.o config.o ...@@ -13,6 +13,9 @@ record: utils.o record.o database.o config.o
replay: utils.o replay.o replay: utils.o replay.o
$(CC) $(CFLAGS) -o replay $^ $(LIBS) $(CC) $(CFLAGS) -o replay $^ $(LIBS)
extract_config: extract_config.o
$(CC) $(CFLAGS) -o extract_config $^ $(LIBS)
textlog: utils.o textlog.o database.o event.o handler.o config.o \ textlog: utils.o textlog.o database.o event.o handler.o config.o \
event_selector.o view/view.a gui/gui.a logger/logger.a \ event_selector.o view/view.a gui/gui.a logger/logger.a \
filter/filter.a filter/filter.a
...@@ -47,6 +50,7 @@ filter/filter.a: ...@@ -47,6 +50,7 @@ filter/filter.a:
clean: clean:
rm -f *.o core tracer_remote textlog enb vcd record replay rm -f *.o core tracer_remote textlog enb vcd record replay
rm -f extract_config
cd gui && make clean cd gui && make clean
cd view && make clean cd view && make clean
cd logger && make clean cd logger && make clean
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../T_defs.h"
void usage(void)
{
printf(
"options:\n"
" -i <input file> this option is mandatory\n"
);
exit(1);
}
#define ERR printf("ERROR: read file %s failed\n", input_filename)
int main(int n, char **v)
{
char *input_filename = NULL;
int i;
FILE *in;
for (i = 1; i < n; i++) {
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-i"))
{ if (i > n-2) usage(); input_filename = v[++i]; continue; }
usage();
}
if (input_filename == NULL) {
printf("ERROR: provide an input file (-i)\n");
exit(1);
}
in = fopen(input_filename, "r");
if (in == NULL) { perror(input_filename); abort(); }
while (1) {
int type;
int32_t length;
char v[T_BUFFER_MAX];
int vpos = 0;
/* read event from file */
if (fread(&length, 4, 1, in) != 1) break;
memcpy(v+vpos, &length, 4);
vpos += 4;
#ifdef T_SEND_TIME
if (length < sizeof(struct timespec)) { ERR; break; }
if (fread(v+vpos, sizeof(struct timespec), 1, in) != 1) { ERR; break; }
vpos += sizeof(struct timespec);
length -= sizeof(struct timespec);
#endif
if (length < sizeof(int)) { ERR; break; }
if (fread(&type, sizeof(int), 1, in) != 1) { ERR; break; }
memcpy(v+vpos, &type, sizeof(int));
vpos += sizeof(int);
length -= sizeof(int);
if (length) if (fread(v+vpos, length, 1, in) != 1) { ERR; break; }
vpos += length;
if (type == -1) {
if (length < sizeof(int)) { ERR; break; }
length -= sizeof(int);
if (fwrite(v+vpos-length, length, 1, stdout) != 1) { ERR; break; }
}
/* TODO: parse all file? */
if (type == -2) break;
}
fclose(in);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment