1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <ctype.h>
|
---|
4 | #include <string.h>
|
---|
5 | #include "wv.h"
|
---|
6 |
|
---|
7 | int wvIsListEntry(PAP *apap,version ver)
|
---|
8 | {
|
---|
9 | if (ver == WORD8)
|
---|
10 | {
|
---|
11 | if (apap->ilfo)
|
---|
12 | return(1);
|
---|
13 | else
|
---|
14 | return(0);
|
---|
15 | }
|
---|
16 | else
|
---|
17 | {
|
---|
18 | if (apap->nLvlAnm)
|
---|
19 | {
|
---|
20 | wvTrace(("old style pap, thats a list\n"));
|
---|
21 | return(1);
|
---|
22 | }
|
---|
23 | else
|
---|
24 | return(0);
|
---|
25 | }
|
---|
26 | return(0);
|
---|
27 | }
|
---|
28 |
|
---|
29 | /*
|
---|
30 | Paragraph List Formatting
|
---|
31 |
|
---|
32 | Given a paragraph and its corresponding PAP, the following process must be
|
---|
33 | followed to find out the paragraph's list information:
|
---|
34 |
|
---|
35 | * Using the pap.ilfo, look up the LFO record in the pllfo with that
|
---|
36 | (1-based) index.
|
---|
37 |
|
---|
38 | * Using the LFO, and the pap.ilvl, check to see if there are any
|
---|
39 | overrides for this particular level. If so, and if the override
|
---|
40 | pertains to both formatting and start-at value, use the LVL record from
|
---|
41 | the correct LFOLVL in the LFO, and skip to step 5.
|
---|
42 |
|
---|
43 | * If the override does not pertain to either formatting or start-at
|
---|
44 | value, we must look up the LST for this list. Using the LFO's List ID,
|
---|
45 | search the rglst for the LST with that List ID.
|
---|
46 |
|
---|
47 | * Now, take from this LST any information (formatting or start-at value)
|
---|
48 | we still need after consulting the LFO.
|
---|
49 |
|
---|
50 | * Once we've got the correct LVL record, apply the lvl.grpprlPapx to the
|
---|
51 | PAP. It may adjust the indents and tab settings for the paragraph.
|
---|
52 |
|
---|
53 | * Use the other information in the LVL, such as the start at, number
|
---|
54 | text, and grpprlChpx, to determine the appearance of the actual
|
---|
55 | paragraph number text.
|
---|
56 | */
|
---|
57 | int wvGetListEntryInfo(version ver,LVL **finallvl,U32 **nos,U8 **nfcs,LVL *retlvl,LFO **retlfo,PAP *apap,LFO **lfo,LFOLVL *lfolvl,LVL *lvl,U32 *nolfo, LST **lst, U16 *noofLST)
|
---|
58 | {
|
---|
59 | LST *alst=NULL;
|
---|
60 | U32 i,number=0;
|
---|
61 | S32 j;
|
---|
62 | U32 oldno;
|
---|
63 | U32 fakeid;
|
---|
64 |
|
---|
65 | wvTrace(("given ilfo of %d %d\n",apap->ilfo,apap->ilvl));
|
---|
66 | if (apap->ilfo < 0)
|
---|
67 | {
|
---|
68 | apap->ilfo = abs(apap->ilfo);
|
---|
69 | wvWarning("Insane negative ilfo value, normalizing to %d and hoping for the best\n",apap->ilfo);
|
---|
70 | }
|
---|
71 |
|
---|
72 | if ( (apap->ilfo == 2047) || (ver != WORD8) )
|
---|
73 | {
|
---|
74 | retlvl->lvlf.iStartAt = apap->anld.iStartAt;
|
---|
75 | retlvl->lvlf.nfc = apap->anld.nfc;
|
---|
76 | wvTrace(("start %d,type is %d\n",apap->anld.iStartAt,apap->anld.nfc));
|
---|
77 | retlvl->lvlf.jc = apap->anld.jc;
|
---|
78 | retlvl->lvlf.fLegal = 0; /*?*/
|
---|
79 | retlvl->lvlf.fNoRestart = 0; /*?*/
|
---|
80 | retlvl->lvlf.fPrev = apap->anld.fPrev;
|
---|
81 | retlvl->lvlf.fPrevSpace = apap->anld.fPrevSpace;
|
---|
82 | retlvl->lvlf.fWord6 = 1;
|
---|
83 | retlvl->lvlf.rgbxchNums[0] = 0; /*wrong for now*/
|
---|
84 | retlvl->lvlf.ixchFollow = 2; /*wrong for now*/
|
---|
85 | retlvl->lvlf.dxaSpace = apap->anld.dxaSpace;
|
---|
86 | retlvl->lvlf.dxaIndent = apap->anld.dxaIndent;
|
---|
87 | retlvl->lvlf.cbGrpprlChpx = 0; /* wrong */
|
---|
88 | retlvl->lvlf.cbGrpprlPapx = 0; /* wrong */
|
---|
89 | retlvl->lvlf.reserved1 = 0;
|
---|
90 | retlvl->lvlf.reserved2 = 0;
|
---|
91 | retlvl->grpprlChpx = NULL; /* wrong */
|
---|
92 | retlvl->grpprlPapx = NULL; /* wrong */
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 | /* wrong: begin of numbertext twiddling */
|
---|
97 | wvTrace(("before len %d\n",apap->anld.cxchTextBefore));
|
---|
98 | wvTrace(("after len %d\n",apap->anld.cxchTextAfter));
|
---|
99 | retlvl->numbertext = (XCHAR *)malloc(sizeof(XCHAR) * 64);
|
---|
100 | i=0;
|
---|
101 | for (;i<apap->anld.cxchTextBefore;i++)
|
---|
102 | retlvl->numbertext[i] = apap->anld.rgxch[i];
|
---|
103 |
|
---|
104 | retlvl->numbertext[i] = 2;
|
---|
105 |
|
---|
106 | for (i=apap->anld.cxchTextBefore;i<apap->anld.cxchTextAfter;i++)
|
---|
107 | retlvl->numbertext[i+1] = apap->anld.rgxch[i];
|
---|
108 |
|
---|
109 | retlvl->numbertext[i+1] = '\0';
|
---|
110 | /* end of numbertext twiddling */
|
---|
111 |
|
---|
112 |
|
---|
113 | /* temp test */
|
---|
114 | if (retlvl->lvlf.nfc > 5)
|
---|
115 | retlvl->numbertext[0] = 0;
|
---|
116 |
|
---|
117 |
|
---|
118 | /*word 6 anld, parse that instead*/
|
---|
119 | fakeid = wvCheckSumANLD(&apap->anld);
|
---|
120 | wvTrace(("creating a fake id of %x\n",fakeid));
|
---|
121 | for (i=0;i<*nolfo;i++)
|
---|
122 | {
|
---|
123 | if ( fakeid == (*lfo)[i].lsid )
|
---|
124 | {
|
---|
125 | wvTrace(("This is not the first time we've seen this list\n"));
|
---|
126 | apap->ilfo = i+1;
|
---|
127 |
|
---|
128 | if (apap->nLvlAnm >= 10)
|
---|
129 | apap->nLvlAnm-=10;
|
---|
130 |
|
---|
131 | if ( (apap->nLvlAnm == 1) || (apap->nLvlAnm == 0) )
|
---|
132 | apap->ilvl = 0;
|
---|
133 | else
|
---|
134 | apap->ilvl = apap->nLvlAnm-1;
|
---|
135 |
|
---|
136 | if (apap->ilvl >= 10) apap->ilvl-=10;
|
---|
137 |
|
---|
138 | for (i=0;i<9;i++) (*nos)[(apap->ilfo-1)*9+i] = 0xffffffffL;
|
---|
139 | for (i=0;i<9;i++) (*nfcs)[(apap->ilfo-1)*9+i] = 0xff;
|
---|
140 |
|
---|
141 | wvTrace(("ilvl %d\n",apap->ilvl));
|
---|
142 |
|
---|
143 |
|
---|
144 | /* if this anld is a dodgy one 0x2e*/
|
---|
145 | if ( (apap->ilvl) && (apap->anld.fNumber1 == 0x2e) )
|
---|
146 | {
|
---|
147 | wvTrace(("Suspicious\n"));
|
---|
148 | switch(apap->ilvl)
|
---|
149 | {
|
---|
150 | case 1:
|
---|
151 | if (retlvl->lvlf.nfc == 0)
|
---|
152 | retlvl->lvlf.nfc = 4;
|
---|
153 | else if (retlvl->lvlf.nfc == 1)
|
---|
154 | retlvl->lvlf.nfc = 3;
|
---|
155 | break;
|
---|
156 | case 2:
|
---|
157 | if (retlvl->lvlf.nfc == 0)
|
---|
158 | retlvl->lvlf.nfc = 2;
|
---|
159 | else if (retlvl->lvlf.nfc == 1)
|
---|
160 | retlvl->lvlf.nfc = 0;
|
---|
161 | break;
|
---|
162 | case 3:
|
---|
163 | if (retlvl->lvlf.nfc == 0)
|
---|
164 | retlvl->lvlf.nfc = 4;
|
---|
165 | else if (retlvl->lvlf.nfc == 1)
|
---|
166 | retlvl->lvlf.nfc = 4;
|
---|
167 | break;
|
---|
168 | case 4:
|
---|
169 | if (retlvl->lvlf.nfc == 0)
|
---|
170 | retlvl->lvlf.nfc = 0;
|
---|
171 | else if (retlvl->lvlf.nfc == 1)
|
---|
172 | retlvl->lvlf.nfc = 0;
|
---|
173 | break;
|
---|
174 | case 5:
|
---|
175 | if (retlvl->lvlf.nfc == 0)
|
---|
176 | retlvl->lvlf.nfc = 4;
|
---|
177 | else if (retlvl->lvlf.nfc == 1)
|
---|
178 | retlvl->lvlf.nfc = 4;
|
---|
179 | break;
|
---|
180 | case 6:
|
---|
181 | if (retlvl->lvlf.nfc == 0)
|
---|
182 | retlvl->lvlf.nfc = 2;
|
---|
183 | else if (retlvl->lvlf.nfc == 1)
|
---|
184 | retlvl->lvlf.nfc = 2;
|
---|
185 | break;
|
---|
186 | case 7:
|
---|
187 | if (retlvl->lvlf.nfc == 0)
|
---|
188 | retlvl->lvlf.nfc = 4;
|
---|
189 | else if (retlvl->lvlf.nfc == 1)
|
---|
190 | retlvl->lvlf.nfc = 4;
|
---|
191 | break;
|
---|
192 | case 8:
|
---|
193 | if (retlvl->lvlf.nfc == 0)
|
---|
194 | retlvl->lvlf.nfc = 2;
|
---|
195 | else if (retlvl->lvlf.nfc == 1)
|
---|
196 | retlvl->lvlf.nfc = 2;
|
---|
197 | break;
|
---|
198 | }
|
---|
199 | }
|
---|
200 | return(0);
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 | wvTrace(("This is the first time we've seen this list\n"));
|
---|
205 |
|
---|
206 | oldno = *nolfo;
|
---|
207 | (*nolfo)++;
|
---|
208 |
|
---|
209 | /*
|
---|
210 | realloc the lfo list to be one bigger,
|
---|
211 | */
|
---|
212 | *lfo = (LFO *)realloc(*lfo,sizeof(LFO) * (*nolfo));
|
---|
213 | *nos = (U32 *)realloc(*nos,sizeof(U32) * 9 * (*nolfo));
|
---|
214 | *nfcs = (U8 *)realloc(*nfcs,9 * (*nolfo));
|
---|
215 | wvTrace(("nos is now %d long\n",9 * (*nolfo)));
|
---|
216 | *finallvl = (LVL *)realloc(*finallvl,9 * (*nolfo) * sizeof(LVL));
|
---|
217 |
|
---|
218 | apap->ilfo = *nolfo;
|
---|
219 |
|
---|
220 | wvTrace(("ilvl is %d, nLvlAnm is %d\n",apap->ilvl,apap->nLvlAnm));
|
---|
221 | if (apap->nLvlAnm >= 10)
|
---|
222 | apap->nLvlAnm-=10;
|
---|
223 |
|
---|
224 | if ((apap->nLvlAnm == 1) || (apap->nLvlAnm == 0) )
|
---|
225 | apap->ilvl = 0;
|
---|
226 | else
|
---|
227 | apap->ilvl = apap->nLvlAnm-1;
|
---|
228 |
|
---|
229 | wvTrace(("ilfo set to %d\n",apap->ilfo));
|
---|
230 |
|
---|
231 | /* begin new test */
|
---|
232 | (*noofLST)++;
|
---|
233 | *lst = (LST *)realloc(*lst,sizeof(LST) * (*noofLST));
|
---|
234 | wvInitLST(&(((*lst)[(*noofLST)-1])));
|
---|
235 | (*lst)[(*noofLST)-1].lstf.lsid = fakeid;
|
---|
236 | wvTrace(("ilvl is %d\n",apap->ilvl));
|
---|
237 | wvCopyLVL(&(((*lst)[(*noofLST)-1]).lvl[apap->ilvl]),retlvl);
|
---|
238 | /* end new test */
|
---|
239 | wvTrace(("End\n"));
|
---|
240 |
|
---|
241 |
|
---|
242 | wvInitLFO(&((*lfo)[apap->ilfo-1]));
|
---|
243 | (*lfo)[apap->ilfo-1].lsid = fakeid; /*how about this?*/
|
---|
244 | *retlfo = &((*lfo)[apap->ilfo-1]);
|
---|
245 | for (i=0;i<9;i++)
|
---|
246 | {
|
---|
247 | (*nos)[(apap->ilfo-1)*9+i] = 0xffffffffL;
|
---|
248 | (*nfcs)[(apap->ilfo-1)*9+i] = 0xff;
|
---|
249 | wvInitLVL(&((*finallvl)[(apap->ilfo-1)*9+i]));
|
---|
250 | wvCopyLVL(&((*finallvl)[(apap->ilfo-1)*9+i]),retlvl);
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | /*
|
---|
255 | and set the ilfo and ilvl of the list to point to that fake entry instead
|
---|
256 | and we'll have to repeat the procedure for the liststartnos
|
---|
257 | */
|
---|
258 | return(0);
|
---|
259 | }
|
---|
260 | else if (apap->ilfo == 0)
|
---|
261 | {
|
---|
262 | /* no number */
|
---|
263 | return(0);
|
---|
264 | }
|
---|
265 | if (apap->ilfo > (S32)(*nolfo))
|
---|
266 | {
|
---|
267 | wvWarning("ilfo no %d, is greater than the number of existing lfo's (%d)\n",apap->ilfo,*nolfo);
|
---|
268 | return(1);
|
---|
269 | }
|
---|
270 |
|
---|
271 | /*
|
---|
272 | Using the pap.ilfo, look up the LFO record in the pllfo with that
|
---|
273 | (1-based) index. == (*lfo)[apap->ilfo]
|
---|
274 | */
|
---|
275 |
|
---|
276 | *retlfo = &((*lfo)[apap->ilfo-1]);
|
---|
277 |
|
---|
278 | wvTrace(("looking for id %x\n",(*retlfo)->lsid));
|
---|
279 |
|
---|
280 | if ((*lfo)[apap->ilfo-1].clfolvl)
|
---|
281 | {
|
---|
282 | /*
|
---|
283 | Using the LFO, and the pap.ilvl, check to see if there are any
|
---|
284 | overrides for this particular level. If so, and if the override
|
---|
285 | pertains to both formatting and start-at value, use the LVL record
|
---|
286 | from the correct LFOLVL in the LFO, and skip to step 5.
|
---|
287 | */
|
---|
288 | wvTrace(("some overridden levels, ilfo %d\n",apap->ilfo));
|
---|
289 |
|
---|
290 | /*
|
---|
291 | there are some levels overridden, find out if the level being overridden
|
---|
292 | is the same as the level the paragraph wants
|
---|
293 | */
|
---|
294 | for (j=0;j<apap->ilfo-1;j++)
|
---|
295 | number+=(*lfo)[j].clfolvl;
|
---|
296 |
|
---|
297 | for(i=0;i<(*lfo)[apap->ilfo-1].clfolvl;i++)
|
---|
298 | {
|
---|
299 | if (lfolvl[i+number].ilvl == apap->ilvl)
|
---|
300 | {
|
---|
301 | /* the requested level is overridden */
|
---|
302 | if ((lfolvl[i+number].fFormatting) && (lfolvl[i+number].fStartAt))
|
---|
303 | {
|
---|
304 | /*save the existing lvl and swap in this new one instead*/
|
---|
305 | alst = wvSearchLST((*lfo)[apap->ilfo-1].lsid,*lst,*noofLST);
|
---|
306 |
|
---|
307 | /*use the LVL record from the correct LFOLVL in the LFO*/
|
---|
308 | wvCopyLVL(retlvl,&(lvl[i+number]));
|
---|
309 | }
|
---|
310 | else if (lfolvl[i+number].fStartAt)
|
---|
311 | {
|
---|
312 | alst = wvSearchLST((*lfo)[apap->ilfo-1].lsid,*lst,*noofLST);
|
---|
313 |
|
---|
314 | /* the lvl is the standard one with a new startat value */
|
---|
315 | wvCopyLVL(retlvl,&(alst->lvl[apap->ilvl]));
|
---|
316 | retlvl->lvlf.iStartAt = lfolvl[i+number].iStartAt;
|
---|
317 | }
|
---|
318 | else if (lfolvl[i+number].fFormatting)
|
---|
319 | {
|
---|
320 | alst = wvSearchLST((*lfo)[apap->ilfo-1].lsid,*lst,*noofLST);
|
---|
321 |
|
---|
322 | /* the lvl is the overridden one, with the original startat */
|
---|
323 | wvCopyLVL(retlvl,&(lvl[i+number]));
|
---|
324 | retlvl->lvlf.iStartAt = alst->lvl[apap->ilvl].lvlf.iStartAt;
|
---|
325 | }
|
---|
326 | }
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | if (alst == NULL)
|
---|
331 | {
|
---|
332 | /*
|
---|
333 | if there no overridden levels i assume that we
|
---|
334 | search for the appropiate LST
|
---|
335 | */
|
---|
336 | alst = wvSearchLST((*lfo)[apap->ilfo-1].lsid,*lst,*noofLST);
|
---|
337 | if (alst != NULL)
|
---|
338 | {
|
---|
339 | wvTrace(("ilvl is %d\n",apap->ilvl));
|
---|
340 | if ( (alst->lstf.fSimpleList) && (apap->ilvl) )
|
---|
341 | {
|
---|
342 | wvWarning("Level %d requested from list with 1 level\n",apap->ilvl+1);
|
---|
343 | wvCopyLVL(retlvl,&(alst->lvl[0]));
|
---|
344 | }
|
---|
345 | else
|
---|
346 | wvCopyLVL(retlvl,&(alst->lvl[apap->ilvl]));
|
---|
347 | wvTrace(("string len is %d",retlvl->numbertext[0]));
|
---|
348 | wvTrace(("offset is %d\n",retlvl->lvlf.rgbxchNums[0]));
|
---|
349 | }
|
---|
350 | }
|
---|
351 |
|
---|
352 | if (alst == NULL)
|
---|
353 | {
|
---|
354 | wvError(("No LST found for list\n"));
|
---|
355 | return(1);
|
---|
356 | }
|
---|
357 |
|
---|
358 | return(0);
|
---|
359 | }
|
---|