Index: /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/SubstitutionFilter.java
===================================================================
--- /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/SubstitutionFilter.java	(revision 0)
+++ /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/SubstitutionFilter.java	(revision 0)
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2009 Toby Speight
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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.
+ */
+package uk.me.parabola.mkgmap.osmstyle.actions;
+
+/**
+ * Perform simple string substition on a value.
+ *
+ * @author Toby Speight
+ */
+public class SubstitutionFilter extends ValueFilter {
+	private final String from;
+	private final String to;
+
+	public SubstitutionFilter(String arg) {
+		int i = arg.indexOf("=>");
+		if (i >= 0) {
+			from = arg.substring(0, i);
+			to = arg.substring(i + 2);
+		} else {
+			from = arg;
+			to = "";
+		}
+	}
+
+	public String doFilter(String value) {
+		if (value == null) return null;
+		if (from == null || to == null)
+			// can't happen!
+			return value;
+		return value.replace(from, to);
+	}
+}
Index: /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/ValueBuilder.java
===================================================================
--- /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/ValueBuilder.java	(revision 1000)
+++ /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/ValueBuilder.java	(working copy)
@@ -27,6 +27,7 @@
  * Build a value that can have tag values substituted in it.
  *
  * @author Steve Ratcliffe
+ * @author Toby Speight
  */
 public class ValueBuilder {
 
@@ -92,20 +93,21 @@
 			switch (state) {
 			case 0:
 				if (c == '$') {
-					if (text.length() > 0) {
-						items.add(new ValueItem(text.toString()));
-						text.setLength(0);
-					}
 					state = 1;
 				} else
 					text.append(c);
 				break;
 			case 1:
 				if (c == '{') {
+					if (text.length() > 0) {
+						items.add(new ValueItem(text.toString()));
+						text.setLength(0);
+					}
 					tagname = new StringBuilder();
 					state = 2;
 				} else {
 					state = 0;
+					text.append('$');
 					text.append(c);
 				}
 				break;
@@ -154,6 +156,10 @@
 			item.addFilter(new DefaultFilter(arg));
 		} else if (cmd.equals("conv")) {
 			item.addFilter(new ConvertFilter(arg));
+		} else if (cmd.equals("subst")) {
+			item.addFilter(new SubstitutionFilter(arg));
+		} else if (cmd.equals("prefix")) {
+			item.addFilter(new PrependFilter(arg));
 		}
 	}
 
Index: /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/PrependFilter.java
===================================================================
--- /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/PrependFilter.java	(revision 0)
+++ /home/tms/maps/mkgmap/trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/PrependFilter.java	(revision 0)
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2009 Toby Speight
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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.
+ */
+
+package uk.me.parabola.mkgmap.osmstyle.actions;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Prepend a Garmin magic-character to the value.
+ * TODO: symbolic names?
+ *
+ * @author Toby Speight
+ */
+public class PrependFilter extends ValueFilter {
+	private final String prefix;
+
+	// TODO: runtime select appropriate table
+	private Map<String, String>symbols = symbols_8bit;
+
+	private static final Map<String, String> symbols_6bit;
+	private static final Map<String, String> symbols_8bit;
+
+	static {
+		// Firstly, the symbols common to both encodings
+		symbols_6bit = new HashMap<String, String>();
+		symbols_6bit.put("ele", "\u001f"); // name.height separator
+
+		// Copy to other encoding
+		symbols_8bit = new HashMap<String, String>(symbols_6bit);
+
+		// Now add other symbols
+		symbols_6bit.put("interstate", "\u002a"); // US Interstate
+		symbols_8bit.put("interstate", "\u0001");
+		symbols_6bit.put("shield", "\u002b"); // US Highway shield
+		symbols_8bit.put("shield", "\u0002");
+		symbols_6bit.put("round", "\u002c"); // US Highway round
+		symbols_8bit.put("round", "\u0003");
+		symbols_6bit.put("boxx", "\u002d"); // box with horizontal bands
+		symbols_8bit.put("boxx", "\u0004");
+		symbols_6bit.put("box", "\u002e"); // Square box
+		symbols_8bit.put("box", "\u0005");
+		symbols_6bit.put("oval", "\u002f"); // box with rounded ends
+		symbols_8bit.put("oval", "\u0006");
+	}
+
+	public PrependFilter(String s) {
+		// First, try the lookup table
+		String p = symbols.get(s);
+		if (p == null) {
+			// else, s is a hex constant character number
+			try {
+				p = Character.toString((char)Integer.parseInt(s, 16));
+			} catch (NumberFormatException e) {
+				// failed - use string literally
+				p = s;
+			}
+		}
+		prefix = p;
+	}
+
+	public String doFilter(String value) {
+		return value == null ? null : prefix + value;
+	}
+}
Index: /home/tms/maps/mkgmap/trunk/resources/styles/default/lines
===================================================================
--- /home/tms/maps/mkgmap/trunk/resources/styles/default/lines	(revision 1000)
+++ /home/tms/maps/mkgmap/trunk/resources/styles/default/lines	(working copy)
@@ -8,6 +8,13 @@
 	{ name '${ele|conv:m=>ft}'; }
 	[0x21 resolution 20]
 
