File: docListOverrideTable.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 (145 lines) | stat: -rw-r--r-- 3,600 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
/************************************************************************/
/*									*/
/*  Management of the list table of a document.				*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

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

#   include	<appDebugon.h>

#   include	"docListOverrideTable.h"

void docInitListOverrideTable(		ListOverrideTable *		lot )
    {
    lot->lotOverrides= (ListOverride *)0;
    lot->lotOverrideCount= 0;

    return;
    }

void docCleanListOverrideTable(		ListOverrideTable *		lot )
    {
    int		i;

    for ( i= 0; i < lot->lotOverrideCount; i++ )
	{ docCleanListOverride( &(lot->lotOverrides[i]) );	}

    if  ( lot->lotOverrides )
	{ free( (void *)lot->lotOverrides );	}

    return;
    }

int docCopyListOverrideTable(	ListOverrideTable *		to,
				const ListOverrideTable *	from )
    {
    int			i;

    const int * const	fontMap= (const int *)0;
    const int * const	colorMap= (const int *)0;

    if  ( to->lotOverrideCount > from->lotOverrideCount )
	{
	for ( i= from->lotOverrideCount; i < to->lotOverrideCount; i++ )
	    { docCleanListOverride( &(to->lotOverrides[i]) );	}

	to->lotOverrideCount= from->lotOverrideCount;
	}

    if  ( to->lotOverrideCount < from->lotOverrideCount )
	{
	ListOverride *	fresh;

	fresh= realloc( to->lotOverrides,
				from->lotOverrideCount* sizeof(ListOverride) );
	if  ( ! fresh )
	    { LXDEB(from->lotOverrideCount,fresh); return -1;	}

	to->lotOverrides= fresh;

	while( to->lotOverrideCount < from->lotOverrideCount )
	    {
	    docInitListOverride( &(to->lotOverrides[to->lotOverrideCount++]) );
	    }
	}

    for ( i= 0; i < from->lotOverrideCount; i++ )
	{
	if  ( docCopyListOverride( &(to->lotOverrides[i]),
				&(from->lotOverrides[i]), fontMap, colorMap ) )
	    { LDEB(i); return -1;	}
	}

    return 0;
    }

/************************************************************************/
/*									*/
/*  Add a list to the listtable.					*/
/*									*/
/************************************************************************/

int docListOverrideTableAddOverride(	ListOverrideTable *	lot,
					const ListOverride *	lo,
					int			idx,
					const int *		fontMap,
					const int *		colorMap )
    {
    if  ( idx >= lot->lotOverrideCount )
	{
	ListOverride *	fresh;

	fresh= (ListOverride *)realloc( lot->lotOverrides,
				    (idx+ 1)* sizeof(ListOverride) );
	if  ( ! fresh )
	    { LXDEB(idx,fresh); return -1;	}

	lot->lotOverrides= fresh;

	fresh += lot->lotOverrideCount;
	while( lot->lotOverrideCount <= idx )
	    {
	    docInitListOverride( fresh );
	    lot->lotOverrideCount++; fresh++;
	    }
	}

    if  ( docCopyListOverride( lot->lotOverrides+ idx, lo, fontMap, colorMap ) )
	{ LDEB(lot->lotOverrideCount); return -1;	}
    lot->lotOverrides[idx].loIndex= idx;
    lot->lotOverrides[idx].loListIndex= -1;

    return 0;
    }

extern int docMergeListOverrideIntoTable(
					ListOverrideTable *	lot,
					const ListOverride *	loNew,
					const int *		fontMap,
					const int *		colorMap )
    {
    int			idx= lot->lotOverrideCount;

    if  ( idx < 1 )
	{ idx=  1;	}

    if  ( loNew->loIndex >= 0					&&
	  loNew->loIndex < lot->lotOverrideCount		&&
	  lot->lotOverrides[loNew->loIndex].loIndex ==
					    loNew->loIndex	&&
	  lot->lotOverrides[loNew->loIndex].loListID ==
					    loNew->loListID	)
	{ return loNew->loIndex;	}

    if  ( docListOverrideTableAddOverride( lot, loNew, idx,
							fontMap, colorMap ) )
	{ LLDEB(idx,lot->lotOverrideCount); return -1;	}

    return idx;
    }