File: docListtextField.c

package info (click to toggle)
ted 2.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,944 kB
  • ctags: 20,273
  • sloc: ansic: 167,980; makefile: 12,518; sh: 263
file content (330 lines) | stat: -rw-r--r-- 8,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/************************************************************************/
/*									*/
/*  Buffer administration routines.					*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

#   include	<stdlib.h>
#   include	<string.h>
#   include	<stdio.h>

#   include	<appDebugon.h>

#   include	<utilBase26.h>
#   include	<utilRoman.h>
#   include	"docBuf.h"
#   include	"docEvalField.h"
#   include	"docEdit.h"

/************************************************************************/
/*									*/
/*  Format the value of a 'listtext' field.				*/
/*									*/
/*  I.E. the text of the bullet or paragraph number at the beginning	*/
/*	of a paragraph that gets one because it has a list reference.	*/
/*									*/
/************************************************************************/

int docCalculateListtextString(	unsigned char *			target,
				int				maxsize,
				int				ilvl,
				const int *			numberPath,
				const int *			startPath,
				const int *			formatPath,
				const DocumentListLevel *	dll )
    {
    int		done= 0;
    int		textSize= 1;
    int		textUsed= 1;

    int		off;

    if  ( ! dll->dllText )
	{ XDEB(dll->dllText); return -1; }

    if  ( dll->dllTextSize > 0 )
	{ textSize= dll->dllText[0]+ 1;	}

    for ( off= 0; off < dll->dllNumberSize; off++ )
	{
	int	level;
	int	step;
	int	upto= dll->dllNumbers[off];
	int	val;

	if  ( upto >= textSize	||
	      upto < textUsed	)
	    { LLLDEB(upto,textSize,textUsed); return -1;	}
	if  ( done+ ( upto- textUsed ) >= maxsize )
	    { LLLDEB(done,upto- textUsed,maxsize); return -1;		}

	if  ( textUsed < upto )
	    {
	    memcpy( target, dll->dllText+ textUsed, upto- textUsed );
	    target += upto- textUsed; done += upto- textUsed; textUsed= upto;
	    }

	target[0]= '\0';

	level= dll->dllText[textUsed++];
	if  ( level > ilvl )
	    { LLDEB(ilvl,level); return -1;	}

	val= startPath[level]+ numberPath[level];

	switch( formatPath[level] )
	    {
	    case DOCpnDEC:
		if  ( done+ 11 > maxsize )
		    { LLDEB(done,maxsize); return -1;	}
		sprintf( (char *)target, "%d", val );
		step= strlen( (char *)target );
		target += step; done += step;
		break;

	    case DOCpnUCRM:
		if  ( utilRomanString( (char *)target, maxsize, val, 1 ) )
		    { LDEB(val); return -1;	}
		step= strlen( (char *)target );
		target += step; done += step;
		break;

	    case DOCpnLCRM:
		if  ( utilRomanString( (char *)target, maxsize, val, 0 ) )
		    { LDEB(val); return -1;	}
		step= strlen( (char *)target );
		target += step; done += step;
		break;

	    case DOCpnUCLTR:
		if  ( val == 0 )
		    { strcpy( (char *)target, "+" ); }
		else{
		    if  ( utilBase26String( (char *)target, maxsize, val, 1 ) )
			{ LDEB(val); return -1;	}
		    }
		step= strlen( (char *)target );
		target += step; done += step;
		break;

	    case DOCpnLCLTR:
		if  ( val == 0 )
		    { strcpy( (char *)target, "+" ); }
		else{
		    if  ( utilBase26String( (char *)target, maxsize, val, 0 ) )
			{ LDEB(val); return -1;	}
		    }
		step= strlen( (char *)target );
		target += step; done += step;
		break;

	    case 22:
		if  ( done+ 11 > maxsize )
		    { LLDEB(done,maxsize); return -1;	}
		sprintf( (char *)target, "%02d", val );
		step= strlen( (char *)target );
		target += step; done += step;
		break;

	    case 23:
		*(target++)= 0xb7; done++;
		target[0]= '\0';
		break;

	    case 255:
		break;

	    default:
		LLLDEB(level,formatPath[level],val);
		if  ( done+ 11 > maxsize )
		    { LLDEB(done,maxsize); return -1;	}
		sprintf( (char *)target, "(%d)", val );
		break;
	    }
	}

    if  ( textUsed < textSize )
	{
	int	upto= textSize;

	if  ( done+ ( upto- textUsed ) >= maxsize )
	    { LLLDEB(done,upto- textUsed,maxsize); return -1;	}

	memcpy( target, dll->dllText+ textUsed, upto- textUsed );
	target += upto- textUsed; done += upto- textUsed;
	target[0]= '\0';
	}

    if  ( dll->dllFollow == DOCllfTAB || dll->dllFollow == DOCllfSPACE )
	{
	if  ( done+ 1 >= maxsize )
	    { LLDEB(done,maxsize); }

	*(target++)= ' '; done++;
	target[0]= '\0';
	}

    return done;
    }

/************************************************************************/
/*									*/
/*  Evaluate Listtext fields for bulleted and numbered lists &c.	*/
/*									*/
/*  1)  Paranoia: check list number.					*/
/*  2)  Get override and number tree.					*/
/*  3)  Link override to list if nexessary.				*/
/*  4)  Paranoia again: Is it an existing list?				*/
/*  5)  Obtain the path in the number tree. ( E.G: 1.4.7.8 )		*/
/*  6)  Calculate number or bullet text.				*/
/*  7)  Replace old field contents with the new string.			*/
/*  8)  Calculate attribute number for added text.			*/
/*  9)  Insert text paricule.						*/
/*  10) Insert tab.							*/
/*									*/
/************************************************************************/

