build.py: revert setting LC_ALL=C due to IRC discussion
[vuplus_bitbake] / lib / bb / parse / parse_c / bitbakec.pyx
1 # ex:ts=4:sw=4:sts=4:et
2 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3
4 cdef extern from "stdio.h":
5     ctypedef int FILE
6     FILE *fopen(char*, char*)
7     int fclose(FILE *fp)
8
9 cdef extern from "string.h":
10     int strlen(char*)
11
12 cdef extern from "lexerc.h":
13     ctypedef struct lex_t:
14         void* parser
15         void* scanner
16         char* name
17         FILE* file
18         int config
19         void* data
20
21     int lineError
22     int errorParse
23
24     cdef extern int parse(FILE*, char*, object, int)
25
26 def parsefile(object file, object data, object config):
27     #print "parsefile: 1", file, data
28
29     # Open the file
30     cdef FILE* f
31
32     f = fopen(file, "r")
33     #print "parsefile: 2 opening file"
34     if (f == NULL):
35         raise IOError("No such file %s." % file)
36
37     #print "parsefile: 3 parse"
38     parse(f, file, data, config)
39
40     # Close the file
41     fclose(f)
42
43
44 cdef public void e_assign(lex_t* container, char* key, char* what):
45     #print "e_assign", key, what
46     if what == NULL:
47         print "FUTURE Warning empty string: use \"\""
48         what = ""
49
50     d = <object>container.data
51     d.setVar(key, what)
52
53 cdef public void e_export(lex_t* c, char* what):
54     #print "e_export", what
55     #exp:
56     # bb.data.setVarFlag(key, "export", 1, data)
57     d = <object>c.data
58     d.setVarFlag(what, "export", 1)
59
60 cdef public void e_immediate(lex_t* c, char* key, char* what):
61     #print "e_immediate", key, what
62     #colon:
63     # val = bb.data.expand(groupd["value"], data)
64     d = <object>c.data
65     d.setVar(key, d.expand(what,d))
66
67 cdef public void e_cond(lex_t* c, char* key, char* what):
68     #print "e_cond", key, what
69     #ques:
70     # val = bb.data.getVar(key, data)
71     # if val == None:    
72     #    val = groupd["value"]
73     if what == NULL:
74         print "FUTURE warning: Use \"\" for", key
75         what = ""
76
77     d = <object>c.data
78     d.setVar(key, (d.getVar(key,False) or what))
79
80 cdef public void e_prepend(lex_t* c, char* key, char* what):
81     #print "e_prepend", key, what
82     #prepend:
83     # val = "%s %s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
84     d = <object>c.data
85     d.setVar(key, what + " " + (d.getVar(key,0) or ""))
86
87 cdef public void e_append(lex_t* c, char* key, char* what):
88     #print "e_append", key, what
89     #append:
90     # val = "%s %s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
91     d = <object>c.data
92     d.setVar(key, (d.getVar(key,0) or "") + " " + what)
93
94 cdef public void e_precat(lex_t* c, char* key, char* what):
95     #print "e_precat", key, what
96     #predot:
97     # val = "%s%s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
98     d = <object>c.data
99     d.setVar(key, what + (d.getVar(key,0) or ""))
100
101 cdef public void e_postcat(lex_t* c, char* key, char* what):
102     #print "e_postcat", key, what
103     #postdot:
104     # val = "%s%s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
105     d = <object>c.data
106     d.setVar(key, (d.getVar(key,0) or "") + what)
107
108 cdef public int e_addtask(lex_t* c, char* name, char* before, char* after) except -1:
109     #print "e_addtask", name
110     # func = m.group("func")
111     # before = m.group("before")
112     # after = m.group("after")
113     # if func is None:
114     #     return
115     # var = "do_" + func
116     #
117     # data.setVarFlag(var, "task", 1, d)
118     #
119     # if after is not None:
120     # #  set up deps for function
121     #     data.setVarFlag(var, "deps", after.split(), d)
122     # if before is not None:
123     # #   set up things that depend on this func
124     #     data.setVarFlag(var, "postdeps", before.split(), d)
125     # return
126
127     if c.config == 1:
128         from bb.parse import ParseError
129         raise ParseError("No tasks allowed in config files")
130         return -1
131
132     d = <object>c.data
133     do = "do_%s" % name
134     d.setVarFlag(do, "task", 1)
135
136     if before != NULL and strlen(before) > 0:
137         #print "Before", before
138         d.setVarFlag(do, "postdeps", ("%s" % before).split())
139     if after  != NULL and strlen(after) > 0:
140         #print "After", after
141         d.setVarFlag(do, "deps", ("%s" % after).split())
142
143     return 0
144
145 cdef public int e_addhandler(lex_t* c, char* h) except -1:
146     #print "e_addhandler", h
147     # data.setVarFlag(h, "handler", 1, d)
148     if c.config == 1:
149         from bb.parse import ParseError
150         raise ParseError("No handlers allowed in config files")
151         return -1
152
153     d = <object>c.data
154     d.setVarFlag(h, "handler", 1)
155     return 0
156
157 cdef public int e_export_func(lex_t* c, char* function) except -1:
158     #print "e_export_func", function
159     if c.config == 1:
160         from bb.parse import ParseError
161         raise ParseError("No functions allowed in config files")
162         return -1
163
164     return 0
165
166 cdef public int e_inherit(lex_t* c, char* file) except -1:
167     #print "e_inherit", file
168
169     if c.config == 1:
170         from bb.parse import ParseError
171         raise ParseError("No inherits allowed in config files")
172         return -1
173
174     return 0
175
176 cdef public void e_include(lex_t* c, char* file):
177     from bb.parse import handle
178     d = <object>c.data
179
180     try:
181         handle(d.expand(file,d), d, True)
182     except IOError:
183         print "Could not include file", file
184
185
186 cdef public int e_require(lex_t* c, char* file) except -1:
187     #print "e_require", file
188     from bb.parse import handle
189     d = <object>c.data
190
191     try:
192         handle(d.expand(file,d), d, True)
193     except IOError:
194         print "ParseError", file
195         from bb.parse import ParseError
196         raise ParseError("Could not include required file %s" % file)
197         return -1
198
199     return 0
200
201 cdef public int e_proc(lex_t* c, char* key, char* what) except -1:
202     #print "e_proc", key, what
203     if c.config == 1:
204         from bb.parse import ParseError
205         raise ParseError("No inherits allowed in config files")
206         return -1
207
208     return 0
209
210 cdef public int e_proc_python(lex_t* c, char* key, char* what) except -1:
211     #print "e_proc_python"
212     if c.config == 1:
213         from bb.parse import ParseError
214         raise ParseError("No pythin allowed in config files")
215         return -1
216
217     if key != NULL:
218         pass
219         #print "Key", key
220     if what != NULL:
221         pass
222         #print "What", what
223
224     return 0
225
226 cdef public int e_proc_fakeroot(lex_t* c, char* key, char* what) except -1:
227     #print "e_fakeroot", key, what
228
229     if c.config == 1:
230         from bb.parse import ParseError
231         raise ParseError("No fakeroot allowed in config files")
232         return -1
233
234     return 0
235
236 cdef public int e_def(lex_t* c, char* a, char* b, char* d) except -1:
237     #print "e_def", a, b, d
238
239     if c.config == 1:
240         from bb.parse import ParseError
241         raise ParseError("No defs allowed in config files")
242         return -1
243
244     return 0
245
246 cdef public int e_parse_error(lex_t* c) except -1:
247     print "e_parse_error", c.name, "line:", lineError, "parse:", errorParse
248
249
250     from bb.parse import ParseError
251     raise ParseError("There was an parse error, sorry unable to give more information at the current time. File: %s Line: %d" % (c.name,lineError) )
252     return -1
253