aboutsummaryrefslogtreecommitdiff
path: root/sim/ppc/tree.c
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2006-02-02 06:45:49 +0000
committerMark Mitchell <mark@codesourcery.com>2006-02-02 06:45:49 +0000
commit59f6d9d6f82ccc6c306740f7eedb613fe0f281a3 (patch)
tree60db3cf8130901a9842110d26c450e43813e1bf3 /sim/ppc/tree.c
parente26af52fd134ceb47298a102d3a0d6ab46e7d69a (diff)
downloadgdb-59f6d9d6f82ccc6c306740f7eedb613fe0f281a3.zip
gdb-59f6d9d6f82ccc6c306740f7eedb613fe0f281a3.tar.gz
gdb-59f6d9d6f82ccc6c306740f7eedb613fe0f281a3.tar.bz2
* emul_netbsd.c (emul_netbsd_create): Quote file-name property.
* emul_unix.c (emul_unix_create): Likewise. * tree.c (libiberty.h): Include it. (tree_quote_property): New function. * tree.h (tree_quote_property): Declare.
Diffstat (limited to 'sim/ppc/tree.c')
-rw-r--r--sim/ppc/tree.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/sim/ppc/tree.c b/sim/ppc/tree.c
index d4cfb71..4338cb0 100644
--- a/sim/ppc/tree.c
+++ b/sim/ppc/tree.c
@@ -45,6 +45,7 @@
#include <ctype.h>
+#include "libiberty.h"
/* manipulate/lookup device names */
@@ -625,6 +626,50 @@ parse_integer_property(device *current,
}
}
+/* PROPERTY_VALUE is a raw property value. Quote it as required by
+ parse_string_property. It is the caller's responsibility to free
+ the memory returned. */
+
+EXTERN_TREE\
+(char *)
+tree_quote_property(const char *property_value)
+{
+ char *p;
+ char *ret;
+ const char *chp;
+ int quotees;
+
+ /* Count characters needing quotes in PROPERTY_VALUE. */
+ quotees = 0;
+ for (chp = property_value; *chp; ++chp)
+ if (*chp == '\\' || *chp == '"')
+ ++quotees;
+
+ ret = (char *) xmalloc (strlen (property_value)
+ + 2 /* quotes */
+ + quotees
+ + 1 /* terminator */);
+
+ p = ret;
+ /* Add the opening quote. */
+ *p++ = '"';
+ /* Copy the value. */
+ for (chp = property_value; *chp; ++chp)
+ if (*chp == '\\' || *chp == '"')
+ {
+ /* Quote this character. */
+ *p++ = '\\';
+ *p++ = *chp;
+ }
+ else
+ *p++ = *chp;
+ /* Add the closing quote. */
+ *p++ = '"';
+ /* Terminate the string. */
+ *p++ = '\0';
+
+ return ret;
+}
/* <string> ... */