summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-13 13:42:27 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-05-13 13:42:27 +0000
commit0fa38fefaf203f99f52eefa6d9c3c0e61f18d6e2 (patch)
treec0a4e821b2326392b8c36b01330a482f962de89e /src
parent085009cc578c5b053b70e823f3a336e36e66b22a (diff)
downloadttf2f-0fa38fefaf203f99f52eefa6d9c3c0e61f18d6e2.tar.gz
ttf2f-0fa38fefaf203f99f52eefa6d9c3c0e61f18d6e2.tar.bz2
Sanitise Font$Path entries before constructing destination menu.
svn path=/trunk/tools/ttf2f/; revision=7505
Diffstat (limited to 'src')
-rw-r--r--src/toolbox.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/toolbox.c b/src/toolbox.c
index 2c4bf5a..27fedef 100644
--- a/src/toolbox.c
+++ b/src/toolbox.c
@@ -93,7 +93,7 @@ void ttf2f_init(int argc, char **argv)
{
os_error *error;
toolbox_block toolbox_block;
- char *stringset;
+ const char *fontpath;
ttf2f_result res;
UNUSED(argc);
@@ -136,10 +136,42 @@ void ttf2f_init(int argc, char **argv)
exit(1);
}
- stringset = getenv("Font$Path");
- if (stringset) {
- error = xstringset_set_available(0, main_window, 7,
- stringset);
+ fontpath = getenv("Font$Path");
+ if (fontpath) {
+ size_t len = strlen(fontpath);
+ char buf[len];
+ char *b;
+ const char *p;
+
+ for (b = buf, p = fontpath; *p != '\0'; ) {
+ /* Strip leading spaces */
+ while (*p != '\0' && *p == ' ')
+ p++;
+
+ /* Ignore paths that begin with a '.'.
+ * These cannot be valid */
+ if (*p == '.' && (b == buf || *(b - 1) == ',')) {
+ /* Skip to end or next comma */
+ while (*p != '\0' && *p != ',')
+ p++;
+ /* Skip comma */
+ if (*p == ',')
+ p++;
+ } else if (*p != '\0') {
+ *(b++) = *(p++);
+ }
+
+ /* Strip trailing spaces */
+ if (b > buf && *(b - 1) == ',') {
+ b--;
+ while (b > buf && *(b - 1) == ' ')
+ b--;
+ *(b++) = ',';
+ }
+ }
+ *b = '\0';
+
+ error = xstringset_set_available(0, main_window, 7, buf);
if (error) {
fprintf(stderr,
"stringset_set_available: 0x%x: %s\n",