This commit is contained in:
parent
5ee3cbd289
commit
fd8b2a3301
2 changed files with 32 additions and 50 deletions
|
|
@ -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;
|
while((str = strstr(href_wd, "./")) == href_wd) href_wd += 2;
|
||||||
|
|
||||||
for(i = 0; i < mapping_len; i++) {
|
if(strstr(href_wd, "://") == NULL) {
|
||||||
char* key = u_strdup(mapping[i]);
|
for(i = 0; i < mapping_len; i++) {
|
||||||
char* value = strchr(key, '=');
|
char* key = u_strdup(mapping[i]);
|
||||||
char* path_abs;
|
char* value = strchr(key, '=');
|
||||||
char* href_abs;
|
char* path_abs;
|
||||||
|
char* href_abs;
|
||||||
|
|
||||||
if(value != NULL) {
|
if(value != NULL) {
|
||||||
value[0] = 0;
|
value[0] = 0;
|
||||||
value++;
|
value++;
|
||||||
}
|
}
|
||||||
|
|
||||||
path_abs = u_path_combine(argbase, key);
|
path_abs = u_path_combine(argbase, key);
|
||||||
|
|
||||||
if(href_wd[0] == '/') {
|
if(href_wd[0] == '/') {
|
||||||
href_abs = u_path_combine(argbase, href_wd);
|
href_abs = u_path_combine(argbase, href_wd);
|
||||||
} else {
|
} else {
|
||||||
href_abs = u_path_combine(argbase2, href_wd);
|
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(path_abs);
|
||||||
free(href_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();
|
print_indent();
|
||||||
|
|
|
||||||
26
src/util.c
26
src/util.c
|
|
@ -30,7 +30,7 @@ char* u_strdup(const char* str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* u_path(const char* top, const char* path) {
|
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) > 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 */
|
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) {
|
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 */
|
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);
|
p = path_func(top, path);
|
||||||
|
|
||||||
if(strlen(p) > 3 && strstr(p, "://") != NULL) {
|
if(strstr(p, "://") != NULL) {
|
||||||
free(p);
|
free(p);
|
||||||
return 0;
|
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] = {
|
unsigned char png_sig[16] = {
|
||||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
||||||
0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52};
|
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);
|
fseek(f, 0, SEEK_SET);
|
||||||
if(fread(buffer, 1, 16, f) == 16 && memcmp(buffer, png_sig, 16) == 0 && fread(buffer, 1, 13, f) == 13) {
|
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;
|
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);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue