+void write_groups_in_files(int nb, struct file_node **nodes) {
+ FILE *file = 0;
+ int current_group = -1, n, first_of_group;
+ char filename[PATH_MAX + 1];
+
+ for(n = 0; n < nb; n++) {
+ first_of_group = (n == 0);
+ if(nodes[n]->group_id != current_group) {
+ if(file) { fclose(file); }
+ sprintf(filename, "%s%06d", result_file_prefix, nodes[n]->group_id);
+ file = fopen(filename, "w");
+ current_group = nodes[n]->group_id;
+ printf("Writing %s.\n" , filename);
+ first_of_group = 1;
+ }
+
+ if(!trim_first || !first_of_group) {
+ write_one_entry_to_file(file, nodes[n]);
+ }
+ }
+
+ if(file) { fclose(file); }
+}
+