static sect_types_t get_section_type ( char *text_line, sect_types_t current_section_type ) { sect_types_t sect_type; /* The order of the first two if-tests cannot be changed! */ if (is_comment_line(text_line)) sect_type = ZEROTH_SECT; else if (is_format(text_line)) sect_type = FMT_SECT; else if (is_equiv_section(text_line, current_section_type)) sect_type = kind_of_equiv_section(text_line); else if (is_last_sect(text_line)) sect_type = LAST_SECT; /* else if (add_your_BOOLEAN_test_here(text_line)) sect_type = ADD_YOUR_SECTION_TYPE_HERE; */ else { if (current_section_type == ZEROTH_SECT) sect_type = FMT_SECT; else sect_type = IN_SECT; } return(sect_type); }
int decompress_fd(int fdi, int fdo) { uint8_t header[6]; if (sizeof(header) != safe_read(fdi, header, sizeof(header))) { perror_msg("Failed to read header bytes"); return -1; } xlseek(fdi, 0, SEEK_SET); if (is_format("xz", header, sizeof(header), s_xz_magic, sizeof(s_xz_magic))) return decompress_fd_xz(fdi, fdo); if (is_format("lz4", header, sizeof(header), s_lz4_magic, sizeof(s_lz4_magic))) return decompress_fd_lz4(fdi, fdo); error_msg("Unsupported file format"); return -1; }
tree selection_compute (tree t, path start, path end) { int i1= start->item; int i2= end->item; path p1= start->next; path p2= end->next; if (is_nil (p1) || is_nil (p2)) { if (start == path (right_index (t))) return ""; if (end == path (0)) return ""; if (start == end) return ""; if (is_nil (p1) && is_nil (p2)) { if (is_compound (t)) return copy (t); if (i1>=i2) return ""; return t->label (i1, i2); } if (is_compound (t) && (!is_format (t))) return copy (t); if (is_nil (p1)) { i1= 0; p1= (start->item==0? 0: right_index (t[i1])); } if (is_nil (p2)) { i2= N(t)-1; p2= (end->item==0? 0: right_index (t[i2])); } } if (i1==i2) return selection_compute (t[i1], p1, p2); if (is_compound (t) && (!is_format (t))) return copy (t); int i; tree r (t, i2-i1+1); r[0] = selection_compute (t[i1], p1, path (right_index (t[i1]))); r[N(r)-1]= selection_compute (t[i2], path (0), p2); for (i=1; i<N(r)-1; i++) r[i]= copy (t[i+i1]); return r; }
void edit_select_rep::raw_cut (path p1, path p2) { if (p2 == p1) return; path p = common (p1, p2); tree t = subtree (et, p); int n = N(p); int i1= p1[n]; int i2= p2[n]; if (is_document (t) || is_concat (t)) { path q1= copy (p); q1 << path (i1, end (t[i1])); path q2= copy (p); q2 << path (i2, start (t[i2])); raw_cut (q2, p2); if (i2>i1+1) remove (p * (i1+1), i2-i1-1); raw_cut (p1, q1); if (is_concat (t)) correct_concat (p); else remove_return (p * i1); return; } if (is_func (t, TFORMAT) || is_func (t, TABLE) || is_func (t, ROW)) { path fp= ::table_search_format (et, p); tree st= subtree (et, fp); int row1, col1, row2, col2; table_search_coordinates (st, tail (p1, N(fp)), row1, col1); table_search_coordinates (st, tail (p2, N(fp)), row2, col2); if (row1>row2) { int tmp= row1; row1= row2; row2= tmp; } if (col1>col2) { int tmp= col1; col1= col2; col2= tmp; } int i, j; for (i=row1; i<=row2; i++) for (j=col1; j<=col2; j++) { path cp= fp * ::table_search_cell (st, i, j); if (is_func (subtree (et, cp), CELL, 1)) cp= cp * 0; assign (cp, ""); } path cp= fp * ::table_search_cell (st, row1, col1); go_to (cp * path (0, 0)); if (is_func (st, TFORMAT)) table_del_format (fp, row1+1, col1+1, row2+1, col2+1, ""); return; } if (is_compound (t) && (!is_format (t))) { assign (p, ""); return; } if ((N(p1) != (N(p)+1)) || (N(p2) != (N(p)+1))) { cerr << "t = " << t << "\n"; cerr << "p = " << p << "\n"; cerr << "p1= " << p1 << "\n"; cerr << "p2= " << p2 << "\n"; FAILED ("invalid cut"); } if (is_atomic (t)) { int pos= last_item (p1); int nr = last_item (p2)-pos; if (nr>0) remove (p1, nr); } else { if ((last_item (p1) != 0) || (last_item (p2) != 1)) { cerr << "t = " << t << "\n"; cerr << "p = " << p << "\n"; cerr << "p1= " << p1 << "\n"; cerr << "p2= " << p2 << "\n"; FAILED ("invalid object cut"); } assign (p, ""); } }