]> git.cameronkatri.com Git - cgit.git/blobdiff - html.c
Fix html error detected by test-suite
[cgit.git] / html.c
diff --git a/html.c b/html.c
index 8a6965970ae903dd434e490cfabbad27f39f900b..eb163d9d1f3a249feb36ee155ab5a464ef4aa64a 100644 (file)
--- a/html.c
+++ b/html.c
@@ -45,7 +45,7 @@ void htmlf(const char *format, ...)
 void html_txt(char *txt)
 {
        char *t = txt;
-       while(*t){
+       while(t && *t){
                int c = *t;
                if (c=='<' || c=='>' || c=='&') {
                        *t = '\0';
@@ -65,11 +65,39 @@ void html_txt(char *txt)
                html(txt);
 }
 
+void html_ntxt(int len, char *txt)
+{
+       char *t = txt;
+       while(t && *t && len--){
+               int c = *t;
+               if (c=='<' || c=='>' || c=='&') {
+                       *t = '\0';
+                       html(txt);
+                       *t = c;
+                       if (c=='>')
+                               html("&gt;");
+                       else if (c=='<')
+                               html("&lt;");
+                       else if (c=='&')
+                               html("&amp;");
+                       txt = t+1;
+               }
+               t++;
+       }
+       if (t!=txt) {
+               char c = *t;
+               *t = '\0';
+               html(txt);
+               *t = c;
+       }
+       if (len<0)
+               html("...");
+}
 
 void html_attr(char *txt)
 {
        char *t = txt;
-       while(*t){
+       while(t && *t){
                int c = *t;
                if (c=='<' || c=='>' || c=='\'') {
                        *t = '\0';
@@ -89,6 +117,27 @@ void html_attr(char *txt)
                html(txt);
 }
 
+void html_hidden(char *name, 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)
+{
+       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)
 {
        html("<a href='");
@@ -121,6 +170,8 @@ void html_filemode(unsigned short mode)
                html("d");
        else if (S_ISLNK(mode))
                html("l");
+       else if (S_ISGITLINK(mode))
+               html("m");
        else
                html("-");
        html_fileperm(mode >> 6);
@@ -128,3 +179,16 @@ void html_filemode(unsigned short mode)
        html_fileperm(mode);
 }
 
+int html_include(const char *filename)
+{
+       FILE *f;
+       char buf[4096];
+       size_t len;
+
+       if (!(f = fopen(filename, "r")))
+               return -1;
+       while((len = fread(buf, 1, 4096, f)) > 0)
+               write(htmlfd, buf, len);
+       fclose(f);
+       return 0;
+}