File: docExternalItem.c

package info (click to toggle)
ted 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 11,064 kB
  • ctags: 13,935
  • sloc: ansic: 120,446; makefile: 7,469; sh: 253
file content (198 lines) | stat: -rw-r--r-- 4,457 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
/************************************************************************/
/*									*/
/*  Buffer administration for 'ExternalItems' I.E. headers/footers and	*/
/*  foonotes/endnotes.							*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

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

#   include	<appDebugon.h>

#   include	"docBuf.h"

/************************************************************************/
/*									*/
/*  Kinds of Headers/Footers.						*/
/*									*/
/************************************************************************/

const int DOC_HeaderScopes[PAGES__COUNT]=
    {
    DOCinFIRST_HEADER,
    DOCinSECT_HEADER,
    DOCinSECT_HEADER,
    DOCinRIGHT_HEADER,
    DOCinLEFT_HEADER,
    };

const int DOC_FooterScopes[PAGES__COUNT]=
    {
    DOCinFIRST_FOOTER,
    DOCinSECT_FOOTER,
    DOCinSECT_FOOTER,
    DOCinRIGHT_FOOTER,
    DOCinLEFT_FOOTER,
    };

/************************************************************************/
/*									*/
/*  Initialise an ExternalItem.						*/
/*									*/
/************************************************************************/

void docInitExternalItem(	ExternalItem *	ei )
    {
    ei->eiItem= (BufferItem *)0;
    ei->eiPageFormattedFor= -1;

    ei->eiY0UsedTwips= 0;
    ei->eiY1UsedTwips= 0;
    ei->eiY0ReservedTwips= 0;
    ei->eiY1ReservedTwips= 0;

    ei->eiPageSelectedUpon= -1;

    return;
    }

void docCleanExternalItem(	BufferDocument *	bd,
				ExternalItem *		ei )
    {
    if  ( ei->eiItem )
	{ docFreeItem( bd, ei->eiItem );	}

    return;
    }

/************************************************************************/
/*									*/
/*  Make a new 'External Item' E.G. A section Header/Footer or a	*/
/*  Footnote/Endnote.							*/
/*									*/
/************************************************************************/

BufferItem * docMakeExternalItem(
			    BufferDocument *		bd,
			    const SelectionScope *	ss,
			    const SectionProperties *	sp )
    {
    BufferItem *	bi= (BufferItem *)malloc( sizeof(BufferItem) );

    const int		numberInParent= 0;

    if  ( ! bi )
	{ XDEB(bi); return (BufferItem *)0;	}

    docInitItem( bi, (BufferItem *)0, bd, numberInParent,
					DOClevSECT, ss->ssInExternalItem );

    if  ( docCopySectionProperties( &(bi->biSectProperties), sp ) )
	{
	LDEB(1);
	docFreeItem( bd, bi );
	return (BufferItem *)0;
	}

    bi->biSectBreakKind= DOCsbkNONE;

    bi->biSectSelectionScope= *ss;

    return bi;
    }

/************************************************************************/
/*									*/
/*  Make an external item and insert an empty paragraph into it.	*/
/*									*/
/************************************************************************/

BufferItem * docMakeExternalparagraph(
				BufferDocument *		bd,
				ExternalItem *			ei,
				const BufferItem *		bodyBi,
				TextAttribute			ta,
				int				noteIndex,
				int				inExtIt )
    {
    BufferItem *		paraBi= (BufferItem *)0;

    SectionProperties		spDef;

    int				numberInParent= -1;
    SelectionScope		ss;

    docInitSelectionScope( &ss );
    docInitSectionProperties( &spDef );

    switch( inExtIt )
	{
	case DOCinBODY:
	    LDEB(inExtIt); goto ready;

	case DOCinSECT_HEADER:
	case DOCinFIRST_HEADER:
	case DOCinLEFT_HEADER:
	case DOCinRIGHT_HEADER:
	case DOCinSECT_FOOTER:
	case DOCinFIRST_FOOTER:
	case DOCinLEFT_FOOTER:
	case DOCinRIGHT_FOOTER:

	    while( bodyBi && bodyBi->biLevel != DOClevSECT )
		{ bodyBi= bodyBi->biParent;	}
	    if  ( ! bodyBi )
		{ XDEB(bodyBi); goto ready;	}

	    numberInParent= bodyBi->biNumberInParent;
	    break;

	case DOCinFOOTNOTE:
	case DOCinENDNOTE:

	case DOCinFTNSEP:
	case DOCinFTNSEPC:
	case DOCinFTNCN:

	case DOCinAFTNSEP:
	case DOCinAFTNSEPC:
	case DOCinAFTNCN:

	    break;

	default:
	    LDEB(inExtIt); return (BufferItem *)0;
	}


    ss.ssInExternalItem= inExtIt;
    ss.ssSectNrExternalTo= numberInParent;
    ss.ssNoteArrayIndex= noteIndex;

    ei->eiItem= docMakeExternalItem( bd, &ss, &spDef );
    if  ( ! ei->eiItem )
	{ XDEB(ei->eiItem); goto ready;	}

    ei->eiPageFormattedFor= -1;
    ei->eiPageSelectedUpon= -1;

    paraBi= docInsertEmptyParagraph( bd, ei->eiItem, ta );
    if  ( ! paraBi )
	{
	XDEB(paraBi);
	docCleanExternalItem( bd, ei );
	docInitExternalItem( ei );
	goto ready;
	}

  ready:

    docCleanSectionProperties( &spDef );

    return paraBi;
    }