1 # ex:ts=4:sw=4:sts=4:et
2 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4 cdef extern from "stdio.h":
6 FILE *fopen(char*, char*)
9 cdef extern from "string.h":
12 cdef extern from "lexerc.h":
13 ctypedef struct lex_t:
24 cdef extern int parse(FILE*, char*, object, int)
26 def parsefile(object file, object data, object config):
27 #print "parsefile: 1", file, data
33 #print "parsefile: 2 opening file"
35 raise IOError("No such file %s." % file)
37 #print "parsefile: 3 parse"
38 parse(f, file, data, config)
44 cdef public void e_assign(lex_t* container, char* key, char* what):
45 #print "e_assign", key, what
47 print "FUTURE Warning empty string: use \"\""
50 d = <object>container.data
53 cdef public void e_export(lex_t* c, char* what):
54 #print "e_export", what
56 # bb.data.setVarFlag(key, "export", 1, data)
58 d.setVarFlag(what, "export", 1)
60 cdef public void e_immediate(lex_t* c, char* key, char* what):
61 #print "e_immediate", key, what
63 # val = bb.data.expand(groupd["value"], data)
65 d.setVar(key, d.expand(what,d))
67 cdef public void e_cond(lex_t* c, char* key, char* what):
68 #print "e_cond", key, what
70 # val = bb.data.getVar(key, data)
72 # val = groupd["value"]
74 print "FUTURE warning: Use \"\" for", key
78 d.setVar(key, (d.getVar(key,False) or what))
80 cdef public void e_prepend(lex_t* c, char* key, char* what):
81 #print "e_prepend", key, what
83 # val = "%s %s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
85 d.setVar(key, what + " " + (d.getVar(key,0) or ""))
87 cdef public void e_append(lex_t* c, char* key, char* what):
88 #print "e_append", key, what
90 # val = "%s %s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
92 d.setVar(key, (d.getVar(key,0) or "") + " " + what)
94 cdef public void e_precat(lex_t* c, char* key, char* what):
95 #print "e_precat", key, what
97 # val = "%s%s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
99 d.setVar(key, what + (d.getVar(key,0) or ""))
101 cdef public void e_postcat(lex_t* c, char* key, char* what):
102 #print "e_postcat", key, what
104 # val = "%s%s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
106 d.setVar(key, (d.getVar(key,0) or "") + what)
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")
117 # data.setVarFlag(var, "task", 1, d)
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)
128 from bb.parse import ParseError
129 raise ParseError("No tasks allowed in config files")
134 d.setVarFlag(do, "task", 1)
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())
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)
149 from bb.parse import ParseError
150 raise ParseError("No handlers allowed in config files")
154 d.setVarFlag(h, "handler", 1)
157 cdef public int e_export_func(lex_t* c, char* function) except -1:
158 #print "e_export_func", function
160 from bb.parse import ParseError
161 raise ParseError("No functions allowed in config files")
166 cdef public int e_inherit(lex_t* c, char* file) except -1:
167 #print "e_inherit", file
170 from bb.parse import ParseError
171 raise ParseError("No inherits allowed in config files")
176 cdef public void e_include(lex_t* c, char* file):
177 from bb.parse import handle
181 handle(d.expand(file,d), d, True)
183 print "Could not include file", file
186 cdef public int e_require(lex_t* c, char* file) except -1:
187 #print "e_require", file
188 from bb.parse import handle
192 handle(d.expand(file,d), d, True)
194 print "ParseError", file
195 from bb.parse import ParseError
196 raise ParseError("Could not include required file %s" % file)
201 cdef public int e_proc(lex_t* c, char* key, char* what) except -1:
202 #print "e_proc", key, what
204 from bb.parse import ParseError
205 raise ParseError("No inherits allowed in config files")
210 cdef public int e_proc_python(lex_t* c, char* key, char* what) except -1:
211 #print "e_proc_python"
213 from bb.parse import ParseError
214 raise ParseError("No pythin allowed in config files")
226 cdef public int e_proc_fakeroot(lex_t* c, char* key, char* what) except -1:
227 #print "e_fakeroot", key, what
230 from bb.parse import ParseError
231 raise ParseError("No fakeroot allowed in config files")
236 cdef public int e_def(lex_t* c, char* a, char* b, char* d) except -1:
237 #print "e_def", a, b, d
240 from bb.parse import ParseError
241 raise ParseError("No defs allowed in config files")
246 cdef public int e_parse_error(lex_t* c) except -1:
247 print "e_parse_error", c.name, "line:", lineError, "parse:", errorParse
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) )