|
diff --git a/shared.c b/shared.c index d0973ab..b42c2a2 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -61,2 +61,3 @@ struct cgit_repo *cgit_add_repo(const char *url) |
61 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; |
61 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; |
| |
62 | ret->enable_subject_links = ctx.cfg.enable_subject_links; |
62 | ret->max_stats = ctx.cfg.max_stats; |
63 | ret->max_stats = ctx.cfg.max_stats; |
@@ -281,2 +282,6 @@ int cgit_diff_files(const unsigned char *old_sha1, |
281 | *binary = 1; |
282 | *binary = 1; |
| |
283 | if (file1.size) |
| |
284 | free(file1.ptr); |
| |
285 | if (file2.size) |
| |
286 | free(file2.ptr); |
282 | return 0; |
287 | return 0; |
@@ -295,2 +300,6 @@ int cgit_diff_files(const unsigned char *old_sha1, |
295 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
300 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
| |
301 | if (file1.size) |
| |
302 | free(file1.ptr); |
| |
303 | if (file2.size) |
| |
304 | free(file2.ptr); |
296 | return 0; |
305 | return 0; |
@@ -430 +439,72 @@ int readfile(const char *path, char **buf, size_t *size) |
430 | } |
439 | } |
| |
440 | |
| |
441 | int is_token_char(char c) |
| |
442 | { |
| |
443 | return isalnum(c) || c == '_'; |
| |
444 | } |
| |
445 | |
| |
446 | /* Replace name with getenv(name), return pointer to zero-terminating char |
| |
447 | */ |
| |
448 | char *expand_macro(char *name, int maxlength) |
| |
449 | { |
| |
450 | char *value; |
| |
451 | int len; |
| |
452 | |
| |
453 | len = 0; |
| |
454 | value = getenv(name); |
| |
455 | if (value) { |
| |
456 | len = strlen(value); |
| |
457 | if (len > maxlength) |
| |
458 | len = maxlength; |
| |
459 | strncpy(name, value, len); |
| |
460 | } |
| |
461 | return name + len; |
| |
462 | } |
| |
463 | |
| |
464 | #define EXPBUFSIZE (1024 * 8) |
| |
465 | |
| |
466 | /* Replace all tokens prefixed by '$' in the specified text with the |
| |
467 | * value of the named environment variable. |
| |
468 | * NB: the return value is a static buffer, i.e. it must be strdup'd |
| |
469 | * by the caller. |
| |
470 | */ |
| |
471 | char *expand_macros(const char *txt) |
| |
472 | { |
| |
473 | static char result[EXPBUFSIZE]; |
| |
474 | char *p, *start; |
| |
475 | int len; |
| |
476 | |
| |
477 | p = result; |
| |
478 | start = NULL; |
| |
479 | while (p < result + EXPBUFSIZE - 1 && txt && *txt) { |
| |
480 | *p = *txt; |
| |
481 | if (start) { |
| |
482 | if (!is_token_char(*txt)) { |
| |
483 | if (p - start > 0) { |
| |
484 | *p = '\0'; |
| |
485 | len = result + EXPBUFSIZE - start - 1; |
| |
486 | p = expand_macro(start, len) - 1; |
| |
487 | } |
| |
488 | start = NULL; |
| |
489 | txt--; |
| |
490 | } |
| |
491 | p++; |
| |
492 | txt++; |
| |
493 | continue; |
| |
494 | } |
| |
495 | if (*txt == '$') { |
| |
496 | start = p; |
| |
497 | txt++; |
| |
498 | continue; |
| |
499 | } |
| |
500 | p++; |
| |
501 | txt++; |
| |
502 | } |
| |
503 | *p = '\0'; |
| |
504 | if (start && p - start > 0) { |
| |
505 | len = result + EXPBUFSIZE - start - 1; |
| |
506 | p = expand_macro(start, len); |
| |
507 | *p = '\0'; |
| |
508 | } |
| |
509 | return result; |
| |
510 | } |
|