/[public]/psiconv/trunk/lib/psiconv/parse_sheet.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_sheet.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 127 Revision 128
505} 505}
506 506
507int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, 507int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev,
508 psiconv_u32 off, int *length, 508 psiconv_u32 off, int *length,
509 psiconv_sheet_cell *result, 509 psiconv_sheet_cell *result,
510 const psiconv_sheet_cell_layout default_layout) 510 const psiconv_sheet_cell_layout default_layout,
511 const psiconv_sheet_line_list row_default_layouts,
512 const psiconv_sheet_line_list col_default_layouts)
511{ 513{
512 int res=0; 514 int res=0;
513 int len=0; 515 int len=0;
514 psiconv_u32 temp; 516 psiconv_u32 temp;
515 psiconv_bool_t has_layout; 517 psiconv_bool_t has_layout;
622 psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); 624 psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type);
623 res = PSICONV_E_PARSE; 625 res = PSICONV_E_PARSE;
624 goto ERROR2; 626 goto ERROR2;
625 } 627 }
626 628
627 if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) 629 if (!((*result)->layout = psiconv_clone_cell_layout(
630 psiconv_get_default_layout(row_default_layouts,
631 col_default_layouts,
632 default_layout,
633 (*result)->row,
634 (*result)->column))))
628 goto ERROR2; 635 goto ERROR2;
629 if (has_layout) { 636 if (has_layout) {
630 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, 637 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,
631 &leng,(*result)->layout))) 638 &leng,(*result)->layout)))
632 goto ERROR2; 639 goto ERROR2;
661 else 668 else
662 return res; 669 return res;
663} 670}
664 671
665int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, 672int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev,
666 psiconv_u32 off, int *length, 673 psiconv_u32 off, int *length,
667 psiconv_sheet_cell_list *result, 674 psiconv_sheet_cell_list *result,
668 const psiconv_sheet_cell_layout default_layout) 675 const psiconv_sheet_cell_layout default_layout,
676 const psiconv_sheet_line_list row_default_layouts,
677 const psiconv_sheet_line_list col_default_layouts)
669{ 678{
670 int res=0; 679 int res=0;
671 int len=0; 680 int len=0;
672 psiconv_u32 temp; 681 psiconv_u32 temp;
673 psiconv_sheet_cell cell; 682 psiconv_sheet_cell cell;
712 721
713 psiconv_progress(lev+2,off+len,"Going to read all cells"); 722 psiconv_progress(lev+2,off+len,"Going to read all cells");
714 for (i = 0; i < listlen; i++) { 723 for (i = 0; i < listlen; i++) {
715 psiconv_progress(lev+3,off+len,"Going to read cell %d",i); 724 psiconv_progress(lev+3,off+len,"Going to read cell %d",i);
716 if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell, 725 if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell,
726 default_layout,row_default_layouts,
717 default_layout))) 727 col_default_layouts)))
718 goto ERROR2; 728 goto ERROR2;
719 if ((res = psiconv_list_add(*result,cell))) 729 if ((res = psiconv_list_add(*result,cell)))
720 goto ERROR3; 730 goto ERROR3;
721 free(cell); 731 free(cell);
722 len += leng; 732 len += leng;
905int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, 915int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev,
906 psiconv_u32 off, int *length, 916 psiconv_u32 off, int *length,
907 psiconv_sheet_worksheet *result) 917 psiconv_sheet_worksheet *result)
908{ 918{
909 int res=0; 919 int res=0;
910 psiconv_u32 temp,cells_off,grid_off; 920 psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off;
911 int len=0; 921 int len=0;
912 int leng; 922 int leng;
913 923
914 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); 924 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section");
915 if (!(*result = malloc(sizeof(**result)))) 925 if (!(*result = malloc(sizeof(**result))))
946 (*result)->default_layout))) 956 (*result)->default_layout)))
947 goto ERROR3; 957 goto ERROR3;
948 len += leng; 958 len += leng;
949 959
950 psiconv_progress(lev+2,off+len, 960 psiconv_progress(lev+2,off+len,
961 "Going to read the offset of the row defaults Section");
962 rows_off = psiconv_read_u32(buf,lev+2,off+len,&res);
963 if (res)
964 goto ERROR3;
965 psiconv_debug(lev+2,off+len,"Offset: %04x",rows_off);
966 len += 4;
967
968 psiconv_progress(lev+2,off+len,
969 "Going to read the offset of the column defaults Section");
970 cols_off = psiconv_read_u32(buf,lev+2,off+len,&res);
971 if (res)
972 goto ERROR3;
973 psiconv_debug(lev+2,off+len,"Offset: %04x",cols_off);
974 len += 4;
975
976 psiconv_progress(lev+2,off+len,
977 "Going to read the offset of the Cells List");
978 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res);
979 if (res)
980 goto ERROR3;
981 psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off);
982 len += 4;
983
984 psiconv_progress(lev+2,off+len,
985 "Going to read the offset of the Grid Section");
986 grid_off = psiconv_read_u32(buf,lev+2,off+len,&res);
987 if (res)
988 goto ERROR3;
989 psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off);
990 len += 4;
991
992 psiconv_progress(lev+2,off+len,
951 "Going to read the offset of the 1st ??? Section"); 993 "Going to read the offset of the 3rd ??? Section");
952 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 994 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
953 if (res) 995 if (res)
954 goto ERROR3; 996 goto ERROR3;
955 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 997 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
956 len += 4; 998 len += 4;
957 999
958 psiconv_progress(lev+2,off+len, 1000 psiconv_progress(lev+2,off+len,"Going to read the row defaults");
959 "Going to read the offset of the 2nd ??? Section"); 1001 if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL,
960 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 1002 &(*result)->row_default_layouts,
961 if (res) 1003 (*result)->default_layout)))
962 goto ERROR3; 1004 goto ERROR3;
963 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
964 len += 4;
965 1005
966 psiconv_progress(lev+2,off+len, 1006 psiconv_progress(lev+2,off+len,"Going to read the column defaults");
967 "Going to read the offset of the Cells List"); 1007 if ((res = psiconv_parse_sheet_line_list(buf,lev+2,cols_off,NULL,
968 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); 1008 &(*result)->col_default_layouts,
969 if (res) 1009 (*result)->default_layout)))
970 goto ERROR3; 1010 goto ERROR4;
971 psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off);
972 len += 4;
973
974 psiconv_progress(lev+2,off+len,
975 "Going to read the offset of the Grid Section");
976 grid_off = psiconv_read_u32(buf,lev+2,off+len,&res);
977 if (res)
978 goto ERROR3;
979 psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off);
980 len += 4;
981
982 psiconv_progress(lev+2,off+len,
983 "Going to read the offset of the 3rd ??? Section");
984 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
985 if (res)
986 goto ERROR3;
987 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
988 len += 4;
989 1011
990 psiconv_progress(lev+2,off+len,"Going to read the cells list"); 1012 psiconv_progress(lev+2,off+len,"Going to read the cells list");
991 if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, 1013 if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL,
992 &(*result)->cells, 1014 &(*result)->cells,
993 (*result)->default_layout))) 1015 (*result)->default_layout,
1016 (*result)->row_default_layouts,
1017 (*result)->col_default_layouts)))
994 goto ERROR3; 1018 goto ERROR5;
995 1019
996 1020
997/* TODO: parse grid section */ 1021/* TODO: parse grid section */
998 1022
999 if (length) 1023 if (length)
1001 1025
1002 psiconv_progress(lev,off+len-1, 1026 psiconv_progress(lev,off+len-1,
1003 "End of sheet worksheet section (total length: %08x)", len); 1027 "End of sheet worksheet section (total length: %08x)", len);
1004 return 0; 1028 return 0;
1005 1029
1030ERROR5:
1031 psiconv_free_sheet_line_list((*result)->col_default_layouts);
1032ERROR4:
1033 psiconv_free_sheet_line_list((*result)->row_default_layouts);
1006ERROR3: 1034ERROR3:
1007 psiconv_free_sheet_cell_layout((*result)->default_layout); 1035 psiconv_free_sheet_cell_layout((*result)->default_layout);
1008ERROR2: 1036ERROR2:
1009 free (*result); 1037 free (*result);
1010ERROR1: 1038ERROR1:
1015 return -PSICONV_E_NOMEM; 1043 return -PSICONV_E_NOMEM;
1016 else 1044 else
1017 return res; 1045 return res;
1018} 1046}
1019 1047
1048int psiconv_parse_sheet_line(const psiconv_buffer buf, int lev,
1049 psiconv_u32 off, int *length,
1050 psiconv_sheet_line *result,
1051 const psiconv_sheet_cell_layout default_layout)
1052{
1053 int res=0;
1054 int len=0;
1055 int leng;
1020 1056
1057
1058 psiconv_progress(lev+1,off,"Going to read a sheet line");
1059 if (!(*result = malloc(sizeof(**result))))
1060 goto ERROR1;
1061
1062 psiconv_progress(lev+2,off+len,"Going to read the line number");
1063 (*result)->position = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
1064 if (res)
1065 goto ERROR2;
1066 psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->position);
1067 len += leng;
1068
1069 if (!((*result)->layout = psiconv_clone_cell_layout(default_layout)))
1070 goto ERROR2;
1071 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,
1072 &leng,(*result)->layout)))
1073 goto ERROR3;
1074 len += leng;
1075
1076 if (length)
1077 *length = len;
1078
1079 psiconv_progress(lev,off+len-1,
1080 "End of the sheet line (total length: %08x)", len);
1081 return 0;
1082
1083ERROR3:
1084 psiconv_free_sheet_cell_layout((*result)->layout);
1085ERROR2:
1086 free (*result);
1087ERROR1:
1088 psiconv_warn(lev+1,off,"Reading of the sheet line failed");
1089 if (length)
1090 *length = 0;
1091 if (!res)
1092 return -PSICONV_E_NOMEM;
1093 else
1094 return res;
1095}
1096
1097
1098int psiconv_parse_sheet_line_list(const psiconv_buffer buf, int lev,
1099 psiconv_u32 off, int *length,
1100 psiconv_sheet_line_list *result,
1101 const psiconv_sheet_cell_layout default_layout)
1102{
1103 int res=0;
1104 int len=0;
1105 psiconv_u32 temp;
1106 psiconv_sheet_line line;
1107 psiconv_u32 listlen,i;
1108 int leng;
1109
1110 psiconv_progress(lev+1,off,"Going to read the sheet line list");
1111 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s))))
1112 goto ERROR1;
1113
1114 psiconv_progress(lev+2,off+len,
1115 "Going to read the initial byte (%02x expected)",0x02);
1116 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
1117 if (res)
1118 goto ERROR2;
1119 if (temp != 0x02) {
1120 psiconv_warn(lev+2,off+len,
1121 "Sheet line list initial byte unknown value (ignored)");
1122 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
1123 }
1124 len ++;
1125
1126 psiconv_progress(lev+2,off+len,
1127 "Going to read the number of defined lines");
1128 listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
1129 if (res)
1130 goto ERROR2;
1131 psiconv_debug(lev+2,off+len,"Number of defined lines: %d",listlen);
1132 len += leng;
1133
1134 psiconv_progress(lev+2,off+len,"Going to read all lines");
1135 for (i = 0; i < listlen; i++) {
1136 psiconv_progress(lev+3,off+len,"Going to read line %d",i);
1137 if ((res = psiconv_parse_sheet_line(buf,lev+3,off+len,&leng,&line,
1138 default_layout)))
1139 goto ERROR2;
1140 if ((res = psiconv_list_add(*result,line)))
1141 goto ERROR3;
1142 free(line);
1143 len += leng;
1144 }
1145
1146 if (length)
1147 *length = len;
1148
1149 psiconv_progress(lev,off+len-1,
1150 "End of sheet line list (total length: %08x)", len);
1151 return 0;
1152
1153ERROR3:
1154 psiconv_free_sheet_line(line);
1155ERROR2:
1156 psiconv_free_sheet_line_list(*result);
1157ERROR1:
1158 psiconv_warn(lev+1,off,"Reading of Sheet Line List failed");
1159 if (length)
1160 *length = 0;
1161 if (!res)
1162 return -PSICONV_E_NOMEM;
1163 else
1164 return res;
1165}
1166

Legend:
Removed from v.127  
changed lines
  Added in v.128

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26