1 /************************************************************************/
2 /*									*/
3 /*  Buffer administration routines.					*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docBaseConfig.h"
8 
9 #   include	<stdio.h>
10 
11 #   include	<utilPropMask.h>
12 #   include	<appDebugon.h>
13 
14 #   include	"docNotesProperties.h"
15 
16 /************************************************************************/
17 
docSetNotesProperty(NotesProperties * np,int prop,int val)18 int docSetNotesProperty(		NotesProperties *	np,
19 					int			prop,
20 					int			val )
21     {
22     switch( prop )
23 	{
24 	case NOTESpropSTARTNR:
25 	    np->npStartNumber= val;
26 	    return 0;
27 	case NOTESpropJUSTIFICATION:
28 	    np->npJustification= val;
29 	    return 0;
30 	case NOTESpropPLACEMENT:
31 	    np->npPlacement= val;
32 	    return 0;
33 	case NOTESpropRESTART:
34 	    np->npRestart= val;
35 	    return 0;
36 	case NOTESpropSTYLE:
37 	    np->npNumberStyle= val;
38 	    return 0;
39 	default:
40 	    LDEB(prop); return -1;
41 	}
42     }
43 
docGetNotesProperty(const NotesProperties * np,int prop)44 int docGetNotesProperty(		const NotesProperties *	np,
45 					int			prop )
46     {
47     switch( prop )
48 	{
49 	case NOTESpropSTARTNR:
50 	    return np->npStartNumber;
51 	case NOTESpropJUSTIFICATION:
52 	    return np->npJustification;
53 	case NOTESpropPLACEMENT:
54 	    return np->npPlacement;
55 	case NOTESpropRESTART:
56 	    return np->npRestart;
57 	case NOTESpropSTYLE:
58 	    return np->npNumberStyle;
59 	default:
60 	    LDEB(prop); return -1;
61 	}
62     }
63 
64 /************************************************************************/
65 /*									*/
66 /*  Change note properties and tell what has been changed.		*/
67 /*									*/
68 /************************************************************************/
69 
docUpdNotesProperties(PropertyMask * pDoneMask,NotesProperties * np,const PropertyMask * setMask,const NotesProperties * npSet,const int propMap[NOTESprop_COUNT])70 static int docUpdNotesProperties(
71 		PropertyMask *			pDoneMask,
72 		NotesProperties *		np,
73 		const PropertyMask *		setMask,
74 		const NotesProperties *		npSet,
75 		const int			propMap[NOTESprop_COUNT] )
76     {
77     int		prop;
78     int		rval= 0;
79 
80     for ( prop= 0; prop < NOTESprop_COUNT; prop++ )
81 	{
82 	const int	pprop= propMap[prop];
83 	int		oval;
84 	int		nval;
85 
86 	if  ( pprop < 0				||
87 	      ! PROPmaskISSET( setMask, pprop )	)
88 	    { continue;	}
89 
90 	oval= docGetNotesProperty( np, prop );
91 	nval= docGetNotesProperty( npSet, prop );
92 	if  ( oval != nval )
93 	    {
94 	    if  ( docSetNotesProperty( np, prop, nval ) )
95 		{ LLLDEB(prop,pprop,nval); rval= -1;	}
96 
97 	    PROPmaskADD( pDoneMask, pprop );
98 	    }
99 	}
100 
101     return rval;
102     }
103 
docUpdFootEndNotesProperties(PropertyMask * pDoneMask,FootEndNotesProperties * fep,const PropertyMask * setMask,const FootEndNotesProperties * fepSet,const int fepPropMap[FEPprop_COUNT])104 int docUpdFootEndNotesProperties(
105 		PropertyMask *			pDoneMask,
106 		FootEndNotesProperties *	fep,
107 		const PropertyMask *		setMask,
108 		const FootEndNotesProperties *	fepSet,
109 		const int			fepPropMap[FEPprop_COUNT] )
110     {
111     docUpdNotesProperties( pDoneMask, &(fep->fepFootnotesProps),
112 				setMask, &(fepSet->fepFootnotesProps),
113 				fepPropMap+ FEPpropFOOT_STARTNR );
114 
115     docUpdNotesProperties( pDoneMask, &(fep->fepEndnotesProps),
116 				setMask, &(fepSet->fepEndnotesProps),
117 				fepPropMap+ FEPpropEND_STARTNR );
118 
119     return 0;
120     }
121 
122 /************************************************************************/
123 /*									*/
124 /*  Compare note properties.						*/
125 /*									*/
126 /************************************************************************/
127 
docNotesPropertyDifference(PropertyMask * pDifMask,const NotesProperties * np1,const PropertyMask * cmpMask,const NotesProperties * np2,const int propMap[NOTESprop_COUNT])128 static int docNotesPropertyDifference(
129 		PropertyMask *			pDifMask,
130 		const NotesProperties *		np1,
131 		const PropertyMask *		cmpMask,
132 		const NotesProperties *		np2,
133 		const int			propMap[NOTESprop_COUNT] )
134     {
135     int		prop;
136     int		rval= 0;
137 
138     for ( prop= 0; prop < NOTESprop_COUNT; prop++ )
139 	{
140 	const int	pprop= propMap[prop];
141 	int		oval;
142 	int		nval;
143 
144 	if  ( pprop < 0				||
145 	      ! PROPmaskISSET( cmpMask, pprop )	)
146 	    { continue;	}
147 
148 	oval= docGetNotesProperty( np1, prop );
149 	nval= docGetNotesProperty( np2, prop );
150 	if  ( oval != nval )
151 	    { PROPmaskADD( pDifMask, pprop );	}
152 	}
153 
154     return rval;
155     }
156 
docFootEndNotesPropertyDifference(PropertyMask * pDifMask,const FootEndNotesProperties * fep1,const PropertyMask * cmpMask,const FootEndNotesProperties * fep2,const int fepPropMap[FEPprop_COUNT])157 int docFootEndNotesPropertyDifference(
158 		PropertyMask *			pDifMask,
159 		const FootEndNotesProperties *	fep1,
160 		const PropertyMask *		cmpMask,
161 		const FootEndNotesProperties *	fep2,
162 		const int			fepPropMap[FEPprop_COUNT] )
163     {
164     docNotesPropertyDifference( pDifMask, &(fep1->fepFootnotesProps),
165 				cmpMask, &(fep2->fepFootnotesProps),
166 				fepPropMap+ FEPpropFOOT_STARTNR );
167     docNotesPropertyDifference( pDifMask, &(fep1->fepEndnotesProps),
168 				cmpMask, &(fep2->fepEndnotesProps),
169 				fepPropMap+ FEPpropEND_STARTNR );
170     return 0;
171     }
172 
docInitNotesProperties(NotesProperties * np)173 void docInitNotesProperties(	NotesProperties *	np )
174     {
175     np->npStartNumber= 1;
176     np->npJustification= FTNjustifyPAGE_BOTTOM;
177     np->npPlacement= FTNplaceSECT_END;
178     np->npRestart= FTN_RST_CONTINUOUS;
179     np->npNumberStyle= FTNstyleNAR;
180 
181     return;
182     }
183 
docDefaultFootNotesProperties(NotesProperties * np)184 void docDefaultFootNotesProperties(	NotesProperties *	np )
185     {
186     np->npStartNumber= 1;
187     np->npJustification= FTNjustifyPAGE_BOTTOM;
188     np->npPlacement= FTNplacePAGE_END;
189     np->npRestart= FTN_RST_CONTINUOUS;
190     np->npNumberStyle= FTNstyleNAR;
191 
192     return;
193     }
194 
docDefaultEndNotesProperties(NotesProperties * np)195 void docDefaultEndNotesProperties(	NotesProperties *	np )
196     {
197     np->npStartNumber= 1;
198     np->npJustification= FTNjustifyBELOW_TEXT;
199     np->npPlacement= FTNplaceSECT_END;
200     np->npRestart= FTN_RST_CONTINUOUS;
201     np->npNumberStyle= FTNstyleNRLC;
202 
203     return;
204     }
205 
docInitFootEndNotesProperties(FootEndNotesProperties * fep)206 void docInitFootEndNotesProperties(	FootEndNotesProperties *	fep )
207     {
208     docInitNotesProperties( &(fep->fepFootnotesProps) );
209     docInitNotesProperties( &(fep->fepEndnotesProps) );
210     }
211 
docDefaultFootEndNotesProperties(FootEndNotesProperties * fep)212 void docDefaultFootEndNotesProperties(	FootEndNotesProperties *	fep )
213     {
214     docDefaultFootNotesProperties( &(fep->fepFootnotesProps) );
215     docDefaultEndNotesProperties( &(fep->fepEndnotesProps) );
216     }
217 
docNotesJustificationStr(int pos)218 const char * docNotesJustificationStr( int pos )
219     {
220     static char scratch[20];
221 
222     switch( pos )
223 	{
224 	case FTNjustifyBELOW_TEXT:	return "BELOW_TEXT";
225 	case FTNjustifyPAGE_BOTTOM:	return "PAGE_BOTTOM";
226 
227 	default:
228 	    sprintf( scratch, "%d", pos );
229 	    return scratch;
230 	}
231     }
232 
docNotesPlacementStr(int pos)233 const char * docNotesPlacementStr( int pos )
234     {
235     static char scratch[20];
236 
237     switch( pos )
238 	{
239 	case FTNplaceSECT_END:	return "SECT_END";
240 	case FTNplaceDOC_END:	return "DOC_END";
241 
242 	default:
243 	    sprintf( scratch, "%d", pos );
244 	    return scratch;
245 	}
246     }
247