]> gitweb.ps.run Git - ps-cgit/blobdiff - html.c
Add separate header-files for each page/view
[ps-cgit] / html.c
diff --git a/html.c b/html.c
index 175b4b687efb75d443b847738775a1de92e97cf6..0962e71a32b66a68f1653594de37506425e5eca9 100644 (file)
--- a/html.c
+++ b/html.c
@@ -6,7 +6,13 @@
  *   (see COPYING for full license text)
  */
 
-#include "cgit.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+int htmlfd = STDOUT_FILENO;
 
 char *fmt(const char *format, ...)
 {
@@ -21,8 +27,10 @@ char *fmt(const char *format, ...)
        va_start(args, format);
        len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
        va_end(args);
-       if (len>sizeof(buf[bufidx]))
-               die("[html.c] string truncated: %s", format);
+       if (len>sizeof(buf[bufidx])) {
+               fprintf(stderr, "[html.c] string truncated: %s\n", format);
+               exit(1);
+       }
        return buf[bufidx];
 }
 
@@ -126,6 +134,18 @@ void html_hidden(char *name, char *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='");
@@ -148,21 +168,20 @@ void html_link_close(void)
 
 void html_fileperm(unsigned short mode)
 {
-       htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), 
+       htmlf("%c%c%c", (mode & 4 ? 'r' : '-'),
              (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-'));
 }
 
-void html_filemode(unsigned short mode)
+int html_include(const char *filename)
 {
-       if (S_ISDIR(mode))
-               html("d");
-       else if (S_ISLNK(mode))
-               html("l");
-       else if (S_ISDIRLNK(mode))
-               html("m");
-       else
-               html("-");
-       html_fileperm(mode >> 6);
-       html_fileperm(mode >> 3);
-       html_fileperm(mode);
+       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;
 }