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

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

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

Revision 167 Revision 168
27 27
28#ifdef DMALLOC 28#ifdef DMALLOC
29#include <dmalloc.h> 29#include <dmalloc.h>
30#endif 30#endif
31 31
32int psiconv_parse_texted_section(const psiconv_buffer buf,int lev, 32int psiconv_parse_texted_section(const psiconv_config config,
33 const psiconv_buffer buf,int lev,
33 psiconv_u32 off, int *length, 34 psiconv_u32 off, int *length,
34 psiconv_texted_section *result, 35 psiconv_texted_section *result,
35 psiconv_character_layout base_char, 36 psiconv_character_layout base_char,
36 psiconv_paragraph_layout base_para) 37 psiconv_paragraph_layout base_para)
37{ 38{
41 psiconv_u32 unknown_sec = 0; 42 psiconv_u32 unknown_sec = 0;
42 psiconv_u32 replacement_sec = 0; 43 psiconv_u32 replacement_sec = 0;
43 psiconv_u32 temp; 44 psiconv_u32 temp;
44 int leng; 45 int leng;
45 46
46 psiconv_progress(lev+1,off,"Going to read a texted section"); 47 psiconv_progress(config,lev+1,off,"Going to read a texted section");
47 if (!((*result) = malloc(sizeof(**result)))) 48 if (!((*result) = malloc(sizeof(**result))))
48 goto ERROR1; 49 goto ERROR1;
49 50
50 psiconv_progress(lev+2,off+len,"Going to read section id"); 51 psiconv_progress(config,lev+2,off+len,"Going to read section id");
51 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 52 temp = psiconv_read_u32(config,buf,lev+2,off+len,&res);
52 if (res) 53 if (res)
53 goto ERROR2; 54 goto ERROR2;
54 if (temp != PSICONV_ID_TEXTED_BODY) { 55 if (temp != PSICONV_ID_TEXTED_BODY) {
55 psiconv_warn(lev+2,off+len, 56 psiconv_warn(config,lev+2,off+len,
56 "Page header section body id not found"); 57 "Page header section body id not found");
57 psiconv_debug(lev+2,off+len, 58 psiconv_debug(config,lev+2,off+len,
58 "Page body id: read %08x, expected %08x",temp, 59 "Page body id: read %08x, expected %08x",temp,
59 PSICONV_ID_TEXTED); 60 PSICONV_ID_TEXTED);
60 res = -PSICONV_E_PARSE; 61 res = -PSICONV_E_PARSE;
61 goto ERROR2; 62 goto ERROR2;
62 } 63 }
63 len += 4; 64 len += 4;
64 65
65 psiconv_progress(lev+2,off+len,"Going to read the section jumptable"); 66 psiconv_progress(config,lev+2,off+len,"Going to read the section jumptable");
66 while (temp = psiconv_read_u32(buf,lev+3,off+len,&res), 67 while (temp = psiconv_read_u32(config,buf,lev+3,off+len,&res),
67 !res && temp != PSICONV_ID_TEXTED_TEXT) { 68 !res && temp != PSICONV_ID_TEXTED_TEXT) {
68 len += 4; 69 len += 4;
69 if (temp == PSICONV_ID_TEXTED_LAYOUT) { 70 if (temp == PSICONV_ID_TEXTED_LAYOUT) {
70 layout_sec = psiconv_read_u32(buf,lev+3,off+len,&res); 71 layout_sec = psiconv_read_u32(config,buf,lev+3,off+len,&res);
71 if (res) 72 if (res)
72 goto ERROR2; 73 goto ERROR2;
73 psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec); 74 psiconv_debug(config,lev+3,off+len,"Found Layout section at %08x",layout_sec);
74 } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) { 75 } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) {
75 replacement_sec = psiconv_read_u32(buf,lev+3,off+len,&res); 76 replacement_sec = psiconv_read_u32(config,buf,lev+3,off+len,&res);
76 if (res) 77 if (res)
77 goto ERROR2; 78 goto ERROR2;
78 psiconv_debug(lev+3,off+len,"Found Replacement section at %08x", 79 psiconv_debug(config,lev+3,off+len,"Found Replacement section at %08x",
79 replacement_sec); 80 replacement_sec);
80 } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) { 81 } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) {
81 unknown_sec= psiconv_read_u32(buf,lev+3,off+len,&res); 82 unknown_sec= psiconv_read_u32(config,buf,lev+3,off+len,&res);
82 if (res) 83 if (res)
83 goto ERROR2; 84 goto ERROR2;
84 if (unknown_sec) { 85 if (unknown_sec) {
85 psiconv_warn(lev+3,off+len, 86 psiconv_warn(config,lev+3,off+len,
86 "Unknown section in TextEd jumptable has real offset (ignoring)"); 87 "Unknown section in TextEd jumptable has real offset (ignoring)");
87 } 88 }
88 psiconv_debug(lev+3,off+len,"Found Unknown section at %08x", 89 psiconv_debug(config,lev+3,off+len,"Found Unknown section at %08x",
89 unknown_sec); 90 unknown_sec);
90 } else { 91 } else {
91 psiconv_warn(lev+3,off+len, 92 psiconv_warn(config,lev+3,off+len,
92 "Unknown section in TextEd jumptable (ignoring)"); 93 "Unknown section in TextEd jumptable (ignoring)");
93 psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp, 94 psiconv_debug(config,lev+3,off+len,"Section ID %08x at offset %08x",temp,
94 psiconv_read_u32(buf,lev+3,off+len,NULL)); 95 psiconv_read_u32(config,buf,lev+3,off+len,NULL));
95 } 96 }
96 len += 4; 97 len += 4;
97 } 98 }
98 if (res) 99 if (res)
99 goto ERROR2; 100 goto ERROR2;
100 101
101 len += 4; 102 len += 4;
102 psiconv_progress(lev+2,off+len,"Going to read the text"); 103 psiconv_progress(config,lev+2,off+len,"Going to read the text");
103 if ((res = psiconv_parse_text_section(buf,lev+2,off+len,&leng, 104 if ((res = psiconv_parse_text_section(config,buf,lev+2,off+len,&leng,
104 &(*result)->paragraphs))) 105 &(*result)->paragraphs)))
105 goto ERROR2; 106 goto ERROR2;
106 len += leng; 107 len += leng;
107 108
108 if (layout_sec) { 109 if (layout_sec) {
109 psiconv_progress(lev+2,off+len,"Going to read the layout"); 110 psiconv_progress(config,lev+2,off+len,"Going to read the layout");
110 if ((res = psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL, 111 if ((res = psiconv_parse_styleless_layout_section(config,buf,lev+2,layout_sec,NULL,
111 (*result)->paragraphs, 112 (*result)->paragraphs,
112 base_char,base_para))) 113 base_char,base_para)))
113 goto ERROR3; 114 goto ERROR3;
114 } 115 }
115 116
116#if 0 117#if 0
117 if (replacement_sec) { 118 if (replacement_sec) {
118 psiconv_progress(lev+2,off+len,"Going to read the replacements"); 119 psiconv_progress(config,lev+2,off+len,"Going to read the replacements");
119 /* WHATEVER */ 120 /* WHATEVER */
120 } 121 }
121#endif 122#endif
122 123
123 if (length) 124 if (length)
124 *length = len; 125 *length = len;
125 126
126 psiconv_progress(lev+1,off+len-1,"End of TextEd section " 127 psiconv_progress(config,lev+1,off+len-1,"End of TextEd section "
127 "(total length: %08x", len); 128 "(total length: %08x", len);
128 129
129 return 0; 130 return 0;
130 131
131ERROR3: 132ERROR3:
132 psiconv_free_text_and_layout((*result)->paragraphs); 133 psiconv_free_text_and_layout((*result)->paragraphs);
133ERROR2: 134ERROR2:
134 free (*result); 135 free (*result);
135ERROR1: 136ERROR1:
136 psiconv_warn(lev+1,off,"Reading of TextEd Section failed"); 137 psiconv_warn(config,lev+1,off,"Reading of TextEd Section failed");
137 if (length) 138 if (length)
138 *length = 0; 139 *length = 0;
139 if (!res) 140 if (!res)
140 return -PSICONV_E_NOMEM; 141 return -PSICONV_E_NOMEM;
141 else 142 else

Legend:
Removed from v.167  
changed lines
  Added in v.168

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