diff --git a/config.h b/config.h index 5a76a51..21a764f 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,11 @@ +/* Absolute path to */ +#define ROOT "8img_dir" +#define DB ROOT"/db" + +/* Html generator */ +#define CSS "style.css" +#define LOGO "logo.png" + +#define DESC "+100500 photos of windowmaker" #define TITLE "8img gallery" #define POST_PER_PAGE 5 - -/* Absolute path to */ -#define ROOT "." -#define DB ROOT"/db" -#define CSS ROOT"/style.css" diff --git a/img.c b/img.c index c684b8e..a15227b 100644 --- a/img.c +++ b/img.c @@ -21,14 +21,23 @@ struct UNIQ_TAGS { size_t size; }; -char *gen_id(void) { - char *alf = "qwertyUIOPasdfghjklQWERTASDFGHJKLZXCVBNMzxcvbnm1234567890"; +char *gen_id(const char *filename) { + const char *alf = "qwertyUIOPasdfghjklQWERTASDFGHJKLZXCVBNMzxcvbnm1234567890"; - static char id[6]; - for (size_t i = 0; i < sizeof(id); i++) + char *ext = strrchr(filename, '.'); + if (ext == NULL) + ext = ""; + + size_t size = 7 + strlen(ext); + char *id = malloc(size); + if (id == NULL) + return NULL; + + for (size_t i = 0; i < size - strlen(ext); i++) id[i] = alf[rand() % sizeof(alf)]; - id[sizeof(id) - 1] = '\0'; + strcat(id, ext); + id[size] = '\0'; return id; } @@ -67,8 +76,14 @@ void add(char **list, const int size) { char new_path[PATH_MAX + 1]; while (1) { - name = gen_id(); + name = gen_id(list[0]); + if (name == NULL) { + fprintf(stderr, "8img: malloc: %s\n", strerror(errno)); + exit(1); + } + snprintf(new_path, sizeof(new_path), "%s/%s", ROOT, name); + free(name); struct stat sb; if (stat(new_path, &sb) < 0) @@ -239,7 +254,7 @@ RDB_CLOSE: } struct DB_STR *build_html(FILE *fp, const char *file, const struct UNIQ_TAGS ut, struct DB_STR *db, const size_t page, const size_t pages) { - fprintf(fp, "\n\n\n%s\n\n\n
", CSS, TITLE); + fprintf(fp, "\n\n\n%s\n\n\n

%s

Page %zu

", CSS, TITLE, LOGO, DESC, page); /* Tags */ fputs("\n [all] ", fp); diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..93eecb4 Binary files /dev/null and b/logo.png differ diff --git a/style.css b/style.css index 18a1303..f5f9159 100644 --- a/style.css +++ b/style.css @@ -12,6 +12,8 @@ a { text-decoration: none; } background-color: #ebdbb2; } +#text { color: #ebdbb2; } + img { height: auto; width: auto;