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
fe4fcdcf
Commit
fe4fcdcf
authored
May 26, 2016
by
Lasse Karstensen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be more pythonistic.
Use the built-in way of describing functions.
parent
8a20a9f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
generate.py
lib/libvcc/generate.py
+12
-12
No files found.
lib/libvcc/generate.py
View file @
fe4fcdcf
...
...
@@ -774,22 +774,21 @@ fi.close()
# Nothing is easily configurable below this line.
#######################################################################
#######################################################################
# Emit a function to recognize tokens in a string
#######################################################################
def
emit_vcl_fixed_token
(
fo
,
tokens
):
"Emit a function to recognize tokens in a string"
recog
=
list
()
emit
=
dict
()
for
i
in
tokens
:
j
=
tokens
[
i
]
if
(
j
!=
None
)
:
if
j
is
not
None
:
recog
.
append
(
j
)
emit
[
j
]
=
i
recog
.
sort
()
rrecog
=
copy
.
copy
(
recog
)
rrecog
.
sort
(
key
=
lambda
x
:
-
len
(
x
))
rrecog
.
sort
(
key
=
lambda
x
:
-
len
(
x
))
fo
.
write
(
"""
#define M1()
\t
do {*q = p + 1; return (p[0]); } while (0)
...
...
@@ -837,26 +836,26 @@ vcl_fixed_token(const char *p, const char **q)
fo
.
write
(
"
\t\t
return (0);
\n
"
)
fo
.
write
(
"
\t
default:
\n\t\t
return (0);
\n\t
}
\n
}
\n
"
)
#######################################################################
# Emit the vcl_tnames (token->string) conversion array
#######################################################################
def
emit_vcl_tnames
(
fo
,
tokens
):
"Emit the vcl_tnames (token->string) conversion array"
fo
.
write
(
"
\n
const char * const vcl_tnames[256] = {
\n
"
)
l
=
list
(
tokens
.
keys
())
l
.
sort
()
for
i
in
l
:
j
=
tokens
[
i
]
if
j
==
None
:
if
j
is
None
:
j
=
i
if
i
[
0
]
==
"'"
:
j
=
i
fo
.
write
(
"
\t
[
%
s] =
\"
%
s
\"
,
\n
"
%
(
i
,
j
))
fo
.
write
(
"};
\n
"
)
#######################################################################
# Read a C-source file and spit out code that outputs it with VSB_cat()
#######################################################################
def
emit_file
(
fo
,
fd
,
bn
):
"Read a C-source file and spit out code that outputs it with VSB_cat()"
fn
=
join
(
fd
,
bn
)
fi
=
open
(
fn
)
...
...
@@ -916,13 +915,14 @@ def emit_file(fo, fd, bn):
def
polish_tokens
(
tokens
):
# Expand single char tokens
"Expand single char tokens"
st
=
tokens
[
None
]
del
tokens
[
None
]
for
i
in
st
:
tokens
[
"'"
+
i
+
"'"
]
=
i
#######################################################################
#######################################################################
def
file_header
(
fo
):
fo
.
write
(
"""/*
* NB: This file is machine generated, DO NOT EDIT!
...
...
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