1 | /* |
1 | /* |
2 | parse_sheet.c - Part of psiconv, a PSION 5 file formats converter |
2 | parse_sheet.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 2001 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 2000-2014 Frodo Looijaard <frodo@frodo.looijaard.name> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
131 | |
131 | |
132 | psiconv_progress(config,lev,off+len-1, |
132 | psiconv_progress(config,lev,off+len-1, |
133 | "End of sheet column reference (total length: %08x)", len); |
133 | "End of sheet column reference (total length: %08x)", len); |
134 | return result; |
134 | return result; |
135 | ERROR1: |
135 | ERROR1: |
136 | psiconv_warn(config,lev+1,off,"Reading of Sheet Column Reference failed"); |
136 | psiconv_error(config,lev+1,off,"Reading of Sheet Column Reference failed"); |
137 | if (length) |
137 | if (length) |
138 | *length = 0; |
138 | *length = 0; |
139 | if (status) |
139 | if (status) |
140 | *status = res?res:-PSICONV_E_NOMEM; |
140 | *status = res?res:-PSICONV_E_NOMEM; |
141 | return result; |
141 | return result; |
… | |
… | |
215 | psiconv_progress(config,lev,off+len-1, |
215 | psiconv_progress(config,lev,off+len-1, |
216 | "End of sheet cell block reference (total length: %08x)", |
216 | "End of sheet cell block reference (total length: %08x)", |
217 | len); |
217 | len); |
218 | return result; |
218 | return result; |
219 | ERROR1: |
219 | ERROR1: |
220 | psiconv_warn(config,lev+1,off,"Reading of Sheet Cell Block Reference failed"); |
220 | psiconv_error(config,lev+1,off,"Reading of Sheet Cell Block Reference failed"); |
221 | if (length) |
221 | if (length) |
222 | *length = 0; |
222 | *length = 0; |
223 | if (status) |
223 | if (status) |
224 | *status = res?res:-PSICONV_E_NOMEM; |
224 | *status = res?res:-PSICONV_E_NOMEM; |
225 | return result; |
225 | return result; |
… | |
… | |
334 | psiconv_progress(config,lev,off+len-1, |
334 | psiconv_progress(config,lev,off+len-1, |
335 | "End of sheet number format (total length: %08x)", len); |
335 | "End of sheet number format (total length: %08x)", len); |
336 | return 0; |
336 | return 0; |
337 | |
337 | |
338 | ERROR1: |
338 | ERROR1: |
339 | psiconv_warn(config,lev+1,off,"Reading of Sheet Number Format failed"); |
339 | psiconv_error(config,lev+1,off,"Reading of Sheet Number Format failed"); |
340 | if (length) |
340 | if (length) |
341 | *length = 0; |
341 | *length = 0; |
342 | if (!res) |
342 | if (!res) |
343 | return -PSICONV_E_NOMEM; |
343 | return -PSICONV_E_NOMEM; |
344 | else |
344 | else |
… | |
… | |
492 | return 0; |
492 | return 0; |
493 | |
493 | |
494 | ERROR2: |
494 | ERROR2: |
495 | free (*result); |
495 | free (*result); |
496 | ERROR1: |
496 | ERROR1: |
497 | psiconv_warn(config,lev+1,off,"Reading of Sheet Status Section failed"); |
497 | psiconv_error(config,lev+1,off,"Reading of Sheet Status Section failed"); |
498 | if (length) |
498 | if (length) |
499 | *length = 0; |
499 | *length = 0; |
500 | if (!res) |
500 | if (!res) |
501 | return -PSICONV_E_NOMEM; |
501 | return -PSICONV_E_NOMEM; |
502 | else |
502 | else |
… | |
… | |
617 | ERROR3: |
617 | ERROR3: |
618 | psiconv_free_sheet_info_section((*result)->info); |
618 | psiconv_free_sheet_info_section((*result)->info); |
619 | ERROR2: |
619 | ERROR2: |
620 | free (*result); |
620 | free (*result); |
621 | ERROR1: |
621 | ERROR1: |
622 | psiconv_warn(config,lev+1,off,"Reading of Sheet Workbook Section failed"); |
622 | psiconv_error(config,lev+1,off,"Reading of Sheet Workbook Section failed"); |
623 | if (length) |
623 | if (length) |
624 | *length = 0; |
624 | *length = 0; |
625 | if (!res) |
625 | if (!res) |
626 | return -PSICONV_E_NOMEM; |
626 | return -PSICONV_E_NOMEM; |
627 | else |
627 | else |
… | |
… | |
667 | return 0; |
667 | return 0; |
668 | |
668 | |
669 | ERROR2: |
669 | ERROR2: |
670 | free(*result); |
670 | free(*result); |
671 | ERROR1: |
671 | ERROR1: |
672 | psiconv_warn(config,lev+1,off,"Reading of Sheet Name Section failed"); |
672 | psiconv_error(config,lev+1,off,"Reading of Sheet Name Section failed"); |
673 | if (length) |
673 | if (length) |
674 | *length = 0; |
674 | *length = 0; |
675 | if (!res) |
675 | if (!res) |
676 | return -PSICONV_E_NOMEM; |
676 | return -PSICONV_E_NOMEM; |
677 | else |
677 | else |
… | |
… | |
734 | return 0; |
734 | return 0; |
735 | |
735 | |
736 | ERROR2: |
736 | ERROR2: |
737 | free(*result); |
737 | free(*result); |
738 | ERROR1: |
738 | ERROR1: |
739 | psiconv_warn(config,lev+1,off,"Reading of Sheet Name Section failed"); |
739 | psiconv_error(config,lev+1,off,"Reading of Sheet Name Section failed"); |
740 | if (length) |
740 | if (length) |
741 | *length = 0; |
741 | *length = 0; |
742 | if (!res) |
742 | if (!res) |
743 | return -PSICONV_E_NOMEM; |
743 | return -PSICONV_E_NOMEM; |
744 | else |
744 | else |
… | |
… | |
802 | ERROR3: |
802 | ERROR3: |
803 | psiconv_free_formula(formula); |
803 | psiconv_free_formula(formula); |
804 | ERROR2: |
804 | ERROR2: |
805 | psiconv_list_free(*result); |
805 | psiconv_list_free(*result); |
806 | ERROR1: |
806 | ERROR1: |
807 | psiconv_warn(config,lev+1,off,"Reading of Sheet Formula list failed"); |
807 | psiconv_error(config,lev+1,off,"Reading of Sheet Formula list failed"); |
808 | if (length) |
808 | if (length) |
809 | *length = 0; |
809 | *length = 0; |
810 | if (!res) |
810 | if (!res) |
811 | return -PSICONV_E_NOMEM; |
811 | return -PSICONV_E_NOMEM; |
812 | else |
812 | else |
… | |
… | |
926 | psiconv_progress(config,lev+2,off+len,"Going to read a string"); |
926 | psiconv_progress(config,lev+2,off+len,"Going to read a string"); |
927 | (*result)->data.dat_string = |
927 | (*result)->data.dat_string = |
928 | psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
928 | psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
929 | if (res) |
929 | if (res) |
930 | goto ERROR2; |
930 | goto ERROR2; |
931 | if (!(auxstr = psiconv_make_printable((*result)->data.dat_string))) |
931 | if (!(auxstr = psiconv_make_printable(config,(*result)->data.dat_string))) |
932 | goto ERROR2; |
932 | goto ERROR2; |
933 | psiconv_debug(config,lev+2,off+len,"Cell contents: `%s'",auxstr); |
933 | psiconv_debug(config,lev+2,off+len,"Cell contents: `%s'",auxstr); |
934 | free(auxstr); |
934 | free(auxstr); |
935 | len += leng; |
935 | len += leng; |
936 | } else { |
936 | } else { |
937 | psiconv_warn(config,lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
937 | psiconv_error(config,lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
938 | res = PSICONV_E_PARSE; |
938 | res = PSICONV_E_PARSE; |
939 | goto ERROR2; |
939 | goto ERROR2; |
940 | } |
940 | } |
941 | |
941 | |
942 | if (!((*result)->layout = psiconv_clone_cell_layout( |
942 | if (!((*result)->layout = psiconv_clone_cell_layout( |
… | |
… | |
1056 | ERROR3: |
1056 | ERROR3: |
1057 | psiconv_free_sheet_cell(cell); |
1057 | psiconv_free_sheet_cell(cell); |
1058 | ERROR2: |
1058 | ERROR2: |
1059 | psiconv_free_sheet_cell_list(*result); |
1059 | psiconv_free_sheet_cell_list(*result); |
1060 | ERROR1: |
1060 | ERROR1: |
1061 | psiconv_warn(config,lev+1,off,"Reading of Sheet Cells List failed"); |
1061 | psiconv_error(config,lev+1,off,"Reading of Sheet Cells List failed"); |
1062 | if (length) |
1062 | if (length) |
1063 | *length = 0; |
1063 | *length = 0; |
1064 | if (!res) |
1064 | if (!res) |
1065 | return -PSICONV_E_NOMEM; |
1065 | return -PSICONV_E_NOMEM; |
1066 | else |
1066 | else |
… | |
… | |
1144 | ERROR3: |
1144 | ERROR3: |
1145 | psiconv_free_sheet_worksheet(worksheet); |
1145 | psiconv_free_sheet_worksheet(worksheet); |
1146 | ERROR2: |
1146 | ERROR2: |
1147 | psiconv_free_sheet_worksheet_list(*result); |
1147 | psiconv_free_sheet_worksheet_list(*result); |
1148 | ERROR1: |
1148 | ERROR1: |
1149 | psiconv_warn(config,lev+1,off,"Reading of worksheet list failed"); |
1149 | psiconv_error(config,lev+1,off,"Reading of worksheet list failed"); |
1150 | if (length) |
1150 | if (length) |
1151 | *length = 0; |
1151 | *length = 0; |
1152 | if (!res) |
1152 | if (!res) |
1153 | return -PSICONV_E_NOMEM; |
1153 | return -PSICONV_E_NOMEM; |
1154 | else |
1154 | else |
… | |
… | |
1216 | "End of sheet cell layout (total length: %08x)", len); |
1216 | "End of sheet cell layout (total length: %08x)", len); |
1217 | |
1217 | |
1218 | return 0; |
1218 | return 0; |
1219 | |
1219 | |
1220 | ERROR1: |
1220 | ERROR1: |
1221 | psiconv_warn(config,lev+1,off,"Reading of sheet cell layout failed"); |
1221 | psiconv_error(config,lev+1,off,"Reading of sheet cell layout failed"); |
1222 | if (length) |
1222 | if (length) |
1223 | *length = 0; |
1223 | *length = 0; |
1224 | if (!res) |
1224 | if (!res) |
1225 | return -PSICONV_E_NOMEM; |
1225 | return -PSICONV_E_NOMEM; |
1226 | else |
1226 | else |
… | |
… | |
1371 | ERROR3: |
1371 | ERROR3: |
1372 | psiconv_free_sheet_cell_layout((*result)->default_layout); |
1372 | psiconv_free_sheet_cell_layout((*result)->default_layout); |
1373 | ERROR2: |
1373 | ERROR2: |
1374 | free (*result); |
1374 | free (*result); |
1375 | ERROR1: |
1375 | ERROR1: |
1376 | psiconv_warn(config,lev+1,off,"Reading of Sheet Worksheet Section failed"); |
1376 | psiconv_error(config,lev+1,off,"Reading of Sheet Worksheet Section failed"); |
1377 | if (length) |
1377 | if (length) |
1378 | *length = 0; |
1378 | *length = 0; |
1379 | if (!res) |
1379 | if (!res) |
1380 | return -PSICONV_E_NOMEM; |
1380 | return -PSICONV_E_NOMEM; |
1381 | else |
1381 | else |
… | |
… | |
1421 | ERROR3: |
1421 | ERROR3: |
1422 | psiconv_free_sheet_cell_layout((*result)->layout); |
1422 | psiconv_free_sheet_cell_layout((*result)->layout); |
1423 | ERROR2: |
1423 | ERROR2: |
1424 | free (*result); |
1424 | free (*result); |
1425 | ERROR1: |
1425 | ERROR1: |
1426 | psiconv_warn(config,lev+1,off,"Reading of the sheet line failed"); |
1426 | psiconv_error(config,lev+1,off,"Reading of the sheet line failed"); |
1427 | if (length) |
1427 | if (length) |
1428 | *length = 0; |
1428 | *length = 0; |
1429 | if (!res) |
1429 | if (!res) |
1430 | return -PSICONV_E_NOMEM; |
1430 | return -PSICONV_E_NOMEM; |
1431 | else |
1431 | else |
… | |
… | |
1492 | ERROR3: |
1492 | ERROR3: |
1493 | psiconv_free_sheet_line(line); |
1493 | psiconv_free_sheet_line(line); |
1494 | ERROR2: |
1494 | ERROR2: |
1495 | psiconv_free_sheet_line_list(*result); |
1495 | psiconv_free_sheet_line_list(*result); |
1496 | ERROR1: |
1496 | ERROR1: |
1497 | psiconv_warn(config,lev+1,off,"Reading of Sheet Line List failed"); |
1497 | psiconv_error(config,lev+1,off,"Reading of Sheet Line List failed"); |
1498 | if (length) |
1498 | if (length) |
1499 | *length = 0; |
1499 | *length = 0; |
1500 | if (!res) |
1500 | if (!res) |
1501 | return -PSICONV_E_NOMEM; |
1501 | return -PSICONV_E_NOMEM; |
1502 | else |
1502 | else |
… | |
… | |
1571 | &leng, &res); |
1571 | &leng, &res); |
1572 | if (res) |
1572 | if (res) |
1573 | goto ERROR3; |
1573 | goto ERROR3; |
1574 | len += leng; |
1574 | len += leng; |
1575 | } else { |
1575 | } else { |
1576 | psiconv_warn(config,lev+2,off+len,"Sheet variable unknown type marker"); |
1576 | psiconv_error(config,lev+2,off+len,"Sheet variable unknown type marker"); |
1577 | res = -PSICONV_E_PARSE; |
1577 | res = -PSICONV_E_PARSE; |
1578 | goto ERROR3; |
1578 | goto ERROR3; |
1579 | } |
1579 | } |
1580 | |
1580 | |
1581 | psiconv_progress(config,lev+2,off+len,"Going to read the variable number"); |
1581 | psiconv_progress(config,lev+2,off+len,"Going to read the variable number"); |
… | |
… | |
1598 | ERROR3: |
1598 | ERROR3: |
1599 | free((*result)->name); |
1599 | free((*result)->name); |
1600 | ERROR2: |
1600 | ERROR2: |
1601 | free (*result); |
1601 | free (*result); |
1602 | ERROR1: |
1602 | ERROR1: |
1603 | psiconv_warn(config,lev+1,off,"Reading of Sheet Variable failed"); |
1603 | psiconv_error(config,lev+1,off,"Reading of Sheet Variable failed"); |
1604 | if (length) |
1604 | if (length) |
1605 | *length = 0; |
1605 | *length = 0; |
1606 | if (!res) |
1606 | if (!res) |
1607 | return -PSICONV_E_NOMEM; |
1607 | return -PSICONV_E_NOMEM; |
1608 | else |
1608 | else |
… | |
… | |
1666 | ERROR3: |
1666 | ERROR3: |
1667 | psiconv_free_sheet_variable(variable); |
1667 | psiconv_free_sheet_variable(variable); |
1668 | ERROR2: |
1668 | ERROR2: |
1669 | psiconv_list_free(*result); |
1669 | psiconv_list_free(*result); |
1670 | ERROR1: |
1670 | ERROR1: |
1671 | psiconv_warn(config,lev+1,off,"Reading of Sheet Variable list failed"); |
1671 | psiconv_error(config,lev+1,off,"Reading of Sheet Variable list failed"); |
1672 | if (length) |
1672 | if (length) |
1673 | *length = 0; |
1673 | *length = 0; |
1674 | if (!res) |
1674 | if (!res) |
1675 | return -PSICONV_E_NOMEM; |
1675 | return -PSICONV_E_NOMEM; |
1676 | else |
1676 | else |
… | |
… | |
1934 | ERROR3: |
1934 | ERROR3: |
1935 | psiconv_free_sheet_grid_size_list((*result)->row_heights); |
1935 | psiconv_free_sheet_grid_size_list((*result)->row_heights); |
1936 | ERROR2: |
1936 | ERROR2: |
1937 | free(*result); |
1937 | free(*result); |
1938 | ERROR1: |
1938 | ERROR1: |
1939 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Section failed"); |
1939 | psiconv_error(config,lev+1,off,"Reading of Sheet Grid Section failed"); |
1940 | if (length) |
1940 | if (length) |
1941 | *length = 0; |
1941 | *length = 0; |
1942 | if (!res) |
1942 | if (!res) |
1943 | return -PSICONV_E_NOMEM; |
1943 | return -PSICONV_E_NOMEM; |
1944 | else |
1944 | else |
… | |
… | |
1989 | ERROR3: |
1989 | ERROR3: |
1990 | psiconv_free_sheet_grid_size(size); |
1990 | psiconv_free_sheet_grid_size(size); |
1991 | ERROR2: |
1991 | ERROR2: |
1992 | psiconv_list_free(*result); |
1992 | psiconv_list_free(*result); |
1993 | ERROR1: |
1993 | ERROR1: |
1994 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Size List failed"); |
1994 | psiconv_error(config,lev+1,off,"Reading of Sheet Grid Size List failed"); |
1995 | if (length) |
1995 | if (length) |
1996 | *length = 0; |
1996 | *length = 0; |
1997 | if (!res) |
1997 | if (!res) |
1998 | return -PSICONV_E_NOMEM; |
1998 | return -PSICONV_E_NOMEM; |
1999 | else |
1999 | else |
… | |
… | |
2036 | return 0; |
2036 | return 0; |
2037 | |
2037 | |
2038 | ERROR2: |
2038 | ERROR2: |
2039 | free (*result); |
2039 | free (*result); |
2040 | ERROR1: |
2040 | ERROR1: |
2041 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Size failed"); |
2041 | psiconv_error(config,lev+1,off,"Reading of Sheet Grid Size failed"); |
2042 | if (length) |
2042 | if (length) |
2043 | *length = 0; |
2043 | *length = 0; |
2044 | if (!res) |
2044 | if (!res) |
2045 | return -PSICONV_E_NOMEM; |
2045 | return -PSICONV_E_NOMEM; |
2046 | else |
2046 | else |
… | |
… | |
2089 | return 0; |
2089 | return 0; |
2090 | |
2090 | |
2091 | ERROR2: |
2091 | ERROR2: |
2092 | psiconv_list_free(*result); |
2092 | psiconv_list_free(*result); |
2093 | ERROR1: |
2093 | ERROR1: |
2094 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid break List failed"); |
2094 | psiconv_error(config,lev+1,off,"Reading of Sheet Grid break List failed"); |
2095 | if (length) |
2095 | if (length) |
2096 | *length = 0; |
2096 | *length = 0; |
2097 | if (!res) |
2097 | if (!res) |
2098 | return -PSICONV_E_NOMEM; |
2098 | return -PSICONV_E_NOMEM; |
2099 | else |
2099 | else |