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

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

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

Revision 161 Revision 162
34 int lev,psiconv_u32 off, 34 int lev,psiconv_u32 off,
35 int *length, 35 int *length,
36 psiconv_text_and_layout result, 36 psiconv_text_and_layout result,
37 psiconv_word_styles_section styles, 37 psiconv_word_styles_section styles,
38 int with_styles); 38 int with_styles);
39static psiconv_file_type_t psiconv_determine_embedded_object_type
40 (const psiconv_buffer buf,int lev,
41 int *status);
39 42
40int psiconv_parse_header_section(const psiconv_buffer buf,int lev, 43int psiconv_parse_header_section(const psiconv_buffer buf,int lev,
41 psiconv_u32 off, int *length, 44 psiconv_u32 off, int *length,
42 psiconv_header_section *result) 45 psiconv_header_section *result)
43{ 46{
939 int len=0; 942 int len=0;
940 int leng,i; 943 int leng,i;
941 psiconv_section_table_section table; 944 psiconv_section_table_section table;
942 psiconv_section_table_entry entry; 945 psiconv_section_table_entry entry;
943 psiconv_u32 icon_sec=0,display_sec=0,table_sec=0; 946 psiconv_u32 icon_sec=0,display_sec=0,table_sec=0;
947 psiconv_buffer subbuf;
944 948
945 psiconv_progress(lev+1,off+len,"Going to read an Embedded Object"); 949 psiconv_progress(lev+1,off+len,"Going to read an Embedded Object");
946 if (!(*result = malloc(sizeof(**result)))) 950 if (!(*result = malloc(sizeof(**result))))
947 goto ERROR1; 951 goto ERROR1;
948 952
993 (*result)->icon = NULL; 997 (*result)->icon = NULL;
994 } else { 998 } else {
995 psiconv_debug(lev+2,off+len,"Object Icon Section at offset %08x",icon_sec); 999 psiconv_debug(lev+2,off+len,"Object Icon Section at offset %08x",icon_sec);
996 if ((res = psiconv_parse_object_icon_section(buf,lev+2,icon_sec,NULL, 1000 if ((res = psiconv_parse_object_icon_section(buf,lev+2,icon_sec,NULL,
997 &(*result)->icon))) 1001 &(*result)->icon)))
998 goto ERROR2; 1002 goto ERROR3;
1003 }
1004
1005 psiconv_progress(lev+2,off+len,
1006 "Looking for the Section Table Offset Section");
1007 if (!table_sec) {
1008 psiconv_warn(lev+2,off+len,
1009 "Embedded Section Table Offset Section not found");
1010 (*result)->object = NULL;
1011 } else {
1012 psiconv_progress(lev+2,off+len,
1013 "Extracting object: add %08x to all following offsets",
1014 table_sec);
1015 /* We can't determine the length of the object, so we just take it all */
1016 if ((res = psiconv_buffer_subbuffer(&subbuf,buf,table_sec,
1017 psiconv_buffer_length(buf)-table_sec)))
1018 goto ERROR4;
1019
1020 if (!((*result)->object = malloc(sizeof(*(*result)->object))))
1021 goto ERROR5;
1022
1023 /* We need to find the file type, but we don't have a normal header */
1024 /* So we try to find the Application ID Section and hope for the best */
1025 psiconv_progress(lev+3,0,"Trying to determine the file type");
1026 (*result)->object->type = psiconv_determine_embedded_object_type
1027 (subbuf,lev+3,&res);
1028 switch ((*result)->object->type) {
1029 case psiconv_word_file:
1030 if ((res = psiconv_parse_word_file(subbuf,lev+3,0,
1031 ((psiconv_word_f *) &(*result)->object->file))))
1032 goto ERROR6;
1033 break;
1034 case psiconv_texted_file:
1035 if ((res = psiconv_parse_texted_file(subbuf,lev+3,0,
1036 ((psiconv_texted_f *) &(*result)->object->file))))
1037 goto ERROR6;
1038 break;
1039 case psiconv_sheet_file:
1040 if ((res = psiconv_parse_sheet_file(subbuf,lev+3,0,
1041 ((psiconv_sheet_f *) &(*result)->object->file))))
1042 goto ERROR6;
1043 break;
1044 case psiconv_sketch_file:
1045 if ((res = psiconv_parse_sketch_file(subbuf,lev+3,0,
1046 ((psiconv_sketch_f *) &(*result)->object->file))))
1047 goto ERROR6;
1048 break;
1049 default:
1050 psiconv_warn(lev+3,0,"Can't parse embedded object (still continuing)");
1051 (*result)->object->file = NULL;
1052 }
999 } 1053 }
1000 1054
1001 if (length) 1055 if (length)
1002 *length = len; 1056 *length = len;
1003 1057
1004 psiconv_progress(lev+1,off+len-1,"End of Embedded Object Section " 1058 psiconv_progress(lev+1,off+len-1,"End of Embedded Object Section "
1005 "(total length: %08x)",len); 1059 "(total length: %08x)",len);
1006 1060
1007 return res; 1061 return res;
1008 1062
1009 1063
1064ERROR6:
1065 free((*result)->object);
1066ERROR5:
1067 psiconv_buffer_free(subbuf);
1068ERROR4:
1069 psiconv_free_object_icon_section((*result)->icon);
1070ERROR3:
1071 psiconv_free_object_display_section((*result)->display);
1010ERROR2: 1072ERROR2:
1011 psiconv_free_section_table_section(table); 1073 psiconv_free_section_table_section(table);
1012ERROR1: 1074ERROR1:
1013 psiconv_warn(lev+1,off,"Reading Embedded Object failed"); 1075 psiconv_warn(lev+1,off,"Reading Embedded Object failed");
1014 1076
1017 1079
1018 if (res == 0) 1080 if (res == 0)
1019 return -PSICONV_E_NOMEM; 1081 return -PSICONV_E_NOMEM;
1020 else 1082 else
1021 return res; 1083 return res;
1084}
1085
1086psiconv_file_type_t psiconv_determine_embedded_object_type
1087 (const psiconv_buffer buf,int lev,
1088 int *status)
1089{
1090 psiconv_u32 off;
1091 psiconv_section_table_section table;
1092 int res,i;
1093 psiconv_file_type_t file_type = psiconv_unknown_file;
1094 psiconv_section_table_entry entry;
1095 psiconv_application_id_section applid;
1096
1097 psiconv_progress(lev+1,0,"Going to determine embedded object file type");
1098 psiconv_progress(lev+2,0,"Going to read the Section Table Offset Section");
1099 off = psiconv_read_u32(buf,lev,0,&res);
1100 if (res)
1101 goto ERROR1;
1102 psiconv_debug(lev+2,0,"Offset: %08x",off);
1103
1104 psiconv_progress(lev+2,off,"Going to read the Section Table Section");
1105 if ((res = psiconv_parse_section_table_section(buf,lev+2,off,NULL,&table)))
1106 goto ERROR1;
1107
1108 psiconv_progress(lev+2,off,"Going to search the Section Table Section "
1109 "for the Application ID Section");
1110 for (i=0; i < psiconv_list_length(table); i++) {
1111 psiconv_progress(lev+3,off,"Going to read entry %d",i);
1112 if (!(entry = psiconv_list_get(table,i)))
1113 goto ERROR2;
1114 if (entry->id == PSICONV_ID_APPL_ID_SECTION) {
1115 psiconv_progress(lev+3,off,
1116 "Found the Application ID Section at offset %08x",
1117 entry->offset);
1118 off = entry->offset;
1119 break;
1120 }
1121 }
1122 if (i == psiconv_list_length(table)) {
1123 psiconv_warn(lev+2,off,"No Application ID Section found");
1124 res = PSICONV_E_PARSE;
1125 goto ERROR2;
1126 }
1127
1128 psiconv_progress(lev+2,off,"Going to read the Application ID Section");
1129 if ((res = psiconv_parse_application_id_section(buf,lev+2,off,NULL,&applid)))
1130 goto ERROR2;
1131
1132 switch (applid->id) {
1133 case PSICONV_ID_WORD: file_type = psiconv_word_file;
1134 psiconv_debug(lev+2,off,"Found a Word file");
1135 break;
1136 case PSICONV_ID_TEXTED: file_type = psiconv_texted_file;
1137 psiconv_debug(lev+2,off,"Found a TextEd file");
1138 break;
1139 case PSICONV_ID_SKETCH: file_type = psiconv_sketch_file;
1140 psiconv_debug(lev+2,off,"Found a Sketch file");
1141 break;
1142 case PSICONV_ID_SHEET: file_type = psiconv_sheet_file;
1143 psiconv_debug(lev+2,off,"Found a Sheet file");
1144 break;
1145 default: psiconv_warn(lev+2,off,"Found an unknown file type");
1146 psiconv_debug(lev+2,off,"Found ID %08x",applid->id);
1147 }
1148
1149ERROR2:
1150 psiconv_free_application_id_section(applid);
1151ERROR1:
1152 psiconv_free_section_table_section(table);
1153 if (status)
1154 *status = res;
1155 return file_type;
1156
1022} 1157}
1023 1158
1024int psiconv_parse_object_display_section(const psiconv_buffer buf,int lev, 1159int psiconv_parse_object_display_section(const psiconv_buffer buf,int lev,
1025 psiconv_u32 off, int *length, 1160 psiconv_u32 off, int *length,
1026 psiconv_object_display_section *result) 1161 psiconv_object_display_section *result)
1039 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 1174 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
1040 if (res) 1175 if (res)
1041 goto ERROR2; 1176 goto ERROR2;
1042 if (temp == 0x00) { 1177 if (temp == 0x00) {
1043 (*result)->show_icon = psiconv_bool_true; 1178 (*result)->show_icon = psiconv_bool_true;
1044 psiconv_debug(lev+2,off+len,"Displayed as full document"); 1179 psiconv_debug(lev+2,off+len,"Displayed as icon");
1045 } else if (temp == 0x01) { 1180 } else if (temp == 0x01) {
1046 (*result)->show_icon = psiconv_bool_false; 1181 (*result)->show_icon = psiconv_bool_false;
1047 psiconv_debug(lev+2,off+len,"Displayed as icon"); 1182 psiconv_debug(lev+2,off+len,"Displayed as full document");
1048 } else { 1183 } else {
1049 psiconv_warn(lev+2,off+len,"Unknown Object Display Section Icon Flag"); 1184 psiconv_warn(lev+2,off+len,"Unknown Object Display Section Icon Flag");
1050 psiconv_debug(lev+2,off+len,"Icon flag found: %02x",temp); 1185 psiconv_debug(lev+2,off+len,"Icon flag found: %02x",temp);
1051 /* Improvise */ 1186 /* Improvise */
1052 (*result)->show_icon = (temp & 0x01?psiconv_bool_false:psiconv_bool_true); 1187 (*result)->show_icon = (temp & 0x01?psiconv_bool_false:psiconv_bool_true);
1053 } 1188 }
1054 len ++; 1189 len ++;
1055 1190
1056 psiconv_progress(lev+2,off+len,"Going to read the icon width"); 1191 psiconv_progress(lev+2,off+len,"Going to read the display width");
1057 (*result)->width = psiconv_read_length(buf,lev+2,off+len,&leng,&res); 1192 (*result)->width = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
1058 if (res) 1193 if (res)
1059 goto ERROR2; 1194 goto ERROR2;
1060 psiconv_debug(lev+2,off+len,"Icon width: %f cm",(*result)->width); 1195 psiconv_debug(lev+2,off+len,"Display width: %f cm",(*result)->width);
1061 len += leng; 1196 len += leng;
1062 1197
1063 psiconv_progress(lev+2,off+len,"Going to read the icon height"); 1198 psiconv_progress(lev+2,off+len,"Going to read the display height");
1064 (*result)->height = psiconv_read_length(buf,lev+2,off+len,&leng,&res); 1199 (*result)->height = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
1065 if (res) 1200 if (res)
1066 goto ERROR2; 1201 goto ERROR2;
1067 psiconv_debug(lev+2,off+len,"Icon length: %f cm",(*result)->height); 1202 psiconv_debug(lev+2,off+len,"Display length: %f cm",(*result)->height);
1068 len += leng; 1203 len += leng;
1069 1204
1070 psiconv_progress(lev+2,off+len,"Going to read unknown long (%08x expected)", 1205 psiconv_progress(lev+2,off+len,"Going to read unknown long (%08x expected)",
1071 0); 1206 0);
1072 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 1207 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
1077 len += 4; 1212 len += 4;
1078 1213
1079 if (length) 1214 if (length)
1080 *length = len; 1215 *length = len;
1081 1216
1082 psiconv_progress(lev+1,off+len-1,"End of Object Display Section" 1217 psiconv_progress(lev+1,off+len-1,"End of Object Display Section "
1083 "(total length: %08x",len); 1218 "(total length: %08x",len);
1084 return res; 1219 return res;
1085 1220
1086ERROR2: 1221ERROR2:
1087 free(*result); 1222 free(*result);

Legend:
Removed from v.161  
changed lines
  Added in v.162

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