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
fb067772
Commit
fb067772
authored
Jul 31, 2015
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implementation of VSB auto-indent facility
parent
ccf1c0d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
1 deletion
+34
-1
vsb.c
lib/libvarnish/vsb.c
+34
-1
No files found.
lib/libvarnish/vsb.c
View file @
fb067772
...
...
@@ -114,7 +114,6 @@ CTASSERT(powerof2(VSB_MAXEXTENDSIZE));
CTASSERT
(
powerof2
(
VSB_MAXEXTENDINCR
));
#endif
static
int
VSB_extendsize
(
int
size
)
{
...
...
@@ -156,6 +155,21 @@ VSB_extend(struct vsb *s, int addlen)
return
(
0
);
}
static
void
_vsb_indent
(
struct
vsb
*
s
)
{
if
(
s
->
s_indent
==
0
||
s
->
s_error
!=
0
||
s
->
s_buf
[
s
->
s_len
-
1
]
!=
'\n'
)
return
;
if
(
VSB_FREESPACE
(
s
)
<=
s
->
s_indent
&&
VSB_extend
(
s
,
s
->
s_indent
)
<
0
)
{
s
->
s_error
=
ENOMEM
;
return
;
}
memset
(
s
->
s_buf
+
s
->
s_len
,
' '
,
s
->
s_indent
);
s
->
s_len
+=
s
->
s_indent
;
}
/*
* Initialize the internals of an vsb.
* If buf is non-NULL, it points to a static or already-allocated string
...
...
@@ -231,6 +245,7 @@ VSB_clear(struct vsb *s)
VSB_CLEARFLAG
(
s
,
VSB_FINISHED
);
s
->
s_error
=
0
;
s
->
s_len
=
0
;
s
->
s_indent
=
0
;
}
/*
...
...
@@ -247,6 +262,7 @@ VSB_put_byte(struct vsb *s, int c)
if
(
s
->
s_error
!=
0
)
return
;
_vsb_indent
(
s
);
if
(
VSB_FREESPACE
(
s
)
<=
0
)
{
if
(
VSB_extend
(
s
,
1
)
<
0
)
s
->
s_error
=
ENOMEM
;
...
...
@@ -270,6 +286,7 @@ VSB_bcat(struct vsb *s, const void *buf, size_t len)
if
(
s
->
s_error
!=
0
)
return
(
-
1
);
_vsb_indent
(
s
);
for
(;
str
<
end
;
str
++
)
{
VSB_put_byte
(
s
,
*
str
);
if
(
s
->
s_error
!=
0
)
...
...
@@ -316,6 +333,7 @@ VSB_vprintf(struct vsb *s, const char *fmt, va_list ap)
if
(
s
->
s_error
!=
0
)
return
(
-
1
);
_vsb_indent
(
s
);
/*
* For the moment, there is no way to get vsnprintf(3) to hand
...
...
@@ -515,3 +533,18 @@ VSB_quote(struct vsb *s, const char *p, int len, int how)
}
(
void
)
VSB_putc
(
s
,
'"'
);
}
/*
* Indentation
*/
void
VSB_indent
(
struct
vsb
*
s
,
int
i
)
{
assert_VSB_integrity
(
s
);
if
(
s
->
s_indent
+
i
<
0
)
s
->
s_error
=
EINVAL
;
else
s
->
s_indent
+=
i
;
}
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