1 /***************************************************************************
2     begin       : Thu Jul 02 2009
3     copyright   : (C) 2009 by Martin Preuss
4     email       : martin@libchipcard.de
5 
6  ***************************************************************************
7  *          Please see toplevel file COPYING for license details           *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 
15 #include "tm_inline_p.h"
16 #include "tm_util.h"
17 
18 
19 #include <gwenhywfar/debug.h>
20 #include <gwenhywfar/misc.h>
21 
22 #include <assert.h>
23 
24 
25 
GWEN_LIST_FUNCTIONS(TYPEMAKER2_INLINE,Typemaker2_Inline)26 GWEN_LIST_FUNCTIONS(TYPEMAKER2_INLINE, Typemaker2_Inline)
27 
28 
29 
30 TYPEMAKER2_INLINE *Typemaker2_Inline_new()
31 {
32   TYPEMAKER2_INLINE *th;
33 
34   GWEN_NEW_OBJECT(TYPEMAKER2_INLINE, th);
35   th->refCount=1;
36   GWEN_LIST_INIT(TYPEMAKER2_INLINE, th);
37 
38   return th;
39 }
40 
41 
42 
Typemaker2_Inline_free(TYPEMAKER2_INLINE * th)43 void Typemaker2_Inline_free(TYPEMAKER2_INLINE *th)
44 {
45   if (th) {
46     assert(th->refCount);
47     if (th->refCount==1) {
48       GWEN_LIST_FINI(TYPEMAKER2_INLINE, th);
49       free(th->content);
50       th->refCount=0;
51       GWEN_FREE_OBJECT(th);
52     }
53     else
54       th->refCount++;
55   }
56 }
57 
58 
59 
Typemaker2_Inline_Attach(TYPEMAKER2_INLINE * th)60 void Typemaker2_Inline_Attach(TYPEMAKER2_INLINE *th)
61 {
62   assert(th);
63   assert(th->refCount);
64   th->refCount++;
65 }
66 
67 
68 
Typemaker2_Inline_GetContent(const TYPEMAKER2_INLINE * th)69 const char *Typemaker2_Inline_GetContent(const TYPEMAKER2_INLINE *th)
70 {
71   assert(th);
72   assert(th->refCount);
73   return th->content;
74 }
75 
76 
77 
Typemaker2_Inline_SetContent(TYPEMAKER2_INLINE * th,const char * s)78 void Typemaker2_Inline_SetContent(TYPEMAKER2_INLINE *th, const char *s)
79 {
80   assert(th);
81   assert(th->refCount);
82   free(th->content);
83   if (s)
84     th->content=strdup(s);
85   else
86     th->content=NULL;
87 }
88 
89 
90 
Typemaker2_Inline_GetLocation(const TYPEMAKER2_INLINE * th)91 int Typemaker2_Inline_GetLocation(const TYPEMAKER2_INLINE *th)
92 {
93   assert(th);
94   assert(th->refCount);
95   return th->location;
96 }
97 
98 
99 
Typemaker2_Inline_SetLocation(TYPEMAKER2_INLINE * th,int i)100 void Typemaker2_Inline_SetLocation(TYPEMAKER2_INLINE *th, int i)
101 {
102   assert(th);
103   assert(th->refCount);
104   th->location=i;
105 }
106 
107 
108 
Typemaker2_Inline_GetAccess(const TYPEMAKER2_INLINE * th)109 int Typemaker2_Inline_GetAccess(const TYPEMAKER2_INLINE *th)
110 {
111   assert(th);
112   assert(th->refCount);
113   return th->acc;
114 }
115 
116 
117 
Typemaker2_Inline_SetAccess(TYPEMAKER2_INLINE * th,int i)118 void Typemaker2_Inline_SetAccess(TYPEMAKER2_INLINE *th, int i)
119 {
120   assert(th);
121   assert(th->refCount);
122   th->acc=i;
123 }
124 
125 
126 
Typemaker2_Inline_GetTypeFlagsMask(const TYPEMAKER2_INLINE * th)127 int Typemaker2_Inline_GetTypeFlagsMask(const TYPEMAKER2_INLINE *th)
128 {
129   assert(th);
130   assert(th->refCount);
131   return th->typeFlagsMask;
132 }
133 
134 
135 
Typemaker2_Inline_GetTypeFlagsValue(const TYPEMAKER2_INLINE * th)136 int Typemaker2_Inline_GetTypeFlagsValue(const TYPEMAKER2_INLINE *th)
137 {
138   assert(th);
139   assert(th->refCount);
140   return th->typeFlagsValue;
141 }
142 
143 
144 
Typemaker2_Inline_fromXml(GWEN_XMLNODE * node)145 TYPEMAKER2_INLINE *Typemaker2_Inline_fromXml(GWEN_XMLNODE *node)
146 {
147   TYPEMAKER2_INLINE *th;
148   const char *s;
149 
150   th=Typemaker2_Inline_new();
151 
152   s=GWEN_XMLNode_GetCharValue(node, "content", NULL);
153   Typemaker2_Inline_SetContent(th, s);
154 
155   s=GWEN_XMLNode_GetCharValue(node, "typeFlagsMask", NULL);
156   if (s && *s)
157     th->typeFlagsMask=Typemaker2_TypeFlagsFromString(s);
158 
159   s=GWEN_XMLNode_GetCharValue(node, "typeFlagsValue", NULL);
160   if (s && *s)
161     th->typeFlagsValue=Typemaker2_TypeFlagsFromString(s);
162 
163   /* read header location */
164   s=GWEN_XMLNode_GetProperty(node, "loc", "post");
165   if (strcasecmp(s, "header")==0)
166     Typemaker2_Inline_SetLocation(th, Typemaker2_InlineLocation_Header);
167   else if (strcasecmp(s, "code")==0)
168     Typemaker2_Inline_SetLocation(th, Typemaker2_InlineLocation_Code);
169 
170   /* read access */
171   s=GWEN_XMLNode_GetProperty(node, "access", "public");
172   Typemaker2_Inline_SetAccess(th, Typemaker2_AccessFromString(s));
173 
174   return th;
175 }
176 
177 
178 
179 
180 
181 
182 
183