1 /** getput-templ.c  -  Auxiliary functions template: cloning, freeing, walking data
2  ** Copyright (c) 2006 Symlabs (symlabs@symlabs.com), All Rights Reserved.
3  ** Author: Sampo Kellomaki (sampo@iki.fi)
4  ** This is confidential unpublished proprietary source code of the author.
5  ** NO WARRANTY, not even implied warranties. Contains trade secrets.
6  ** Distribution prohibited unless authorized in writing.
7  ** Licensed under Apache License 2.0, see file COPYING.
8  ** $Id: getput-templ.c,v 1.8 2009-08-30 15:09:26 sampo Exp $
9  **
10  ** 30.5.2006, created, Sampo Kellomaki (sampo@iki.fi)
11  ** 6.8.2006, factored from enc-templ.c to separate file --Sampo
12  **
13  ** N.B: wo=wire order (needed for exc-c14n), so=schema order
14  ** Edit with care! xsd2sg.pl applies various substitutions to this file.
15  **/
16 
17 #if 1 /* GETPUT_SUBTEMPL */
18 
19 #ifdef ZX_ENA_GETPUT
20 
21 /* FUNC(ELTYPE_NUM_FNAME) */
22 
23 int ELTYPE_NUM_FNAME(struct ELTYPE_s* x)
24 {
25   struct FTYPE_s* y;
26   int n = 0;
27   if (!x) return 0;
28   for (y = x->FNAME; y && y->gg.g.tok == FTYPE_ELEM; ++n, y = (struct FTYPE_s*)y->gg.g.n) ;
29   return n;
30 }
31 
32 /* FUNC(ELTYPE_GET_FNAME) */
33 
34 struct FTYPE_s* ELTYPE_GET_FNAME(struct ELTYPE_s* x, int n)
35 {
36   struct FTYPE_s* y;
37   if (!x) return 0;
38   for (y = x->FNAME; n>=0 && y && y->gg.g.tok == FTYPE_ELEM; --n, y = (struct FTYPE_s*)y->gg.g.n) ;
39   return y;
40 }
41 
42 /* FUNC(ELTYPE_POP_FNAME) */
43 
44 struct FTYPE_s* ELTYPE_POP_FNAME(struct ELTYPE_s* x)
45 {
46   struct FTYPE_s* y;
47   if (!x) return 0;
48   y = x->FNAME;
49   if (y)
50     x->FNAME = (struct FTYPE_s*)y->gg.g.n;
51   return y;
52 }
53 
54 /* FUNC(ELTYPE_PUSH_FNAME) */
55 
56 void ELTYPE_PUSH_FNAME(struct ELTYPE_s* x, struct FTYPE_s* z)
57 {
58   if (!x || !z) return;
59   z->gg.g.n = &x->FNAME->gg.g;
60   x->FNAME = z;
61 }
62 
63 /* FUNC(ELTYPE_REV_FNAME) */
64 
65 void ELTYPE_REV_FNAME(struct ELTYPE_s* x)
66 {
67   struct FTYPE_s* nxt;
68   struct FTYPE_s* y;
69   if (!x) return;
70   y = x->FNAME;
71   if (!y) return;
72   x->FNAME = 0;
73   while (y) {
74     nxt = (struct FTYPE_s*)y->gg.g.n;
75     y->gg.g.n = &x->FNAME->gg.g;
76     x->FNAME = y;
77     y = nxt;
78   }
79 }
80 
81 /* FUNC(ELTYPE_PUT_FNAME) */
82 
83 void ELTYPE_PUT_FNAME(struct ELTYPE_s* x, int n, struct FTYPE_s* z)
84 {
85   struct FTYPE_s* y;
86   if (!x || !z) return;
87   y = x->FNAME;
88   if (!y) return;
89   switch (n) {
90   case 0:
91     z->gg.g.n = y->gg.g.n;
92     x->FNAME = z;
93     return;
94   default:
95     for (; n > 1 && y->gg.g.n && y->gg.g.n->gg.g.tok == FTYPE_ELEM; --n, y = (struct FTYPE_s*)y->gg.g.n) ;
96     if (!y->gg.g.n) return;
97     z->gg.g.n = y->gg.g.n->n;
98     y->gg.g.n = &z->gg.g;
99   }
100 }
101 
102 /* FUNC(ELTYPE_ADD_FNAME) */
103 
104 void ELTYPE_ADD_FNAME(struct ELTYPE_s* x, int n, struct FTYPE_s* z)
105 {
106   struct FTYPE_s* y;
107   if (!x || !z) return;
108   switch (n) {
109   case 0:
110   add_to_start:
111     z->gg.g.n = &x->FNAME->gg.g;
112     x->FNAME = z;
113     return;
114   case -1:
115     y = x->FNAME;
116     if (!y) goto add_to_start;
117     for (; y->gg.g.n && y->gg.g.n->gg.g.tok == FTYPE_ELEM; y = (struct FTYPE_s*)y->gg.g.n) ;
118     break;
119   default:
120     for (y = x->FNAME; n > 1 && y && y->gg.g.tok == FTYPE_ELEM; --n, y = (struct FTYPE_s*)y->gg.g.n) ;
121     if (!y) return;
122   }
123   z->gg.g.n = y->gg.g.n;
124   y->gg.g.n = &z->gg.g;
125 }
126 
127 /* FUNC(ELTYPE_DEL_FNAME) */
128 
129 void ELTYPE_DEL_FNAME(struct ELTYPE_s* x, int n)
130 {
131   struct FTYPE_s* y;
132   if (!x) return;
133   switch (n) {
134   case 0:
135     x->FNAME = (struct FTYPE_s*)x->FNAME->gg.g.n;
136     return;
137   case -1:
138     y = (struct FTYPE_s*)x->FNAME;
139     if (!y) return;
140     for (; y->gg.g.n && y->gg.g.n->gg.g.tok == FTYPE_ELEM; y = (struct FTYPE_s*)y->gg.g.n) ;
141     break;
142   default:
143     for (y = x->FNAME; n > 1 && y->gg.g.n && y->gg.g.n->gg.g.tok == FTYPE_ELEM; --n, y = (struct FTYPE_s*)y->gg.g.n) ;
144     if (!y->gg.g.n) return;
145   }
146   y->gg.g.n = y->gg.g.n->n;
147 }
148 
149 #endif
150 
151 #endif /* GETPUT_SUBTEMPL */
152 
153 /* EOF */
154