diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-01-30 16:03:10 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-01-30 16:03:10 -0800 |
commit | 00d3278c8534a8244ae3447189401111e017fd5d (patch) | |
tree | f1c19903bc10ffe4816642040080fb6cfd5da376 /interpolate.c | |
parent | b9b727ddb3c9e005bc4e9af0b990b6ef06d7f621 (diff) | |
parent | b319ef70a94731a5c6f18d07a49d5dda3f06f5d3 (diff) | |
download | git-00d3278c8534a8244ae3447189401111e017fd5d.tar.gz git-00d3278c8534a8244ae3447189401111e017fd5d.tar.xz |
Merge commit 'b319ef7' into jc/maint-fix-test-perm
* commit 'b319ef7': (8132 commits)
Add a small patch-mode testing library
git-apply--interactive: Refactor patch mode code
t8005: Nobody writes Russian in shift_jis
Fix severe breakage in "git-apply --whitespace=fix"
Update release notes for 1.6.4
After renaming a section, print any trailing variable definitions
Make section_name_match start on '[', and return the length on success
send-email: detect cycles in alias expansion
Show the presence of untracked files in the bash prompt.
SunOS grep does not understand -C<n> nor -e
Fix export_marks() error handling.
git repack: keep commits hidden by a graft
Add a test showing that 'git repack' throws away grafted-away parents
git branch: clean up detached branch handling
git branch: avoid unnecessary object lookups
git branch: fix performance problem
git svn: fix shallow clone when upstream revision is too new
do_one_ref(): null_sha1 check is not about broken ref
configure.ac: properly unset NEEDS_SSL_WITH_CRYPTO when sha1 func is missing
janitor: useless checks before free
...
Diffstat (limited to 'interpolate.c')
-rw-r--r-- | interpolate.c | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/interpolate.c b/interpolate.c deleted file mode 100644 index fb30694f4..000000000 --- a/interpolate.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2006 Jon Loeliger - */ - -#include "git-compat-util.h" -#include "interpolate.h" - - -void interp_set_entry(struct interp *table, int slot, const char *value) -{ - char *oldval = table[slot].value; - char *newval = NULL; - - if (oldval) - free(oldval); - - if (value) - newval = xstrdup(value); - - table[slot].value = newval; -} - - -void interp_clear_table(struct interp *table, int ninterps) -{ - int i; - - for (i = 0; i < ninterps; i++) { - interp_set_entry(table, i, NULL); - } -} - - -/* - * Convert a NUL-terminated string in buffer orig - * into the supplied buffer, result, whose length is reslen, - * performing substitutions on %-named sub-strings from - * the table, interps, with ninterps entries. - * - * Example interps: - * { - * { "%H", "example.org"}, - * { "%port", "123"}, - * { "%%", "%"}, - * } - * - * Returns 1 on a successful substitution pass that fits in result, - * Returns 0 on a failed or overflowing substitution pass. - */ - -int interpolate(char *result, int reslen, - const char *orig, - const struct interp *interps, int ninterps) -{ - const char *src = orig; - char *dest = result; - int newlen = 0; - const char *name, *value; - int namelen, valuelen; - int i; - char c; - - memset(result, 0, reslen); - - while ((c = *src) && newlen < reslen - 1) { - if (c == '%') { - /* Try to match an interpolation string. */ - for (i = 0; i < ninterps; i++) { - name = interps[i].name; - namelen = strlen(name); - if (strncmp(src, name, namelen) == 0) { - break; - } - } - - /* Check for valid interpolation. */ - if (i < ninterps) { - value = interps[i].value; - valuelen = strlen(value); - - if (newlen + valuelen < reslen - 1) { - /* Substitute. */ - strncpy(dest, value, valuelen); - newlen += valuelen; - dest += valuelen; - src += namelen; - } else { - /* Something's not fitting. */ - return 0; - } - - } else { - /* Skip bogus interpolation. */ - *dest++ = *src++; - newlen++; - } - - } else { - /* Straight copy one non-interpolation character. */ - *dest++ = *src++; - newlen++; - } - } - - return newlen < reslen - 1; -} |