-void read_file(const char *input_filename,
- int nb_lines_max, int *nb_lines, char **lines,
- int hash_table_size, int *hash_table) {
+void store_line(hash_table_t *hash_table,
+ const char *t,
+ int nb_lines_max, int *nb_lines, char **lines) {
+ int dup;
+
+ /* Remove the zsh history prefix */
+
+ if(zsh_history && *t == ':') {
+ while(*t && *t != ';') t++;
+ if(*t == ';') t++;
+ }
+
+ /* Remove the bash history prefix */
+
+ if(bash_history) {
+ while(*t == ' ') t++;
+ while(*t >= '0' && *t <= '9') t++;
+ while(*t == ' ') t++;
+ }
+
+ /* Check for duplicates with the hash table and insert the line in
+ the list if necessary */
+
+ if(hash_table) {
+ dup = add_and_get_previous_index(hash_table, t, *nb_lines, lines);
+ } else {
+ dup = -1;
+ }
+
+ if(dup < 0) {
+ lines[*nb_lines] = (char *) malloc((strlen(t) + 1) * sizeof(char));
+ strcpy(lines[*nb_lines], t);
+ } else {
+ /* The string was already in there, so we do not allocate a new
+ string but use the pointer to the first occurence of it */
+ lines[*nb_lines] = lines[dup];
+ lines[dup] = 0;
+ }
+
+ (*nb_lines)++;
+}
+
+void read_file(hash_table_t *hash_table,
+ const char *input_filename,
+ int nb_lines_max, int *nb_lines, char **lines) {