From a9d6e04cf24437c529a18bd40055c38f30f2237a Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Mon, 9 Oct 2017 16:33:05 +0200
Subject: [PATCH] T: modify extract_input_subframe to dump several subframes

---
 .../utils/T/tracer/extract_input_subframe.c   | 40 +++++++++++++++++--
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/common/utils/T/tracer/extract_input_subframe.c b/common/utils/T/tracer/extract_input_subframe.c
index b5f74b3b27b..02c5f3d5650 100644
--- a/common/utils/T/tracer/extract_input_subframe.c
+++ b/common/utils/T/tracer/extract_input_subframe.c
@@ -12,7 +12,9 @@ void usage(void)
 "usage: [options] <file> <frame> <subframe>\n"
 "options:\n"
 "    -d <database file>        this option is mandatory\n"
+"    -o <output file>          this option is mandatory\n"
 "    -v                        verbose\n"
+"    -c <number of subframes>  default to 1\n"
   );
   exit(1);
 }
@@ -25,15 +27,23 @@ int main(int n, char **v)
   int input_event_id;
   database_event_format f;
   char *file = NULL;
+  char *output_file = NULL;
+  FILE *out;
   int fd;
   int frame = -1, subframe = -1;
   int frame_arg, subframe_arg, buffer_arg;
   int verbose = 0;
+  int number_of_subframes = 1;
+  int processed_subframes = 0;
 
   for (i = 1; i < n; i++) {
     if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
     if (!strcmp(v[i], "-d"))
       { if (i > n-2) usage(); database_filename = v[++i]; continue; }
+    if (!strcmp(v[i], "-o"))
+      { if (i > n-2) usage(); output_file = v[++i]; continue; }
+    if (!strcmp(v[i], "-c"))
+      { if (i > n-2) usage(); number_of_subframes = atoi(v[++i]); continue; }
     if (!strcmp(v[i], "-v")) { verbose = 1; continue; }
     if (file == NULL) { file = v[i]; continue; }
     if (frame == -1) { frame = atoi(v[i]); continue; }
@@ -47,6 +57,19 @@ int main(int n, char **v)
     exit(1);
   }
 
+  if (number_of_subframes < 1) {
+    printf("bad value for option -c, must be at least 1 and is %d\n",
+           number_of_subframes);
+    exit(1);
+  }
+
+  if (output_file == NULL) {
+    printf("gimme -o <output file>, thanks\n");
+    exit(1);
+  }
+
+  out = fopen(output_file, "w"); if(out==NULL){perror(output_file);exit(1);}
+
   database = parse_database(database_filename);
 
   load_config_file(database_filename);
@@ -99,11 +122,22 @@ short *x = e.e[buffer_arg].b;
 x[i] *= 14;
 }
 #endif
-    fwrite(e.e[buffer_arg].b, e.e[buffer_arg].bsize, 1, stdout);
-    fflush(stdout);
-    return 0;
+    if (fwrite(e.e[buffer_arg].b, e.e[buffer_arg].bsize, 1, out) != 1)
+      { perror(output_file); exit(1); }
+    processed_subframes++;
+    number_of_subframes--;
+    if (!number_of_subframes) {
+      if (fclose(out)) perror(output_file);
+      printf("%d subframes dumped\n", processed_subframes);
+      return 0;
+    }
+    subframe++;
+    if (subframe == 10) { subframe = 0; frame=(frame+1)%1024; }
   }
 
   printf("frame %d subframe %d not found\n", frame, subframe);
+  printf("%d subframes dumped\n", processed_subframes);
+  fclose(out);
+
   return 0;
 }
-- 
GitLab