summaryrefslogtreecommitdiffabout
path: root/html.c
authorMark Lodato <lodatom@gmail.com>2010-02-09 04:04:41 (UTC)
committer Mark Lodato <lodatom@gmail.com>2010-02-09 04:04:41 (UTC)
commit8aab27f24de70acfbdcee31c634a4b1facf23b92 (patch) (side-by-side diff)
tree10e5f83a5f0c2a286ec2d1feecf6732f863c9a47 /html.c
parent547a64fbd65de293c290f4e18bbeae958d54aaa7 (diff)
downloadcgit-8aab27f24de70acfbdcee31c634a4b1facf23b92.zip
cgit-8aab27f24de70acfbdcee31c634a4b1facf23b92.tar.gz
cgit-8aab27f24de70acfbdcee31c634a4b1facf23b92.tar.bz2
html: make all strings 'const char *'
None of the html_* functions modify their argument, so they can all be 'const char *' instead of a simple 'char *'. This removes the need to cast (or copy) when trying to print a const string. Signed-off-by: Mark Lodato <lodatom@gmail.com>
Diffstat (limited to 'html.c') (more/less context) (ignore whitespace changes)
-rw-r--r--html.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/html.c b/html.c
index 66ba65d..4033200 100644
--- a/html.c
+++ b/html.c
@@ -54,145 +54,145 @@ void htmlf(const char *format, ...)
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
html(buf);
}
void html_status(int code, const char *msg, int more_headers)
{
htmlf("Status: %d %s\n", code, msg);
if (!more_headers)
html("\n");
}
-void html_txt(char *txt)
+void html_txt(const char *txt)
{
- char *t = txt;
+ const char *t = txt;
while(t && *t){
int c = *t;
if (c=='<' || c=='>' || c=='&') {
write(htmlfd, txt, t - txt);
if (c=='>')
html("&gt;");
else if (c=='<')
html("&lt;");
else if (c=='&')
html("&amp;");
txt = t+1;
}
t++;
}
if (t!=txt)
html(txt);
}
-void html_ntxt(int len, char *txt)
+void html_ntxt(int len, const char *txt)
{
- char *t = txt;
+ const char *t = txt;
while(t && *t && len--){
int c = *t;
if (c=='<' || c=='>' || c=='&') {
write(htmlfd, txt, t - txt);
if (c=='>')
html("&gt;");
else if (c=='<')
html("&lt;");
else if (c=='&')
html("&amp;");
txt = t+1;
}
t++;
}
if (t!=txt)
write(htmlfd, txt, t - txt);
if (len<0)
html("...");
}
-void html_attr(char *txt)
+void html_attr(const char *txt)
{
- char *t = txt;
+ const char *t = txt;
while(t && *t){
int c = *t;
if (c=='<' || c=='>' || c=='\'' || c=='\"') {
write(htmlfd, txt, t - txt);
if (c=='>')
html("&gt;");
else if (c=='<')
html("&lt;");
else if (c=='\'')
html("&#x27;");
else if (c=='"')
html("&quot;");
txt = t+1;
}
t++;
}
if (t!=txt)
html(txt);
}
-void html_url_path(char *txt)
+void html_url_path(const char *txt)
{
- char *t = txt;
+ const char *t = txt;
while(t && *t){
int c = *t;
if (c=='"' || c=='#' || c=='\'' || c=='?') {
write(htmlfd, txt, t - txt);
write(htmlfd, fmt("%%%2x", c), 3);
txt = t+1;
}
t++;
}
if (t!=txt)
html(txt);
}
-void html_url_arg(char *txt)
+void html_url_arg(const char *txt)
{
- char *t = txt;
+ const char *t = txt;
while(t && *t){
int c = *t;
if (c=='"' || c=='#' || c=='%' || c=='&' || c=='\'' || c=='+' || c=='?') {
write(htmlfd, txt, t - txt);
write(htmlfd, fmt("%%%2x", c), 3);
txt = t+1;
}
t++;
}
if (t!=txt)
html(txt);
}
-void html_hidden(char *name, char *value)
+void html_hidden(const char *name, const char *value)
{
html("<input type='hidden' name='");
html_attr(name);
html("' value='");
html_attr(value);
html("'/>");
}
-void html_option(char *value, char *text, char *selected_value)
+void html_option(const char *value, const char *text, const char *selected_value)
{
html("<option value='");
html_attr(value);
html("'");
if (selected_value && !strcmp(selected_value, value))
html(" selected='selected'");
html(">");
html_txt(text);
html("</option>\n");
}
-void html_link_open(char *url, char *title, char *class)
+void html_link_open(const char *url, const char *title, const char *class)
{
html("<a href='");
html_attr(url);
if (title) {
html("' title='");
html_attr(title);
}
if (class) {
html("' class='");
html_attr(class);
}
html("'>");
@@ -248,32 +248,32 @@ char *convert_query_hexchar(char *txt)
d1 = hextoint(*(txt+1));
d2 = hextoint(*(txt+2));
if (d1<0 || d2<0) {
strcpy(txt, txt+3);
return txt-1;
} else {
*txt = d1 * 16 + d2;
strcpy(txt+1, txt+3);
return txt;
}
}
-int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value))
+int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value))
{
- char *t, *value = NULL, c;
+ char *t, *txt, *value = NULL, c;
- if (!txt)
+ if (!txt_)
return 0;
- t = txt = strdup(txt);
+ t = txt = strdup(txt_);
if (t == NULL) {
printf("Out of memory\n");
exit(1);
}
while((c=*t) != '\0') {
if (c=='=') {
*t = '\0';
value = t+1;
} else if (c=='+') {
*t = ' ';
} else if (c=='%') {
t = convert_query_hexchar(t);