ssize_t get_file_length(const t_hs filename) { struct stat fstat; if (stat(hs_to_str(filename), &fstat) != -1) return (fstat.st_size); return (-1); }
void hs_test (void) { array_t *arr; struct hs *a = hs_create (1); hs_add (a, array_from_str ("0011xx00")); hs_add (a, array_from_str ("10100x0x")); arr = array_from_str ("10100x01"); hs_diff (a, arr); hs_print (a); struct hs *b = hs_copy_a (a); hs_print (b); hs_free (b); free (arr); b = hs_create (1); hs_add (b, array_from_str ("xxxx1x00")); hs_add (b, array_from_str ("xxxxx1x0")); hs_print (b); hs_isect (b, a); hs_print (b); hs_free (b); hs_free (a); a = hs_create (1); hs_add (a, array_from_str ("10xxxxxx")); hs_add (a, array_from_str ("xxxxxx10")); arr = array_from_str ("11111111"); hs_diff (a, arr); hs_print (a); hs_cmpl (a); hs_print (a); hs_free (a); a = hs_create (1); hs_add (a, array_from_str ("10xxxxxx")); hs_add (a, array_from_str ("xxxxxx10")); b = hs_create (1); hs_add (b, array_from_str ("11111111")); hs_minus (a, b); hs_print (a); hs_free (a); hs_free (b); a = hs_create (1); hs_add (a, array_from_str ("11111111")); //hs_add (a, array_from_str ("xxxxxxx1")); hs_diff (a, arr); hs_print (a); hs_comp_diff (a); char *s = hs_to_str (a); printf ("S: %s\n", s); free (s); hs_free (a); free (arr); }
int source_file_read(t_source_file *file, t_hs file_name) { int fd; file->name = file_name; fd = open(hs_to_str(file_name), O_RDONLY); if (fd == -1) return (-1); file->content = read_whole_file(fd); if (!file->content) { close(fd); return (-2); } close(fd); return (0); }
void source_file_init_unnamed(t_source_file *file, t_hs content) { file->name = hs("<unknown file>"); file->content = hs_to_str(content); }