+2008-06-29 Guillem Jover <guillem@debian.org>
+
+ * lib/Makefile.am (libdpkg_a_SOURCES): Add 'string.c'.
+ * lib/dpkg-priv.h (str_escape_fmt): New prototype.
+ * lib/parsehelp.c: Include <dpkg-priv.h>.
+ (parseerr): Refactor string format escaping to ,,,
+ * lib/string.c (str_escape_fmt): ... here. New file.
+
2008-06-28 Guillem Jover <guillem@debian.org>
* lib/parsedump.h (parseerr, parsemustfield): Remove unused 'file'
#define sizeof_array(a) (sizeof(a) / sizeof((a)[0]))
#endif
+/* String handling. */
+
+char *str_escape_fmt(char *dest, const char *src);
+
/* Path handling. */
size_t rtrim_slash_slashdot(char *path);
#include <dpkg.h>
#include <dpkg-db.h>
+#include <dpkg-priv.h>
+
#include "parsedump.h"
void parseerr
sprintf(buf2, _(" package `%.255s'"), pigp->name);
strcat(buf1,buf2);
}
- for (p=buf1, q=buf2; *p; *q++= *p++) if (*p == '%') *q++= '%';
+ q = str_escape_fmt(buf2, buf1);
strcpy(q,":\n "); strcat(q,fmt);
va_start(al,fmt);
if (!warnonly) ohshitv(buf2,al);
--- /dev/null
+/*
+ * libdpkg - Debian packaging suite library routines
+ * string.c - string handling routines
+ *
+ * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
+ * Copyright © 2008 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dpkg; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+char *
+str_escape_fmt(char *dst, const char *src)
+{
+ char *d = dst;
+ const char *s = src;
+
+ while (*s) {
+ if (*s == '%')
+ *d++ = '%';
+ *d++ = *s++;
+ }
+
+ *d = '\0';
+
+ return d;
+}
+