remove stb
All checks were successful
pyrite-dev/taiga/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-03-09 00:43:35 +09:00
commit e659037335
Signed by: nishi
GPG key ID: 27EF69B208EB9343
7 changed files with 118 additions and 10 deletions

View file

@ -1,7 +1,7 @@
CC ?= cc
CFLAGS ?= -I external/xemil/include -I src $(DEFS)
CFLAGS ?= -I external/xemil/include -I external/stb -I src $(DEFS)
LDFLAGS ?=
LIBS ?=
LIBS ?= -lm
AFTER ?=
E ?=

View file

@ -215,8 +215,18 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body
char* text = xl_get_attribute(nodes[0], "src");
if(text != NULL) {
int ws, hs;
char size[256];
size[0] = 0;
if(u_image_size(top, text, u_http_path, &ws, &hs)) {
sprintf(size, " width=\"%d\" height=\"%d\"", ws, hs);
}
text = u_path(top, text);
fprintf(out, " <a href=\"%s\"><img src=\"%s\" alt=\"%s\" border=\"0\"></a>\n", link, text, images[i + 1], name);
fprintf(out, " <a href=\"%s\"><img src=\"%s\" alt=\"%s\" border=\"0\"%s></a>\n", link, text, name, size);
free(text);
}

View file

@ -179,10 +179,27 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) {
sprintf(end, "</%s>", element->name);
} else if(strcmp(element->name, "img") == 0) {
xl_attribute_t* attr = element->first_attribute;
char* r;
char* w;
char* h;
int ws, hs;
accept_attr(text, element, "src", "alt", "title", "height", "width", "id", "class", NULL);
w = xl_get_attribute(element, "width");
h = xl_get_attribute(element, "height");
if((w == NULL || h == NULL) && (r = xl_get_attribute(element, "src")) != NULL) {
if(u_image_size(top, r, u_http_path, &ws, &hs)) {
if(w == NULL && h == NULL) {
sprintf(text + strlen(text), "width=\"%d\" height=\"%d\"", ws, hs);
} else if(w != NULL) {
sprintf(text + strlen(text), "width=\"%d\" height=\"%d\"", atoi(w), hs * atoi(w) / ws);
} else if(h != NULL) {
sprintf(text + strlen(text), "width=\"%d\" height=\"%d\"", ws * atoi(h) / hs, atoi(h));
}
}
}
sprintf(tag, "<%s%s border=\"0\">", element->name, text);
} else if(strcmp(element->name, "script") == 0) {
accept_attr(text, element, "src", "type", NULL);

View file

@ -187,6 +187,9 @@ void simple_body(FILE* out, const char* top, const char* title, xl_node_t* body)
xl_node_t* child;
char* text;
char* link;
char size[256];
size[0] = 0;
strcpy(year, "Some year");
@ -254,7 +257,13 @@ void simple_body(FILE* out, const char* top, const char* title, xl_node_t* body)
}
if(text != NULL) {
fprintf(out, " <a href=\"%s\"><img src=\"%s\" alt=\"Project logo\" border=\"0\"></a>\n", link, text);
int ws, hs;
if(u_image_size(top, text, u_http_path, &ws, &hs)) {
sprintf(size, " width=\"%d\" height=\"%d\"", ws, hs);
}
fprintf(out, " <a href=\"%s\"><img src=\"%s\" alt=\"Project logo\" border=\"0\"%s></a>\n", link, text, size);
free(text);
}

View file

@ -5,7 +5,7 @@ void (*site_stylesheet)(FILE* out, const char* top); /* also create files here i
void (*site_head)(FILE* out, const char* top, xl_node_t* header);
void (*site_body)(FILE* out, const char* top, const char* title, xl_node_t* body);
static int scan(const char* top, const char* path) {
static int scan(const char* top, int mode, const char* path) {
char* in = u_strvacat("site/content/", path, NULL);
char* out = u_strvacat("build/", path, NULL);
IO_DIR* dir;
@ -29,7 +29,7 @@ static int scan(const char* top, const char* path) {
io_mkdir(o, 0755);
free(o);
if(!scan(t, p2)) {
if(!scan(t, mode, p2)) {
free(t);
free(p2);
free(p);
@ -41,7 +41,7 @@ static int scan(const char* top, const char* path) {
}
free(t);
free(p2);
} else if(strcmp(d->d_name, "index.xml") == 0) {
} else if(mode && strcmp(d->d_name, "index.xml") == 0) {
printf("%s:\n", p);
if(!process(top, out, p)) {
free(p);
@ -51,7 +51,7 @@ static int scan(const char* top, const char* path) {
return 0;
}
} else {
} else if(!mode) {
char* po = u_strvacat(out, d->d_name, NULL);
FILE* fin = fopen(p, "rb");
FILE* fout = fopen(po, "wb");
@ -130,7 +130,12 @@ int action_site(int argc, char** argv) {
fclose(css);
if(!scan("", "")) {
if(!scan("", 0, "")) {
st = 1;
goto cleanup;
}
if(!scan("", 1, "")) {
st = 1;
goto cleanup;
}

View file

@ -65,6 +65,8 @@ int action_seed(int argc, char** argv);
char* u_strvacat(const char* str, ...);
char* u_strdup(const char* str);
char* u_path(const char* top, const char* path);
char* u_http_path(const char* top, const char* path);
int u_image_size(const char* top, const char* path, char* (*path_func)(const char* top, const char* path), int* w, int* h);
/* process.c */
int process(const char* top, const char* out, const char* full);

View file

@ -36,3 +36,68 @@ char* u_path(const char* top, const char* path) {
return u_strvacat(top, path, NULL); /* otherwise, concat */
}
char* u_http_path(const char* top, const char* path) {
if(strlen(path) > 3 && strstr(path, "://") != NULL) return u_strdup(path); /* link - return as is */
return u_strvacat(top, "build/", path, NULL); /* otherwise, concat */
}
int u_image_size(const char* top, const char* path, char* (*path_func)(const char* top, const char* path), int* w, int* h) {
char* p;
int ch;
FILE* f;
int st = 0;
p = path_func(top, path);
if(strlen(p) > 3 && strstr(p, "://") != NULL) {
free(p);
return 0;
}
if((f = fopen(p, "rb")) != NULL) {
unsigned char buffer[512];
unsigned char png_sig[16] = {
0x89,
0x50,
0x4e,
0x47,
0x0d,
0x0a,
0x1a,
0x0a,
/**/
0x00,
0x00,
0x00,
0x0d,
0x49,
0x48,
0x44,
0x52};
if(fread(buffer, 1, 16, f) == 16 && memcmp(buffer, png_sig, 16) == 0 && fread(buffer, 1, 13, f) == 13) {
int i;
*w = 0;
*h = 0;
for(i = 0; i < 4; i++) {
*w = (*w) << 8;
*w |= buffer[i + 0];
*h = (*h) << 8;
*h |= buffer[i + 4];
}
st = 1;
}
fclose(f);
}
free(p);
return st;
}