1 /************************************************************************/
2 /*									*/
3 /*  Bookkeeping about merge fields.					*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docBaseConfig.h"
8 
9 #   include	<appDebugon.h>
10 
11 #   include	"docDocumentField.h"
12 #   include	"docMergeField.h"
13 #   include	"docFieldFormat.h"
14 
docInitMergeField(MergeField * mf)15 void docInitMergeField(	MergeField *	mf )
16     {
17     utilInitMemoryBuffer( &(mf->mfFieldName) );
18     utilInitMemoryBuffer( &(mf->mfTextBefore) );
19     utilInitMemoryBuffer( &(mf->mfTextAfter) );
20 
21     mf->mfIsMapped= 0;
22     mf->mfEnableVertival= 0;
23     mf->mfCaseShift= MERGE_ASIS;
24 
25     return;
26     }
27 
docCleanMergeField(MergeField * mf)28 void docCleanMergeField(	MergeField *	mf )
29     {
30     utilCleanMemoryBuffer( &(mf->mfFieldName) );
31     utilCleanMemoryBuffer( &(mf->mfTextBefore) );
32     utilCleanMemoryBuffer( &(mf->mfTextAfter) );
33     }
34 
docGetMergeField(MergeField * mf,const DocumentField * df)35 int docGetMergeField(		MergeField *			mf,
36 				const DocumentField *		df )
37     {
38     const FieldInstructions *		fi= &(df->dfInstructions);
39     const InstructionsComponent *	ic;
40     int					comp;
41 
42     if  ( df->dfKind != DOCfkMERGEFIELD )
43 	{ return 1;	}
44 
45     ic= fi->fiComponents+ 1;
46     for ( comp= 1; comp < fi->fiComponentCount; ic++, comp++ )
47 	{
48 	if  ( docComponentIsFlag( fi, comp, 'm' ) )
49 	    { mf->mfIsMapped= 1; continue;	}
50 	if  ( docComponentIsFlag( fi, comp, 'v' ) )
51 	    { mf->mfEnableVertival= 1; continue;	}
52 
53 	if  ( docComponentIsArgFlag( fi, comp, 'b' ) )
54 	    {
55 	    ic++, comp++;
56 
57 	    if  ( utilCopyMemoryBuffer( &(mf->mfTextBefore), &(ic->icBuffer) ) )
58 		{ LDEB(comp);	}
59 
60 	    continue;
61 	    }
62 
63 	if  ( docComponentIsArgFlag( fi, comp, 'f' ) )
64 	    {
65 	    ic++, comp++;
66 
67 	    if  ( utilCopyMemoryBuffer( &(mf->mfTextAfter), &(ic->icBuffer) ) )
68 		{ LDEB(comp);	}
69 
70 	    continue;
71 	    }
72 
73 	if  ( ! ic->icIsFlag )
74 	    {
75 	    if  ( utilCopyMemoryBuffer( &(mf->mfFieldName), &(ic->icBuffer) ) )
76 		{ LDEB(comp);	}
77 
78 	    continue;
79 	    }
80 
81 	if  ( docComponentIsArgFlag( fi, comp, '*' ) )
82 	    {
83 	    ic++, comp++;
84 
85 	    if  ( docFieldComponentCaseShift( &(mf->mfCaseShift), ic ) )
86 		{ LDEB(comp);	}
87 
88 	    continue;
89 	    }
90 
91 	LDEB(comp);
92 	}
93 
94     return 0;
95     }
96 
97