Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
34b365c5
Commit
34b365c5
authored
Jan 31, 2011
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wash and improve the .vcc file parser a little bit
parent
5da592f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
21 deletions
+60
-21
vmod.py
lib/libvmod_std/vmod.py
+60
-21
No files found.
lib/libvmod_std/vmod.py
View file @
34b365c5
...
...
@@ -40,14 +40,13 @@
# $Id$
import
sys
import
re
if
len
(
sys
.
argv
)
==
2
:
specfile
=
sys
.
argv
[
1
]
else
:
specfile
=
"vmod.vcc"
type_tab
=
dict
()
ctypes
=
{
'IP'
:
"struct sockaddr_storage *"
,
'STRING'
:
"const char *"
,
...
...
@@ -114,49 +113,89 @@ def partition(string, separator):
return
(
string
[:
i
],
separator
,
string
[
i
+
len
(
separator
):])
return
(
string
,
''
,
''
)
#######################################################################
f
=
open
(
specfile
,
"r"
)
for
l0
in
f
:
# print("# " + l0)
l0
=
l0
.
strip
()
def
nextline
():
while
True
:
l0
=
f
.
readline
()
if
l0
==
""
:
return
l0
l0
=
re
.
sub
(
"#.*$"
,
""
,
l0
)
l0
=
re
.
sub
(
"
\
s
\
s*"
,
" "
,
l0
.
strip
())
if
l0
!=
""
:
return
l0
def
is_c_name
(
s
):
return
None
!=
re
.
match
(
"^[a-z][a-z0-9_]*$"
,
s
)
while
True
:
l0
=
nextline
()
if
l0
==
""
:
continue
i
=
l0
.
find
(
"#"
)
if
i
==
0
:
continue
if
i
>=
0
:
line
=
l0
[:
i
-
1
]
else
:
line
=
l0
line
=
line
.
expandtabs
()
.
strip
()
l
=
partition
(
line
,
" "
)
break
;
l
=
partition
(
l0
,
" "
)
if
l
[
0
]
==
"Module"
:
modname
=
l
[
2
]
.
strip
();
if
not
is_c_name
(
modname
):
raise
Exception
(
"Module name '
%
s' is illegal"
%
modname
)
continue
if
l
[
0
]
==
"Init"
:
initname
=
l
[
2
]
.
strip
();
if
not
is_c_name
(
initname
):
raise
Exception
(
"Init name '
%
s' is illegal"
%
initname
)
continue
if
l
[
0
]
!=
"Function"
:
assert
False
raise
Exception
(
"Expected 'Function' line, got '
%
s'"
%
l
[
0
])
# Find the return type of the function
l
=
partition
(
l
[
2
]
.
strip
(),
" "
)
rt_type
=
l
[
0
]
if
rt_type
not
in
ctypes
:
raise
Exception
(
"Return type '
%
s' not a valid type"
%
rt_type
)
# Find the function name
l
=
partition
(
l
[
2
]
.
strip
(),
"("
)
fname
=
l
[
0
]
.
strip
()
if
not
is_c_name
(
fname
):
raise
Exception
(
"Function name '
%
s' is illegal"
%
fname
)
if
l
[
1
]
!=
'('
:
raise
Exception
(
"Missing '('"
)
l
=
l
[
2
]
while
-
1
==
l
.
find
(
")"
):
l1
=
nextline
()
if
l1
==
""
:
raise
Exception
(
"End Of Input looking for ')'"
)
l
=
l
+
l1
if
-
1
!=
l
.
find
(
"("
):
raise
Exception
(
"Nesting trouble with '(...)' "
)
if
l
[
-
1
:]
!=
')'
:
raise
Exception
(
"Junk after ')'"
)
l
=
l
[:
-
1
]
args
=
list
()
while
True
:
l
=
partition
(
l
[
2
]
.
strip
(),
","
)
if
len
(
l
[
2
])
==
0
:
l
=
partition
(
l
,
","
)
t
=
l
[
0
]
.
strip
()
if
t
not
in
ctypes
:
raise
Exception
(
"Argument type '
%
s' not a valid type"
%
t
)
args
.
append
(
t
)
l
=
l
[
2
]
if
l
==
""
:
break
args
.
append
(
l
[
0
])
l
=
partition
(
l
[
0
]
.
strip
(),
")"
)
args
.
append
(
l
[
0
])
do_func
(
fname
,
rt_type
,
args
)
#######################################################################
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment