--- psiconv/trunk/lib/psiconv/data.c 2001/01/17 00:05:08 94 +++ psiconv/trunk/lib/psiconv/data.c 2001/07/24 20:32:51 129 @@ -34,6 +34,9 @@ static void psiconv_free_paragraph_aux(void * paragraph); static void psiconv_free_paint_data_section_aux(void * section); 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); @@ -43,6 +46,9 @@ static psiconv_word_status_section psiconv_empty_word_status_section(void); static psiconv_word_f psiconv_empty_word_f(void); static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void); +static psiconv_formula_list psiconv_empty_formula_list(void); +static psiconv_sheet_workbook_section + psiconv_empty_sheet_workbook_section(void); static psiconv_sheet_f psiconv_empty_sheet_f(void); static psiconv_texted_f psiconv_empty_texted_f(void); static psiconv_paint_data_section psiconv_empty_paint_data_section(void); @@ -149,6 +155,7 @@ psiconv_bool_false, /* keep_with_next */ psiconv_bool_false, /* on_next_page */ psiconv_bool_false, /* no_widow_protection */ + psiconv_bool_false, /* wrap_to_fit_cell */ 0.0, /* left_margin */ &bullet, /* bullet */ &no_border, /* left_border */ @@ -313,6 +320,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) @@ -544,11 +579,177 @@ free(section); } +void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat) +{ + if (numberformat) + free(numberformat); +} + +void psiconv_free_sheet_cell_layout(psiconv_sheet_cell_layout layout) +{ + psiconv_free_paragraph_layout(layout->paragraph); + psiconv_free_character_layout(layout->character); + 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_aux(cell); + free(cell); + } +} + +void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); +} + +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_line_aux); +} + +void psiconv_free_sheet_worksheet_aux (void *data) +{ + 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); +} + +void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) +{ + if (sheet) { + psiconv_free_sheet_worksheet_aux(sheet); + free(sheet); + } +} + +void psiconv_free_sheet_worksheet_list(psiconv_sheet_worksheet_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_worksheet_aux); +} + +void psiconv_free_formula_aux(void *data) +{ + psiconv_formula formula; + formula = data; + if (formula->type == psiconv_formula_dat_string) + free(formula->data.dat_string); + else if ((formula->type != psiconv_formula_dat_int) && + (formula->type != psiconv_formula_dat_var) && + (formula->type != psiconv_formula_dat_float) && + (formula->type != psiconv_formula_dat_cellref) && + (formula->type != psiconv_formula_dat_cellblock) && + (formula->type != psiconv_formula_dat_vcellblock) && + (formula->type != psiconv_formula_mark_opsep) && + (formula->type != psiconv_formula_mark_opend) && + (formula->type != psiconv_formula_mark_eof) && + (formula->type != psiconv_formula_unknown)) + psiconv_free_formula_list(formula->data.fun_operands); +} + +void psiconv_free_formula(psiconv_formula formula) +{ + if (formula) { + psiconv_free_formula_aux(formula); + free(formula); + } +} + +void psiconv_free_formula_list(psiconv_formula_list list) +{ + if (list) + 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_name_section(section->name); + psiconv_free_sheet_info_section(section->info); + psiconv_free_sheet_variable_list(section->variables); + free(section); + } +} + void psiconv_free_sheet_f(psiconv_sheet_f file) { if (file) { psiconv_free_page_layout_section(file->page_sec); psiconv_free_sheet_status_section(file->status_sec); + psiconv_free_sheet_workbook_section(file->workbook_sec); free(file); } } @@ -955,6 +1156,26 @@ return result; } +psiconv_formula_list psiconv_empty_formula_list(void) +{ + return psiconv_list_new(sizeof(struct psiconv_formula_s)); +} + +psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void) +{ + psiconv_sheet_workbook_section result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->formulas = psiconv_empty_formula_list())) + goto ERROR2; + return result; +ERROR2: + free(result); +ERROR1: + return NULL; +} + + psiconv_sheet_f psiconv_empty_sheet_f(void) { psiconv_sheet_f result; @@ -964,7 +1185,11 @@ goto ERROR2; if (!(result->status_sec = psiconv_empty_sheet_status_section())) goto ERROR3; + if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section())) + goto ERROR4; return result; +ERROR4: + psiconv_free_sheet_status_section(result->status_sec); ERROR3: psiconv_free_page_layout_section(result->page_sec); ERROR2: