1 /************************************************************************/
2 /*									*/
3 /*  Management of the list table of a document.				*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docBaseConfig.h"
8 
9 #   include	<stdlib.h>
10 
11 #   include	<appDebugon.h>
12 
13 #   include	"docListOverride.h"
14 #   include	"docListOverrideTable.h"
15 
docInitListOverrideTable(ListOverrideTable * lot)16 void docInitListOverrideTable(		ListOverrideTable *		lot )
17     {
18     lot->lotOverrides= (ListOverride *)0;
19     lot->lotOverrideCount= 0;
20 
21     return;
22     }
23 
docCleanListOverrideTable(ListOverrideTable * lot)24 void docCleanListOverrideTable(		ListOverrideTable *		lot )
25     {
26     int		i;
27 
28     for ( i= 0; i < lot->lotOverrideCount; i++ )
29 	{ docCleanListOverride( &(lot->lotOverrides[i]) );	}
30 
31     if  ( lot->lotOverrides )
32 	{ free( (void *)lot->lotOverrides );	}
33 
34     return;
35     }
36 
docCopyListOverrideTable(ListOverrideTable * to,const ListOverrideTable * from)37 int docCopyListOverrideTable(	ListOverrideTable *		to,
38 				const ListOverrideTable *	from )
39     {
40     int			i;
41 
42     if  ( to->lotOverrideCount > from->lotOverrideCount )
43 	{
44 	for ( i= from->lotOverrideCount; i < to->lotOverrideCount; i++ )
45 	    { docCleanListOverride( &(to->lotOverrides[i]) );	}
46 
47 	to->lotOverrideCount= from->lotOverrideCount;
48 	}
49 
50     if  ( to->lotOverrideCount < from->lotOverrideCount )
51 	{
52 	ListOverride *	fresh;
53 
54 	fresh= (ListOverride *)realloc( to->lotOverrides,
55 				from->lotOverrideCount* sizeof(ListOverride) );
56 	if  ( ! fresh )
57 	    { LXDEB(from->lotOverrideCount,fresh); return -1;	}
58 
59 	to->lotOverrides= fresh;
60 
61 	while( to->lotOverrideCount < from->lotOverrideCount )
62 	    {
63 	    docInitListOverride( &(to->lotOverrides[to->lotOverrideCount++]) );
64 	    }
65 	}
66 
67     for ( i= 0; i < from->lotOverrideCount; i++ )
68 	{
69 	if  ( docCopyListOverrideSameDocument( &(to->lotOverrides[i]),
70 						&(from->lotOverrides[i]) ) )
71 	    { LDEB(i); return -1;	}
72 	}
73 
74     return 0;
75     }
76 
77 /************************************************************************/
78 /*									*/
79 /*  Add a list to the listtable.					*/
80 /*									*/
81 /************************************************************************/
82 
docListOverrideTableAddOverride(ListOverride ** pLo,ListOverrideTable * lot,int ls,int listId,int listIndex)83 int docListOverrideTableAddOverride(	ListOverride **		pLo,
84 					ListOverrideTable *	lot,
85 					int			ls,
86 					int			listId,
87 					int			listIndex )
88     {
89     if  ( ls < 0 )
90 	{ ls= lot->lotOverrideCount;	}
91     if  ( ls < 1 )
92 	{ ls=  1;			}
93 
94     if  ( ls >= lot->lotOverrideCount )
95 	{
96 	ListOverride *	fresh;
97 
98 	fresh= (ListOverride *)realloc( lot->lotOverrides,
99 				    (ls+ 1)* sizeof(ListOverride) );
100 	if  ( ! fresh )
101 	    { LXDEB(ls,fresh); return -1;	}
102 
103 	lot->lotOverrides= fresh;
104 
105 	fresh += lot->lotOverrideCount;
106 	while( lot->lotOverrideCount <= ls )
107 	    {
108 	    docInitListOverride( fresh );
109 	    lot->lotOverrideCount++; fresh++;
110 	    }
111 	}
112 
113     lot->lotOverrides[ls].loIndex= ls;
114     lot->lotOverrides[ls].loListID= listId;
115     lot->lotOverrides[ls].loListIndex= listIndex;
116 
117     if  ( pLo )
118 	{ *pLo= lot->lotOverrides+ ls;	}
119 
120     return ls;
121     }
122 
docMergeListOverrideIntoTable(ListOverrideTable * lot,const ListOverride * loSet,const int * fontMap,const int * colorMap,const int * rulerMap)123 int docMergeListOverrideIntoTable(	ListOverrideTable *	lot,
124 					const ListOverride *	loSet,
125 					const int *		fontMap,
126 					const int *		colorMap,
127 					const int *		rulerMap )
128     {
129     int			ls;
130     ListOverride *	lo;
131 
132     if  ( loSet->loIndex > 0						&&
133 	  loSet->loIndex < lot->lotOverrideCount			&&
134 	  lot->lotOverrides[loSet->loIndex].loIndex ==
135 						    loSet->loIndex	&&
136 	  lot->lotOverrides[loSet->loIndex].loListID ==
137 						    loSet->loListID	)
138 	{ return loSet->loIndex;	}
139 
140     ls= docListOverrideTableAddOverride( &lo, lot, -1,
141 					loSet->loListID, loSet->loListIndex );
142     if  ( ls < 0 )
143 	{ LLDEB(ls,lot->lotOverrideCount); return -1;	}
144 
145     if  ( docCopyListOverride( lo, loSet, fontMap, colorMap, rulerMap ) )
146 	{ LDEB(ls); return -1;	}
147 
148     return ls;
149     }
150 
docListOverrideTableSetOverride(ListOverrideTable * lot,const ListOverride * loSet,const int * fontMap,const int * colorMap,const int * rulerMap)151 int docListOverrideTableSetOverride(
152 				ListOverrideTable *		lot,
153 				const ListOverride *		loSet,
154 				const int *			fontMap,
155 				const int *			colorMap,
156 				const int *			rulerMap )
157     {
158     int			ls= loSet->loIndex;
159     ListOverride *	lo;
160 
161     if  ( ls >= lot->lotOverrideCount )
162 	{
163 	ls= docListOverrideTableAddOverride( &lo, lot,
164 				    ls, loSet->loListID, loSet->loListIndex );
165 	if  ( ls < 0 )
166 	    { LLDEB(ls,lot->lotOverrideCount); return -1;	}
167 	}
168     else{
169 	lo= lot->lotOverrides+ ls;
170 	}
171 
172     if  ( docCopyListOverride( lo, loSet, fontMap, colorMap, rulerMap ) )
173 	{ LDEB(ls); return -1;	}
174 
175     return ls;
176     }
177 
178 /************************************************************************/
179 /*									*/
180 /*  delete a list from the table.					*/
181 /*									*/
182 /************************************************************************/
183 
docListOverrideTableDeleteOverride(ListOverrideTable * lot,int ls)184 int docListOverrideTableDeleteOverride(	ListOverrideTable *	lot,
185 					int			ls )
186     {
187     if  ( ls < 0 || ls >= lot->lotOverrideCount )
188 	{ LLDEB(ls,lot->lotOverrideCount); return -1;	}
189 
190     docCleanListOverride( lot->lotOverrides+ ls );
191     docInitListOverride( lot->lotOverrides+ ls );
192 
193     return 0;
194     }
195 
196