Hi
Attached is the patch that allows you to turn off any option by
prefixing the name with "no-"
For example:
mkgmap --description="hello world" 00000001.pbf --no-description
00000002.pbf
will result in the first file having the description "hello world" but
the second one will have no description at all.
..Steve
Index: resources/help/en/copyright
===================================================================
--- resources/help/en/copyright (revision 2383)
+++ resources/help/en/copyright (working copy)
@@ -1,5 +1,5 @@
-This software is Copyright 2006-2008 by the mkgmap authors
+This software is Copyright 2006-2012 by the mkgmap authors
and contributors.
This program is free software; you can redistribute it and/or modify
Index: src/uk/me/parabola/imgfmt/FileSystemParam.java
===================================================================
--- src/uk/me/parabola/imgfmt/FileSystemParam.java (revision 2383)
+++ src/uk/me/parabola/imgfmt/FileSystemParam.java (working copy)
@@ -40,6 +40,8 @@
public void setMapDescription(String mapDescription) {
this.mapDescription = mapDescription;
+ if (this.mapDescription == null)
+ this.mapDescription = "";
}
public int getBlockSize() {
Index: src/uk/me/parabola/mkgmap/ArgumentProcessor.java
===================================================================
--- src/uk/me/parabola/mkgmap/ArgumentProcessor.java (revision 2383)
+++ src/uk/me/parabola/mkgmap/ArgumentProcessor.java (working copy)
@@ -24,15 +24,25 @@
public interface ArgumentProcessor {
/**
- * Process an option. This is intended for options that change state or
- * that say how the next filename is to be operated upon.
+ * Process an option. In general you do not do anything in this callback for most options.
+ * Options that determine how a particular file are processed are saved into a map that
+ * is handed to the map building process.
*
+ * Options that are processed here are things like --help or --list-styles that have an
+ * actual effect by themselves.
+ *
* @param opt The option name.
* @param val The option value.
*/
public void processOption(String opt, String val);
/**
+ * Called when an option is reset, eg --no-tdbfile.
+ * @param opt The option name.
+ */
+ public void removeOption(String opt);
+
+ /**
* Process a filename.
*
* @param args A copy of the option arguments in force when this filename
Index: src/uk/me/parabola/mkgmap/CommandArgsReader.java
===================================================================
--- src/uk/me/parabola/mkgmap/CommandArgsReader.java (revision 2383)
+++ src/uk/me/parabola/mkgmap/CommandArgsReader.java (working copy)
@@ -293,8 +293,13 @@
}
public void processArg() {
- args.setProperty(option.getOption(), option.getValue());
- proc.processOption(option.getOption(), option.getValue());
+ if (option.isReset()) {
+ args.remove(option.getOption());
+ proc.removeOption(option.getOption());
+ } else {
+ args.setProperty(option.getOption(), option.getValue());
+ proc.processOption(option.getOption(), option.getValue());
+ }
}
public String getOption() {
Index: src/uk/me/parabola/mkgmap/Option.java
===================================================================
--- src/uk/me/parabola/mkgmap/Option.java (revision 2383)
+++ src/uk/me/parabola/mkgmap/Option.java (working copy)
@@ -1,18 +1,14 @@
/*
- * Copyright (C) 2008 Steve Ratcliffe
- *
- * 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.
- *
- *
- * Author: Steve Ratcliffe
- * Create date: May 26, 2008
+ * Copyright (C) 2008, 2011.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 or
+ * 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;
@@ -23,6 +19,7 @@
private final String option;
private final String value;
private final boolean experimental;
+ private final boolean reset;
protected Option(String optval) {
String[] v = optval.split("[=:]", 2);
@@ -38,6 +35,13 @@
val = "";
}
+ boolean reset = false;
+ if (name.startsWith("no-")) {
+ reset = true;
+ name = name.substring(3);
+ val = null;
+ }
+
boolean exp = false;
if (name.startsWith("x-")) {
exp = true;
@@ -47,19 +51,11 @@
option = name;
value = val;
experimental = exp;
+ this.reset = reset;
}
protected Option(String option, String value) {
- boolean exp = false;
- String name = option;
- if (name.startsWith("x-")) {
- exp = true;
- name = name.substring(2);
- }
-
- this.option = name;
- this.value = value;
- this.experimental = exp;
+ this(option + '=' + value);
}
public String getOption() {
@@ -73,4 +69,8 @@
public boolean isExperimental() {
return experimental;
}
+
+ public boolean isReset() {
+ return reset;
+ }
}
Index: src/uk/me/parabola/mkgmap/main/Main.java
===================================================================
--- src/uk/me/parabola/mkgmap/main/Main.java (revision 2383)
+++ src/uk/me/parabola/mkgmap/main/Main.java (working copy)
@@ -263,6 +263,9 @@
}
}
+ public void removeOption(String opt) {
+ }
+
private void addTdbBuilder() {
TdbBuilder builder = new TdbBuilder();
builder.setOverviewSource(new OverviewMapDataSource());
Index: test/uk/me/parabola/mkgmap/CommandArgsTest.java
===================================================================
--- test/uk/me/parabola/mkgmap/CommandArgsTest.java (revision 2383)
+++ test/uk/me/parabola/mkgmap/CommandArgsTest.java (working copy)
@@ -85,7 +85,7 @@
String SETNAME1 = "11110000";
String SETNAME2 = "22220000";
- carg.readArgs(new String[] {
+ carg.readArgs(new String[]{
"--mapname=" + SETNAME1, FILE1,
"--mapname=" + SETNAME2, FILE2
});
@@ -156,17 +156,6 @@
assertEquals("description", "OSM-AU New South Wales", arg.getProperty("description"));
}
- private void createFile(String name, String content) throws IOException {
- TestUtils.registerFile(name);
- Writer w = null;
- try {
- w = new FileWriter(name);
- w.append(content);
- } finally {
- Utils.closeFile(w);
- }
- }
-
/**
* Combinations of all mapname possibilities.
*/
@@ -191,6 +180,38 @@
}
/**
+ * Options can be switched off by prefixing them with 'no-'.
+ */
+ @Test
+ public void testArgReset() {
+ carg.readArgs(new String[] {
+ "--keep-going",
+ FILE1,
+ "--no-keep-going",
+ FILE2,
+ "--keep-going",
+ FILE3,
+ });
+
+ assertEquals("first file has keep-going", "", proc.getProperty(0, "keep-going"));
+ assertEquals("second file does not have keep-going", null, proc.getProperty(1, "keep-going"));
+ assertEquals("third file does has keep-going", "", proc.getProperty(2, "keep-going"));
+ assertEquals("any option that was not present is null", null, proc.getProperty(1,
+ "invalid-option-does-not-exist"));
+ }
+
+ private void createFile(String name, String content) throws IOException {
+ TestUtils.registerFile(name);
+ Writer w = null;
+ try {
+ w = new FileWriter(name);
+ w.append(content);
+ } finally {
+ Utils.closeFile(w);
+ }
+ }
+
+ /**
* Argument processor that saves the filenames and the values of
* the arguments that are in scope for each argument.
*/
@@ -213,8 +234,11 @@
public void processOption(String opt, String val) {
}
+ public void removeOption(String opt) {
+ }
+
public void processFilename(CommandArgs args, String filename) {
- ArgCollector.FileArgs fa = new FileArgs();
+ FileArgs fa = new FileArgs();
fa.name = filename;
fa.props = new Properties();
Index: test/uk/me/parabola/mkgmap/OptionTest.java
===================================================================
--- test/uk/me/parabola/mkgmap/OptionTest.java (revision 2383)
+++ test/uk/me/parabola/mkgmap/OptionTest.java (working copy)
@@ -60,4 +60,17 @@
assertEquals("value", "world", o.getValue());
assertTrue("experimental", o.isExperimental());
}
+
+ /**
+ * Test for an negative option eg: no-route. These begin with the prefix 'no-'.
+ * The option name is without the prefix and a flag is set to show that the option
+ * is being reset.
+ */
+ @Test
+ public void testOptionReset() {
+ Option o = new Option("no-hello");
+ assertEquals("name", "hello", o.getOption());
+ assertEquals("value", null, o.getValue());
+ assertTrue("reset", o.isReset());
+ }
}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://lists.mkgmap.org.uk/mailman/listinfo/mkgmap-dev