]> git.ipfire.org Git - thirdparty/git.git/blobdiff - interpolate.c
GIT-VERSION-FILE: check ./version first.
[thirdparty/git.git] / interpolate.c
index d82f1b51bbff4a545a2d5a0aebb91612cacd3d69..f992ef77533737fe2ec52dc3b662cb6cacca0ea2 100644 (file)
@@ -2,11 +2,35 @@
  * Copyright 2006 Jon Loeliger
  */
 
-#include <string.h>
-
+#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,
  */
 
 int interpolate(char *result, int reslen,
-               char *orig,
-               struct interp *interps, int ninterps)
+               const char *orig,
+               const struct interp *interps, int ninterps)
 {
-       char *src = orig;
+       const char *src = orig;
        char *dest = result;
        int newlen = 0;
        char *name, *value;