+ free_matcher(&matcher);
+}
+
+//////////////////////////////////////////////////////////////////////
+
+void read_file(const char *input_filename,
+ int nb_lines_max, int *nb_lines, char **lines,
+ int hash_table_size, int *hash_table) {
+
+ char buffer[buffer_size], raw_line[buffer_size];;
+
+ ifstream file(input_filename);
+
+ if(file.fail()) {
+ cerr << "Can not open " << input_filename << endl;
+ exit(1);
+ }
+
+ while(*nb_lines < nb_lines_max && !file.eof()) {
+
+ file.getline(raw_line, buffer_size);
+
+ if(raw_line[0]) {
+
+ if(file.fail()) {
+ cerr << "Line too long:" << endl;
+ cerr << raw_line << endl;
+ exit(1);
+ }
+
+ char *s, *t;
+ const char *u;
+
+ t = raw_line;
+
+ // Remove the zsh history prefix
+
+ if(zsh_history && *t == ':') {
+ while(*t && *t != ';') s++;
+ if(*t == ';') t++;
+ }
+
+ // Remove the bash history prefix
+
+ if(bash_history && (*t == ' ' || (*t >= '0' && *t <= '9'))) {
+ while(*t == ' ' || (*t >= '0' && *t <= '9')) t++;
+ }
+
+ // Copy the string while transforming the ctrl characters into
+ // printable characters
+
+ s = buffer;
+
+ while(*t) {
+ u = unctrl(*t++);
+ while(*u) { *s++ = *u++; }
+ }
+ *s = '\0';
+
+ // Check for duplicates with the hash table and insert the line
+ // in the list if necessary
+
+ int dup;
+
+ if(hash_table) {
+ dup = test_and_add(buffer, *nb_lines, lines, hash_table, hash_table_size);
+ } else {
+ dup = -1;
+ }
+
+ if(dup < 0) {
+ lines[*nb_lines] = new char[strlen(buffer) + 1];
+ strcpy(lines[*nb_lines], buffer);
+ } 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)++;
+ }
+ }