@@ 2,6 2,8 @@
// public domain
// by Marek Maskarinec <marek@mrms.cz>
+#include <assert.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ 20,12 22,12 @@ const char *page =
"img {"
"width: 90vw;"
- "height: 90vh;"
+ "height: 80vh;"
"object-fit: contain;"
"}"
"table {"
- "height: 90vh;"
+ "height: 80vh;"
"}"
"/* Custom CSS */"
@@ 36,29 38,19 @@ const char *page =
"<body>"
"<table><tr>"
"<td><a class=\"arrow\" ""href=\"/%s\"><b><</b></a></td>"
- "<td><img src=\"/%s\" /></td>"
+ "<td><img src=\"%s\" /></td>"
"<td><a class=\"arrow\" ""href=\"/%s\"><b>></b></a></td>"
"</tr></table>"
+ "%s"
"</body>";
static
char *pagename(char *img) {
char *s = calloc(sizeof(char), strlen(img) + strlen(".html") + 1);
+ assert(s != NULL);
strcpy(s, img);
-
- char *p = s + strlen(img);
- while (p != s) {
- if (*p == '.')
- break;
-
- --p;
- }
-
- if (p == s) // the image has no extension
- strcat(s, ".html");
- else
- strcpy(p, ".html");
+ strcat(s, ".html");
return s;
}
@@ 81,7 73,7 @@ char *readall(char *path) {
char *buf = malloc(siz + 1);
buf[siz - 1] = 0;
- fread(buf, 1, siz, f);
+ siz = fread(buf, 1, siz, f);
fclose(f);
return buf;
@@ 92,9 84,10 @@ extern int optind;
int main(int argc, char *argv[]) {
char *css = NULL;
+ char *custom = NULL;
char ch;
- while ((ch = getopt(argc, argv, "hs:")) >= 0) {
+ while ((ch = getopt(argc, argv, "hs:c:")) >= 0) {
switch (ch) {
case 's':;
if (!(css = readall(optarg))) {
@@ 104,11 97,16 @@ int main(int argc, char *argv[]) {
break;
+ case 'c':
+ custom = optarg;
+ break;
+
case '?':
fprintf(stderr, "invalid option.\n");
case 'h':
default:
fprintf(stderr, "-s path - use custom css\n");
+ fprintf(stderr, "-c string - add custom content bello the image\n");
return 1;
}
}
@@ 128,12 126,13 @@ int main(int argc, char *argv[]) {
FILE *f = fopen(name, "w");
if (!f) {
- fprintf(stderr, "ERROR: file %s not found\n", name);
+ fprintf(stderr, "stagal: %s, %s\n", name, strerror(errno));
goto fail;
}
- fprintf(f, page, css ? css : "", prev, argv[i], next);
+ fprintf(f, page, css ? css : "",
+ prev, argv[i], next, custom ? custom : "");
fclose(f);
free(prev);