+# Set highway names to include the reference if there is one
+highway=motorway {name '${ref|subst: =>.|prefix:boxx} ${name}' | '${ref|subst: =>.|prefix:boxx}' | '${name}' }
+highway=trunk {name '${ref|subst: =>.|subst: =>.|prefix:boxx} ${name}' | '${ref|subst: =>.|prefix:boxx}' | '${name}' }
+highway=primary {name '${ref|subst: =>.|prefix:box} ${name}' | '${ref|subst: =>.|prefix:box}' | '${name}' }
+highway=secondary {name '${ref|subst: =>.|prefix:oval} ${name}' | '${ref|subst: =>.|prefix:oval}' | '${name}' }
+highway=* {name '${ref} ${name}' | '${ref}' | '${name}' }
+
 junction=roundabout & highway=trunk [0x0c road_class=3 road_speed=5 resolution 16]
 junction=roundabout & highway=primary [0x0c road_class=3 road_speed=4 resolution 19]
 junction=roundabout & highway=secondary [0x0c road_class=2 road_speed=3 resolution 20]
@@ -15,8 +22,6 @@
 junction=roundabout & highway=unclassified [0x0c road_class=1 road_speed=2 resolution 21]
 junction=roundabout [0x0c road_class=0 road_speed=1 resolution 21]
 
-# Set highway names to include the reference if there is one
-#highway=* {name '${name} (${ref})' | '${ref}' | '${name}' }
 highway=bridleway {add access = no; add bicycle = yes; add foot = yes} [0x16 road_class=0 road_speed=0 resolution 23]
 highway=byway [0x16 road_class=0 road_speed=0 resolution 23]
 highway=cycleway {add access = no; add bicycle = yes; add foot = yes} [0x16 road_class=0 road_speed=1 resolution 23]
Index: /home/tms/maps/mkgmap/trunk/resources/styles/default/points
===================================================================
--- /home/tms/maps/mkgmap/trunk/resources/styles/default/points	(revision 1000)
+++ /home/tms/maps/mkgmap/trunk/resources/styles/default/points	(working copy)
@@ -92,7 +92,7 @@
 natural=beach [0x6604 resolution 21]
 natural=cliff [0x6607 resolution 21]
 natural=glacier [0x650a resolution 21]
-natural=peak [0x6616 resolution 21]
+natural=peak {name '${name|def:summit}${ele|conv:m=>ft|prefix:1f|def:}' } [0x6616 resolution 16]
 natural=spring [0x6511 resolution 21]
 #natural=stream [0x6512 resolution 21]
 natural=volcano [0x2c0c resolution 21]
