girtobac  0.4
Create FB Headers from GObject Introspection *.gir files
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
girtobac_RepData.bas
Go to the documentation of this file.
1 
9 
10 
11 
25 TYPE RepData
26  AS CONST gchar PTR Na
27  AS STRING _
28  Er, _
29  Su = MKL(0) & CHR(1)
30  DECLARE CONSTRUCTOR(BYVAL T AS CONST gchar PTR)
31  DECLARE FUNCTION Az() AS LONG
32  DECLARE SUB add(BYVAL AS CONST ZSTRING PTR, BYVAL AS CONST ZSTRING PTR)
33  DECLARE FUNCTION rep(BYVAL T AS CONST gchar PTR) AS CONST ZSTRING PTR
34  DECLARE SUB list(BYREF Li AS STRING)
35 END TYPE
36 
37 
38 CONSTRUCTOR RepData(BYVAL T AS CONST gchar PTR)
39  Na = T
40 END CONSTRUCTOR
41 
42 
50 FUNCTION RepData.Az() AS LONG : RETURN *CAST(INTEGER PTR, SADD(Su))
51 END FUNCTION
52 
53 
54 
61 SUB RepData.list(BYREF Li AS STRING)
62  VAR r = "", a = 6, e = INSTR(a, Su, CHR(2)), t = ""
63  WHILE e > a
64  VAR l = e - a : e += 1
65  VAR x = INSTR(e, Su, CHR(1)), z = SADD(Er) + VALINT("&h" & MID(Su, e, x - e))
66  VAR n = *CAST(LONG PTR, z - 4)
67  IF 0 = n THEN Li &= NL !"\t" & MID(Su, a, l) & " <" & *Na & ">"
68  a = x + 1 : e = INSTR(a, Su, CHR(2))
69  WEND
70 END SUB
71 
72 
73 
86 SUB RepData.add(BYVAL S AS CONST ZSTRING PTR, BYVAL E AS CONST ZSTRING PTR)
87  IF *S = "" THEN ?"Empty <" & *Na & "> search attribute!" : EXIT SUB
88  IF INSTR(*S, ANY !"\000\001\002") THEN ?"Undefined char in <" & *Na & ">: " & *S : EXIT SUB
89  VAR c = CHR(1) & *S & CHR(2) : IF INSTR(5, Su, c) THEN ?"Duplicated <" & *Na & ">: " & *S : EXIT SUB
90  *CAST(LONG PTR, SADD(Su)) += 1 : Su &= MID(c, 2) & HEX(LEN(Er) + 4) & CHR(1)
91  Er &= MKL(0) & *E & CHR(0)
92 END SUB
93 
94 
95 
106 FUNCTION RepData.rep(BYVAL T AS CONST gchar PTR) AS CONST ZSTRING PTR
107  IF 0 = T THEN RETURN @"/'unknown'/"
108  VAR a = INSTR(Su, CHR(1) & *T & CHR(2)) : IF a THEN a += LEN(*T) + 2 ELSE RETURN T
109  VAR e = INSTR(a, Su, CHR(1)) + 1
110  DIM AS ZSTRING PTR z = SADD(Er) + VALINT("&h" & MID(Su, a, e - a))
111  *CAST(LONG PTR, z - 4) += 1 : RETURN z
112 END FUNCTION
113 
114 
121 TYPE Stack
122  AS STRING Dat = ";"
123  AS INTEGER A = 1
124  DECLARE SUB add(BYVAL AS CONST gchar PTR)
125  DECLARE FUNCTION nxt() AS STRING
126  DECLARE FUNCTION find(BYVAL T AS CONST gchar PTR) AS INTEGER
127 END TYPE
128 
129 
130 
139 SUB Stack.add(BYVAL S AS CONST gchar PTR)
140  IF 0 = find(S) THEN Dat &= *S & ";" : EXIT SUB
141  ?"Duplicated <first>: " & *S
142 END SUB
143 
144 
145 
154 FUNCTION Stack.nxt() AS STRING
155  VAR x = A : A = INSTR(A + 1, Dat, ";") : IF 0 = A THEN RETURN ""
156  x += 1 : RETURN MID(Dat, x, A - x)
157 END FUNCTION
158 
159 
160 
168 FUNCTION Stack.find(BYVAL T AS CONST gchar PTR) AS INTEGER
169  RETURN INSTR(Dat, ";" & *T & ";")
170 END FUNCTION
171 
172 
173 DIM SHARED AS RepData _
174  FB_TYP = @"type", _
175  FB_NAM = @"name"
176 DIM SHARED AS Stack _
177  FIRST
178 
179 
180 
181 '& SUB_CDECL g2b_parser(){
182 G2b_parser:
183 _START_PARSER(G2b)
184 
185  SELECT CASE *element_name
186  CASE "first"
187  VAR n = find_value("search", AttNams, AttVals) ' *< local variable
188  IF 0 = n THEN EXIT SELECT
189  FIRST.add(n) '& RepData.add();
190  CASE "type"
191  VAR s = find_value("search", AttNams, AttVals) ' *< local variable
192  IF 0 = s THEN EXIT SELECT
193  VAR r = find_value("replace", AttNams, AttVals) ' *< local variable
194  VAR a = find_value("add", AttNams, AttVals) ' *< local variable
195  IF r THEN FB_TYP.add(s, r) : EXIT SELECT '& RepData.add();
196 
197  VAR e = *s & *a ' *< local variable
198  FB_TYP.add(s, e) '& RepData.add();
199  CASE "name"
200  VAR s = find_value("search", AttNams, AttVals) ' *< local variable
201  IF 0 = s THEN EXIT SELECT
202  VAR r = find_value("replace", AttNams, AttVals) ' *< local variable
203  VAR a = find_value("add", AttNams, AttVals) ' *< local variable
204  IF r THEN FB_NAM.add(s, r) : EXIT SELECT '& RepData.add();
205 
206  VAR e = *s & *a ' *< local variable
207  FB_NAM.add(s, SADD(e)) '& RepData.add();
208  CASE "binary"
209  VAR n = find_value("name", AttNams, AttVals) ' *< local variable
210  IF 0 = n THEN EXIT SELECT
211  .NamDll = *n
212  CASE "check"
213  VAR n = find_value("name", AttNams, AttVals) ' *< local variable
214  IF 0 = n THEN EXIT SELECT
215  .Check = *n
216  CASE "pack"
217  VAR n = find_value("name", AttNams, AttVals) ' *< local variable
218  IF 0 = n THEN EXIT SELECT
219  .NamSpace = *n
220 
221 _END_PARSER(G2b)
222 
223  SELECT CASE *element_name
224  CASE "type", "name", "first", "binary", "check", "pack"
225 
226 _NEW_PARSER(G2b)
227 '& };
228