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

This commit is contained in:
Nishi 2026-03-10 06:55:58 +09:00
commit fd8b2a3301
Signed by: nishi
GPG key ID: 27EF69B208EB9343
2 changed files with 32 additions and 50 deletions

View file

@ -225,37 +225,39 @@ static int enter_span(MD_SPANTYPE type, void* detail, void* user) {
while((str = strstr(href_wd, "./")) == href_wd) href_wd += 2;
for(i = 0; i < mapping_len; i++) {
char* key = u_strdup(mapping[i]);
char* value = strchr(key, '=');
char* path_abs;
char* href_abs;
if(strstr(href_wd, "://") == NULL) {
for(i = 0; i < mapping_len; i++) {
char* key = u_strdup(mapping[i]);
char* value = strchr(key, '=');
char* path_abs;
char* href_abs;
if(value != NULL) {
value[0] = 0;
value++;
}
if(value != NULL) {
value[0] = 0;
value++;
}
path_abs = u_path_combine(argbase, key);
path_abs = u_path_combine(argbase, key);
if(href_wd[0] == '/') {
href_abs = u_path_combine(argbase, href_wd);
} else {
href_abs = u_path_combine(argbase2, href_wd);
}
if(href_wd[0] == '/') {
href_abs = u_path_combine(argbase, href_wd);
} else {
href_abs = u_path_combine(argbase2, href_wd);
}
if(value != NULL && strcmp(path_abs, href_abs) == 0) {
if(value != NULL && strcmp(path_abs, href_abs) == 0) {
free(path_abs);
free(href_abs);
free(href);
href = encode(value, -1);
free(key);
break;
}
free(path_abs);
free(href_abs);
free(href);
href = encode(value, -1);
free(key);
break;
}
free(path_abs);
free(href_abs);
free(key);
free(key);
}
}
print_indent();

View file

@ -30,7 +30,7 @@ char* u_strdup(const char* str) {
}
char* u_path(const char* top, const char* path) {
if(strlen(path) > 3 && strstr(path, "://") != NULL) return u_strdup(path); /* link - return as is */
if(strstr(path, "://") != NULL) return u_strdup(path); /* link - return as is */
if(strlen(path) > 2 && memcmp(path, "./", 2) == 0) return u_strdup(path); /* current directory - probably intended */
if(strlen(path) > 3 && memcmp(path, "../", 2) == 0) return u_strdup(path); /* parent directory - also probably intended */
@ -38,7 +38,7 @@ char* u_path(const char* top, const char* path) {
}
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 */
if(strstr(path, "://") != NULL) return u_strdup(path); /* link - return as is */
return u_strvacat(top, "build/", path, NULL); /* otherwise, concat */
}
@ -54,7 +54,7 @@ int u_image_size(const char* top, const char* path, char* (*path_func)(const cha
p = path_func(top, path);
if(strlen(p) > 3 && strstr(p, "://") != NULL) {
if(strstr(p, "://") != NULL) {
free(p);
return 0;
}
@ -64,8 +64,6 @@ int u_image_size(const char* top, const char* path, char* (*path_func)(const cha
unsigned char png_sig[16] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52};
unsigned char gif_sig[6] = {
0x47, 0x49, 0x46, 0x38, 0x39, 0x61}; /* GIF89a */
fseek(f, 0, SEEK_SET);
if(fread(buffer, 1, 16, f) == 16 && memcmp(buffer, png_sig, 16) == 0 && fread(buffer, 1, 13, f) == 13) {
@ -85,24 +83,6 @@ int u_image_size(const char* top, const char* path, char* (*path_func)(const cha
st = 1;
}
fseek(f, 0, SEEK_SET);
if(fread(buffer, 1, 6, f) == 6 && memcmp(buffer, gif_sig, 6) == 0 && fread(buffer, 1, 4, f) == 4) {
int i;
*w = 0;
*h = 0;
for(i = 0; i < 2; i++) {
*w = (*w) << 8;
*w |= buffer[1 - i + 0];
*h = (*h) << 8;
*h |= buffer[1 - i + 2];
}
st = 1;
}
fclose(f);
}