Convert "4 space tabs" to spaces; Minor reformatting.
[obnox/wireshark/wip.git] / merge.c
diff --git a/merge.c b/merge.c
index bedb342855dec194616869c6e1422d4ff135f1ea..95be037fcfcca3acb7a154dc529d0fef721a4c06 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -41,7 +41,7 @@ merge_open_in_files(int in_file_count, char *const *in_file_names,
   merge_in_file_t *files;
   gint64 size;
 
-  files = g_malloc(files_size);
+  files = (merge_in_file_t *)g_malloc(files_size);
   *in_files = files;
 
   for (i = 0; i < in_file_count; i++) {
@@ -49,6 +49,7 @@ merge_open_in_files(int in_file_count, char *const *in_file_names,
     files[i].wth         = wtap_open_offline(in_file_names[i], err, err_info, FALSE);
     files[i].data_offset = 0;
     files[i].state       = PACKET_NOT_PRESENT;
+    files[i].packet_num  = 0;
     if (!files[i].wth) {
       /* Close the files we've already opened. */
       for (j = 0; j < i; j++)
@@ -150,10 +151,19 @@ is_earlier(struct wtap_nstime *l, struct wtap_nstime *r) {
 /*
  * Read the next packet, in chronological order, from the set of files
  * to be merged.
+ *
+ * On success, set *err to 0 and return a pointer to the merge_in_file_t
+ * for the file from which the packet was read.
+ *
+ * On a read error, set *err to the error and return a pointer to the
+ * merge_in_file_t for the file on which we got an error.
+ *
+ * On an EOF (meaning all the files are at EOF), set *err to 0 and return
+ * NULL.
  */
-wtap *
-merge_read_packet(int in_file_count, merge_in_file_t in_files[], int *err,
-                  gchar **err_info)
+merge_in_file_t *
+merge_read_packet(int in_file_count, merge_in_file_t in_files[],
+                  int *err, gchar **err_info)
 {
   int i;
   int ei = -1;
@@ -199,15 +209,27 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[], int *err,
   /* We'll need to read another packet from this file. */
   in_files[ei].state = PACKET_NOT_PRESENT;
 
-  /* Return a pointer to the wtap structure for the file with that frame. */
-  return in_files[ei].wth;
+  /* Count this packet. */
+  in_files[ei].packet_num++;
+
+  /* Return the ordinal of the file from which the packet was read. */
+  return &in_files[ei];
 }
 
 /*
  * Read the next packet, in file sequence order, from the set of files
  * to be merged.
+ *
+ * On success, set *err to 0 and return a pointer to the merge_in_file_t
+ * for the file from which the packet was read.
+ *
+ * On a read error, set *err to the error and return a pointer to the
+ * merge_in_file_t for the file on which we got an error.
+ *
+ * On an EOF (meaning all the files are at EOF), set *err to 0 and return
+ * NULL.
  */
-wtap *
+merge_in_file_t *
 merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
                          int *err, gchar **err_info)
 {
@@ -224,7 +246,7 @@ merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
     if (*err != 0) {
       /* Read error - quit immediately. */
       in_files[i].state = GOT_ERROR;
-      return NULL;
+      return &in_files[i];
     }
     /* EOF - flag this file as being at EOF, and try the next one. */
     in_files[i].state = AT_EOF;
@@ -235,6 +257,7 @@ merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
     return NULL;
   }
 
-  /* Return a pointer to the wtap structure for the file with that frame. */
-  return in_files[i].wth;
+  /* Return the ordinal of the file from which the packet was read. */
+  *err = 0;
+  return &in_files[i];
 }