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_header_p.h"
16
17
18 #include <gwenhywfar/debug.h>
19 #include <gwenhywfar/misc.h>
20
21 #include <assert.h>
22
23
24
GWEN_LIST_FUNCTIONS(TYPEMAKER2_HEADER,Typemaker2_Header)25 GWEN_LIST_FUNCTIONS(TYPEMAKER2_HEADER, Typemaker2_Header)
26
27
28
29 TYPEMAKER2_HEADER *Typemaker2_Header_new()
30 {
31 TYPEMAKER2_HEADER *th;
32
33 GWEN_NEW_OBJECT(TYPEMAKER2_HEADER, th);
34 th->refCount=1;
35 GWEN_LIST_INIT(TYPEMAKER2_HEADER, th);
36
37 return th;
38 }
39
40
41
Typemaker2_Header_free(TYPEMAKER2_HEADER * th)42 void Typemaker2_Header_free(TYPEMAKER2_HEADER *th)
43 {
44 if (th) {
45 assert(th->refCount);
46 if (th->refCount==1) {
47 GWEN_LIST_FINI(TYPEMAKER2_HEADER, th);
48 free(th->fileName);
49 th->refCount=0;
50 GWEN_FREE_OBJECT(th);
51 }
52 else
53 th->refCount++;
54 }
55 }
56
57
58
Typemaker2_Header_Attach(TYPEMAKER2_HEADER * th)59 void Typemaker2_Header_Attach(TYPEMAKER2_HEADER *th)
60 {
61 assert(th);
62 assert(th->refCount);
63 th->refCount++;
64 }
65
66
67
Typemaker2_Header_GetFileName(const TYPEMAKER2_HEADER * th)68 const char *Typemaker2_Header_GetFileName(const TYPEMAKER2_HEADER *th)
69 {
70 assert(th);
71 assert(th->refCount);
72 return th->fileName;
73 }
74
75
76
Typemaker2_Header_SetFileName(TYPEMAKER2_HEADER * th,const char * s)77 void Typemaker2_Header_SetFileName(TYPEMAKER2_HEADER *th, const char *s)
78 {
79 assert(th);
80 assert(th->refCount);
81 free(th->fileName);
82 if (s)
83 th->fileName=strdup(s);
84 else
85 th->fileName=NULL;
86 }
87
88
89
Typemaker2_Header_GetType(const TYPEMAKER2_HEADER * th)90 int Typemaker2_Header_GetType(const TYPEMAKER2_HEADER *th)
91 {
92 assert(th);
93 assert(th->refCount);
94 return th->type;
95 }
96
97
98
Typemaker2_Header_SetType(TYPEMAKER2_HEADER * th,int i)99 void Typemaker2_Header_SetType(TYPEMAKER2_HEADER *th, int i)
100 {
101 assert(th);
102 assert(th->refCount);
103 th->type=i;
104 }
105
106
107
Typemaker2_Header_GetLocation(const TYPEMAKER2_HEADER * th)108 int Typemaker2_Header_GetLocation(const TYPEMAKER2_HEADER *th)
109 {
110 assert(th);
111 assert(th->refCount);
112 return th->location;
113 }
114
115
116
Typemaker2_Header_SetLocation(TYPEMAKER2_HEADER * th,int i)117 void Typemaker2_Header_SetLocation(TYPEMAKER2_HEADER *th, int i)
118 {
119 assert(th);
120 assert(th->refCount);
121 th->location=i;
122 }
123
124
125
Typemaker2_Header_readXml(TYPEMAKER2_HEADER * th,GWEN_XMLNODE * node)126 int Typemaker2_Header_readXml(TYPEMAKER2_HEADER *th, GWEN_XMLNODE *node)
127 {
128 const char *s;
129 GWEN_XMLNODE *n;
130
131 assert(th);
132 assert(th->refCount);
133
134 n=GWEN_XMLNode_GetFirstData(node);
135 if (n) {
136 s=GWEN_XMLNode_GetData(n);
137 Typemaker2_Header_SetFileName(th, s);
138 }
139
140 /* read header type */
141 s=GWEN_XMLNode_GetProperty(node, "type", "sys");
142 if (strcasecmp(s, "sys")==0 ||
143 strcasecmp(s, "system")==0)
144 Typemaker2_Header_SetType(th, Typemaker2_HeaderType_System);
145 else if (strcasecmp(s, "local")==0)
146 Typemaker2_Header_SetType(th, Typemaker2_HeaderType_Local);
147
148 /* read header location */
149 s=GWEN_XMLNode_GetProperty(node, "loc", "post");
150 if (strcasecmp(s, "pre")==0)
151 Typemaker2_Header_SetLocation(th, Typemaker2_HeaderLocation_Pre);
152 else if (strcasecmp(s, "post")==0)
153 Typemaker2_Header_SetLocation(th, Typemaker2_HeaderLocation_Post);
154 else if (strcasecmp(s, "code")==0)
155 Typemaker2_Header_SetLocation(th, Typemaker2_HeaderLocation_Code);
156 else if (strcasecmp(s, "codeEnd")==0)
157 Typemaker2_Header_SetLocation(th, Typemaker2_HeaderLocation_CodeEnd);
158 else if (strcasecmp(s, "headerEnd")==0)
159 Typemaker2_Header_SetLocation(th, Typemaker2_HeaderLocation_HeaderEnd);
160
161 return 0;
162 }
163
164
165
166
167
168
169
170