--- psiconv/trunk/lib/psiconv/data.c 2001/03/06 23:59:46 111 +++ psiconv/trunk/lib/psiconv/data.c 2002/01/29 18:38:38 142 @@ -24,6 +24,10 @@ #include "data.h" #include "list.h" +#ifdef DMALLOC +#include +#endif + static psiconv_color clone_color(psiconv_color color); static psiconv_font clone_font(psiconv_font font); static psiconv_border clone_border(psiconv_border border); @@ -36,6 +40,7 @@ static void psiconv_free_clipart_section_aux(void * section); static void psiconv_free_formula_aux(void *data); static void psiconv_free_sheet_worksheet_aux (void *data); +static void psiconv_free_sheet_variable_aux(void * variable); static psiconv_word_styles_section psiconv_empty_word_styles_section(void); static psiconv_text_and_layout psiconv_empty_text_and_layout(void); @@ -319,6 +324,34 @@ return psiconv_list_get(ss->styles,0xff - nr); } +psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) +{ + return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); +} + +/* TODO: What if a cell is both in a default row and a default column?!? */ +psiconv_sheet_cell_layout psiconv_get_default_layout + (psiconv_sheet_line_list row_defaults, + psiconv_sheet_line_list col_defaults, + psiconv_sheet_cell_layout cell_default, + int row,int col) +{ + int i; + psiconv_sheet_line line; + for (i = 0;i < psiconv_list_length(row_defaults);i++) { + line = psiconv_list_get(row_defaults,i); + if (line->position == row) + return line->layout; + } + for (i = 0;i < psiconv_list_length(col_defaults);i++) { + line = psiconv_list_get(col_defaults,i); + if (line->position == col) + return line->layout; + } + return cell_default; +} + + void psiconv_free_color (psiconv_color color) { if (color) @@ -563,28 +596,79 @@ psiconv_free_sheet_numberformat(layout->numberformat); } +void psiconv_free_sheet_cell_aux(void *cell) +{ + psiconv_sheet_cell data = cell; + + psiconv_free_sheet_cell_layout(data->layout); + + if ((data->type == psiconv_cell_string) && (data->data.dat_string)) + free(data->data.dat_string); +} + void psiconv_free_sheet_cell(psiconv_sheet_cell cell) { if (cell) { - psiconv_free_sheet_cell_layout(cell->layout); - - if ((cell->type == psiconv_cell_string) && (cell->data.dat_string)) - free(cell->data.dat_string); + psiconv_free_sheet_cell_aux(cell); free(cell); } } -void psiconv_free_sheet_cell_aux(void *data) +void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list) { - psiconv_sheet_cell cell; - cell = data; - psiconv_free_sheet_cell(cell); + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); } -void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list) +void psiconv_free_sheet_line_aux(void *line) +{ + psiconv_sheet_line data = line; + + psiconv_free_sheet_cell_layout(data->layout); +} + +void psiconv_free_sheet_line(psiconv_sheet_line line) +{ + if (line) { + psiconv_free_sheet_line_aux(line); + free(line); + } +} + + +void psiconv_free_sheet_line_list(psiconv_sheet_line_list list) { if (list) - psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); + psiconv_list_free_el(list,psiconv_free_sheet_line_aux); +} + +void psiconv_free_sheet_grid_break_list(psiconv_sheet_grid_break_list list) +{ + if (list) + psiconv_list_free(list); +} + +void psiconv_free_sheet_grid_size(psiconv_sheet_grid_size s) +{ + if (s) + free(s); +} + +void psiconv_free_sheet_grid_size_list(psiconv_sheet_grid_size_list list) +{ + if (list) + psiconv_list_free(list); +} + +void psiconv_free_sheet_grid_section(psiconv_sheet_grid_section sec) +{ + if (sec) { + psiconv_free_sheet_grid_size_list(sec->row_heights); + psiconv_free_sheet_grid_size_list(sec->column_heights); + psiconv_free_sheet_grid_break_list(sec->row_page_breaks); + psiconv_free_sheet_grid_break_list(sec->column_page_breaks); + free(sec); + } } void psiconv_free_sheet_worksheet_aux (void *data) @@ -592,6 +676,9 @@ psiconv_sheet_worksheet section = data; psiconv_free_sheet_cell_layout(section->default_layout); psiconv_free_sheet_cell_list(section->cells); + psiconv_free_sheet_line_list(section->row_default_layouts); + psiconv_free_sheet_line_list(section->col_default_layouts); + psiconv_free_sheet_grid_section(section->grid); } void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) @@ -641,11 +728,53 @@ psiconv_list_free_el(list,psiconv_free_formula_aux); } +void psiconv_free_sheet_name_section(psiconv_sheet_name_section section) +{ + if (section) { + if(section->name) + free(section->name); + free(section); + } +} + +void psiconv_free_sheet_info_section(psiconv_sheet_info_section section) +{ + if (section) { + free(section); + } +} + +void psiconv_free_sheet_variable_aux(void * variable) +{ + psiconv_sheet_variable var = variable; + if (var->name) + free(var->name); + if (var->type == psiconv_var_string) + free(var->data.dat_string); +} + +void psiconv_free_sheet_variable(psiconv_sheet_variable var) +{ + if (var) { + psiconv_free_sheet_variable_aux(var); + free(var); + } +} + +void psiconv_free_sheet_variable_list(psiconv_sheet_variable_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_variable_aux); +} + void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) { if (section) { psiconv_free_formula_list(section->formulas); - psiconv_free_sheet_worksheet_list(section->worksheets); + psiconv_free_sheet_worksheet_list(section->worksheets); + psiconv_free_sheet_name_section(section->name); + psiconv_free_sheet_info_section(section->info); + psiconv_free_sheet_variable_list(section->variables); free(section); } }