From 6b6884ddfaf656a49310f8a454038b45b98b8529 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 10 Nov 2024 20:22:33 +0300 Subject: [PATCH] fixed --- config.h | 14 +++++++++----- img.c | 29 ++++++++++++++++++++++------- logo.png | Bin 0 -> 4283 bytes style.css | 2 ++ 4 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 logo.png 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 0000000000000000000000000000000000000000..93eecb4be7f4ecbaf97241adbbaee35343638a0f GIT binary patch literal 4283 zcmeHKeQ*lr>AxtAE(uyKA>o z#8apBWbdk_?(3acmOdd?@Y-qJoTjFgEwAspMz=g`ISUi}67H-hUUcR0y(X0^;Q?r~ zxg9p!U_vO3hCSO`9zO1#v8nysM_d2-qG^lmSD(5(sfmX&?@d2Z)EV26nl`iU{@NWq zbN`)smz;l3XJN1~c)R_>&d&5FOnnPBhx>oLoPs};^l|Gt6)aFUUs+J{T=TVW=a#S? z+HbJ*TgR^M`6#+{O-s$O?`jHfbw7V#`bn_3W~aU8qZ0Z#nBP_~Kem_jju<9c~~yj(fXm(vs9x_?P#nsZZza-0;lP z4`;&6mo7g}tBw2fT-we1_vO9;-??<~mZh=gE2@5{ExSv6&n6l4h^5{YOdv{nrH2+C|W6QqvN>2QR=!&L!^i{gRs zLYX4YVFzJ81cMS31DMRodBh6Is?nfvY%o55(CHka4}=F)Kza~SE=W*XlJNV9ku$P-}_H|xm}bOj(3M*SvJQlyqI$;0knAxbnBoU{zNC}c>~FKjWkYrjRsUcFTg#3r*PT;1U*ga3|>!M)gkt<=#?T| z2xRz>jz}xior+f2V!426qeF?50l7LzFPt>u!+KEzdJzNp67r5Qn6QQTA4x0q0vrF|-v9NQT1wC4U2@_$6In*tnB1={qjhxLjjWU`*ig?i!bCObUz%Jl1>S>KD-n#O{iF03X zTz>xgk(&*l|GlsNRL<@n+-u%%rs!uYFETd~iSJh|J zH>Pdq?47Be55C{gUD9yLWnQuK$&U}Hk33MjEw5zFmd$5Bm@MR+`E}1Xv6|a?ceHJm y@27ow;B)n>!9Ul2SrO@fz3%FZo93nVzucd21G-_PY2qU&OO+$bWpB