1 /************************************************************************/
2 /*									*/
3 /*  Manage a lookup to keep track of the different possible rulers for	*/
4 /*  a paragraph								*/
5 /*									*/
6 /************************************************************************/
7 
8 #   include	"docBaseConfig.h"
9 
10 #   include	<stdlib.h>
11 
12 #   include	<appDebugon.h>
13 
14 #   include	"docParaRulerAdmin.h"
15 
16 /************************************************************************/
17 
docGetTabStopListProperty(const TabStopList * tsl,int prop)18 static int docGetTabStopListProperty(	const TabStopList *	tsl,
19 					int			prop )
20     {
21     if  ( prop < 0 )
22 	{ LDEB(prop); return -1;	}
23     if  ( prop >= 1+ tsl->tslTabStopCount* TABprop_COUNT )
24 	{
25 	LLLDEB(prop,tsl->tslTabStopCount,tsl->tslTabStopCount* TABprop_COUNT);
26 	return 0;
27 	}
28 
29     if  ( prop == 0 )
30 	{ return tsl->tslTabStopCount;	}
31 
32     prop--;
33 
34     return docTabStopGetProperty( tsl->tslTabStops+ (prop / TABprop_COUNT),
35 						     prop % TABprop_COUNT );
36     }
37 
38 /************************************************************************/
39 /*									*/
40 /*  Initialize/Clean attribute administration.				*/
41 /*									*/
42 /************************************************************************/
43 
docInitTabStopListList(NumberedPropertiesList * tsll)44 void docInitTabStopListList(	NumberedPropertiesList *	tsll )
45     {
46     int			num;
47     TabStopList		tsl;
48 
49     utilInitNumberedPropertiesList( tsll );
50 
51     utilStartNumberedPropertyList( tsll,
52 
53 		    1, /* An arbitrary value */
54 		    (NumberedPropertiesGetProperty)docGetTabStopListProperty,
55 
56 		    sizeof(TabStopList),
57 		    (InitPagedListItem)docInitTabStopList,
58 		    (CleanPagedListItem)docCleanTabStopList );
59 
60     docInitTabStopList( &tsl );
61 
62     num= docTabStopListNumberImpl( tsll, &tsl );
63     if  ( num != 0 )
64 	{ LDEB(num);	}
65 
66     docCleanTabStopList( &tsl );
67 
68     return;
69     }
70 
71 /************************************************************************/
72 /*									*/
73 /*  Translate a ruler number to a value.				*/
74 /*									*/
75 /************************************************************************/
76 
docGetTabStopListByNumberImpl(TabStopList * tsl,const NumberedPropertiesList * tsll,int n)77 void docGetTabStopListByNumberImpl(	TabStopList *			tsl,
78 					const NumberedPropertiesList *	tsll,
79 					int				n )
80     {
81     void *	vtsl= utilPagedListGetItemByNumber( &(tsll->nplPagedList), n );
82 
83     if  ( ! vtsl )
84 	{ LXDEB(n,vtsl); docInitTabStopList( tsl ); return; }
85 
86     *tsl= *((TabStopList *)vtsl);
87     return;
88     }
89 
90 /************************************************************************/
91 /*									*/
92 /*  Translate a text attribute to its number.				*/
93 /*									*/
94 /************************************************************************/
95 
docTabStopListNumberImpl(NumberedPropertiesList * npl,const TabStopList * tsl)96 int docTabStopListNumberImpl(	NumberedPropertiesList *	npl,
97 				const TabStopList *		tsl )
98     {
99     const int		make= 1;
100 
101     int			prop;
102     IntegerValueNode *	ivn= &(npl->nplValueNodes);
103     void *		vta;
104 
105     int			propCount= 1+ tsl->tslTabStopCount* TABprop_COUNT;
106 
107     if  ( propCount < 1 )
108 	{ LDEB(propCount); return -1;	}
109     if  ( ! npl->nplGetProperty )
110 	{ XDEB(npl->nplGetProperty); return -1;	}
111 
112     for ( prop= 0; prop < propCount; prop++ )
113 	{
114 	int	propval= (*npl->nplGetProperty)( tsl, prop );
115 
116 	ivn= utilChildIntegerValueNode( ivn, make, propval );
117 	if  ( ! ivn )
118 	    {
119 	    if  ( make )
120 		{ LLXDEB(propval,make,ivn);	}
121 	    return -1;
122 	    }
123 	}
124 
125     if  ( ivn->ivnIsLeaf )
126 	{ return ivn->ivnReference;	}
127 
128     vta= utilPagedListClaimItemAtEnd( &(ivn->ivnReference),
129 						    &(npl->nplPagedList) );
130     if  ( ! vta )
131 	{ XDEB(vta); return -1;	}
132 
133     if  ( docCopyTabStopList( (TabStopList *)vta, tsl ) )
134 	{ LDEB(tsl->tslTabStopCount); return -1;	}
135     ivn->ivnIsLeaf= 1;
136 
137     return ivn->ivnReference;
138     }
139 
140 /************************************************************************/
141 /*									*/
142 /*  Merge ruler lists and create a mapping.				*/
143 /*									*/
144 /************************************************************************/
145 
docMergeTabstopListLists(int ** pRulerMap,NumberedPropertiesList * tsllTo,const NumberedPropertiesList * tsllFrom)146 int docMergeTabstopListLists(	int **				pRulerMap,
147 				NumberedPropertiesList *	tsllTo,
148 				const NumberedPropertiesList *	tsllFrom )
149     {
150     int		fromCount= tsllFrom->nplPagedList.plItemCount;
151 
152     if  ( fromCount > 0 )
153 	{
154 	int		fr;
155 	int *		rmap= (int *)malloc( fromCount* sizeof(int) );
156 
157 	if  ( ! rmap )
158 	    { LXDEB(fromCount,rmap); return -1; }
159 
160 	for ( fr= 0; fr < fromCount; fr++ )
161 	    { rmap[fr]= -1;	}
162 
163 	for ( fr= 0; fr < fromCount; fr++ )
164 	    {
165 	    int				to;
166 	    void *			vtsl;
167 	    TabStopList			tsl;
168 
169 	    vtsl= utilPagedListGetItemByNumber( &(tsllFrom->nplPagedList), fr );
170 	    if  ( ! vtsl )
171 		{ continue;	}
172 
173 	    tsl= *((TabStopList *)vtsl);
174 
175 	    to= docTabStopListNumberImpl( tsllTo, &tsl );
176 	    if  ( to < 0 )
177 		{ LDEB(to); free( rmap ); return -1;	}
178 	    rmap[fr]= to;
179 	    }
180 
181 	if  ( pRulerMap )
182 	    { *pRulerMap= rmap;		}
183 	else{ free( rmap );		}
184 	}
185 
186     return 0;
187     }
188 
189