int docRecalculateParaListtextTextParticules(
				int *				pCalculated,
				BufferDocument *		bd,
				int *				pPartShift,
				int *				pStroffShift,
				BufferItem *			paraBi,
				int				part,
				int				partCount,
				DocumentField *			dfListtext,
				void *				voidadd,
				DOC_CLOSE_OBJECT		closeObject )
    {
    const ParagraphProperties *	pp= &(paraBi->biParaProperties);

    int				ilvl= pp->ppListLevel;

    ListOverride *		lo;
    DocumentList *		dl;
    ListNumberTreeNode *	root;

    int				paraNr= docNumberOfParagraph( paraBi );

    int				startPath[DLmaxLEVELS+1];
    int				formatPath[DLmaxLEVELS+1];
    const DocumentListLevel *	dll= (const DocumentListLevel *)0;
    int				numberPath[DLmaxLEVELS+1];

    unsigned char		addedString[200+1];
    int				addedStrlen;

    int				stroff;
    int				stroffShift;
    int				textAttributeNumber;
    int				sepAttributeNumber;

    int				partsMade= 0;
    int				makeSep= 0;
    int				sepKind= DOCkindTAB;

    TextAttribute		ta;
    PropertyMask		doneMask;

    TextParticule *		tp;

    utilInitTextAttribute( &ta );

    if  ( pp->ppListOverride <= 0 )
	{ LDEB(pp->ppListOverride); *pCalculated= 0; return 0; }

    /*  1,2,3,4  */
    if  ( docGetListOfParagraph( &lo, &root, &dl, pp->ppListOverride, bd ) )
	{ LLDEB(pp->ppListOverride,ilvl); *pCalculated= 0; return 0; }

    if  ( docListGetFormatPath( startPath, formatPath, &dll, ilvl, dl, lo ) )
	{ LLDEB(pp->ppListOverride,ilvl); *pCalculated= 0; return 0; }

    /*  5  */
    if  ( docListNumberTreeGetNumberPath( numberPath, root, ilvl, paraNr ) )
	{ LLDEB(pp->ppListOverride,ilvl); *pCalculated= 0; return 0; }

    /*  6  */
    addedStrlen= docCalculateListtextString(
				    addedString, sizeof(addedString)- 1, ilvl,
				    numberPath, startPath, formatPath, dll );
    if  ( addedStrlen < 0 )
	{ LLDEB(ilvl,addedStrlen); *pCalculated= 0; return 0;	}

    /*  7  */
    if  ( docFieldReplaceContents( &stroff,
			    &stroffShift, &textAttributeNumber,
			    bd, paraBi, part, partCount,
			    *pStroffShift, addedString, addedStrlen,
			    voidadd, closeObject ) )
	{ LDEB(1); return -1;	}

    if  ( stroff != 0 )
	{ LDEB(stroff);	}

    /*  8  */
    utilGetTextAttributeByNumber( &ta,
		    &(bd->bdTextAttributeList), textAttributeNumber );
    utilUpdateTextAttribute( &doneMask, &ta, &(dll->dllTextAttribute),
						&(dll->dllTextAttributeMask) );
    textAttributeNumber=
		utilTextAttributeNumber( &(bd->bdTextAttributeList), &ta );

    sepAttributeNumber= textAttributeNumber;

    if  ( dll->dllFollow != DOCllfNONE )
	{
	int		changed= 0;

	if  ( PROPmaskISSET( &(dll->dllTextAttributeMask),
						TApropTEXTUNDERLINED )	&&
	      ta.taTextIsUnderlined					)
	    { ta.taTextIsUnderlined= 0; changed= 1;	}

	if  ( PROPmaskISSET( &(dll->dllTextAttributeMask),
						TApropSTRIKETHROUGH )	&&
	      ta.taHasStrikethrough					)
	    { ta.taHasStrikethrough= 0; changed= 1;	}

	if  ( changed )
	    {
	    sepAttributeNumber=
		utilTextAttributeNumber( &(bd->bdTextAttributeList), &ta );
	    }
	}

    /*  9  */
    if  ( dll->dllFollow == DOCllfTAB )
	{ makeSep= 1; sepKind= DOCkindTAB;	}

    if  ( dll->dllFollow == DOCllfSPACE			&&
	  sepAttributeNumber != textAttributeNumber	)
	{ makeSep= 1; sepKind= DOCkindTEXT;	}

    tp= docInsertTextParticule( paraBi, part+ 1,
					    stroff, addedStrlen- makeSep,
					    DOCkindTEXT, textAttributeNumber );
    if  ( ! tp )
	{ XDEB(tp); *pCalculated= 0; return 0;	}
    partsMade++;

    /*  10  */
    if  ( makeSep )
	{
	tp= docInsertTextParticule( paraBi, part+ 2,
					    stroff+ addedStrlen- makeSep, 1,
					    sepKind, sepAttributeNumber );
	if  ( ! tp )
	    { XDEB(tp); *pCalculated= 0; return 0;	}
	partsMade++;
	}

    *pCalculated= 1;
    *pPartShift= partsMade- partCount;
    *pStroffShift += stroffShift;

    return 0;
    }