progress with _hex and _16_hex
This commit is contained in:
parent
ff4eb5ba98
commit
f4169b0819
Binary file not shown.
|
@ -288,7 +288,12 @@ public class ConfigDefinition {
|
||||||
name = line.substring(0, index);
|
name = line.substring(0, index);
|
||||||
line = line.substring(index).trim();
|
line = line.substring(index).trim();
|
||||||
}
|
}
|
||||||
VariableRegistry.INSTANCE.register(name, line);
|
if (VariableRegistry.isNumeric(line)) {
|
||||||
|
Integer v = Integer.valueOf(line);
|
||||||
|
VariableRegistry.INSTANCE.register(name, v);
|
||||||
|
} else {
|
||||||
|
VariableRegistry.INSTANCE.register(name, line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getMd5(byte[] content) {
|
private static String getMd5(byte[] content) {
|
||||||
|
|
|
@ -15,6 +15,8 @@ import static com.rusefi.ReaderState.MULT_TOKEN;
|
||||||
* 3/30/2015
|
* 3/30/2015
|
||||||
*/
|
*/
|
||||||
public class VariableRegistry {
|
public class VariableRegistry {
|
||||||
|
private static final String _16_HEX_SUFFIX = "_16_hex";
|
||||||
|
private static final String _HEX_SUFFIX = "_hex";
|
||||||
private TreeMap<String, String> data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
private TreeMap<String, String> data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
public static final VariableRegistry INSTANCE = new VariableRegistry();
|
public static final VariableRegistry INSTANCE = new VariableRegistry();
|
||||||
|
|
||||||
|
@ -69,18 +71,31 @@ public class VariableRegistry {
|
||||||
|
|
||||||
if (!value.contains("\n")) {
|
if (!value.contains("\n")) {
|
||||||
// multi-lines are not supported in C headers
|
// multi-lines are not supported in C headers
|
||||||
cAllDefinitions.put(var, "#define " + var + " " + value + EOL);
|
if (!var.endsWith(_16_HEX_SUFFIX) && !var.endsWith(_HEX_SUFFIX)) {
|
||||||
|
cAllDefinitions.put(var, "#define " + var + " " + value + EOL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tryToRegisterAsInteger(var, value);
|
tryToRegisterAsInteger(var, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isNumeric(String str) {
|
||||||
|
try {
|
||||||
|
Integer.parseInt(str);
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
private void tryToRegisterAsInteger(String var, String value) {
|
private void tryToRegisterAsInteger(String var, String value) {
|
||||||
try {
|
try {
|
||||||
int intValue = Integer.parseInt(value);
|
int intValue = Integer.parseInt(value);
|
||||||
SystemOut.println("key [" + var + "] value: " + intValue);
|
SystemOut.println("key [" + var + "] value: " + intValue);
|
||||||
intValues.put(var, intValue);
|
intValues.put(var, intValue);
|
||||||
javaDefinitions.put(var, "\tpublic static final int " + var + " = " + intValue + ";" + EOL);
|
if (!var.endsWith(_HEX_SUFFIX)) {
|
||||||
|
javaDefinitions.put(var, "\tpublic static final int " + var + " = " + intValue + ";" + EOL);
|
||||||
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
SystemOut.println("Not an integer: " + value);
|
SystemOut.println("Not an integer: " + value);
|
||||||
|
|
||||||
|
@ -105,7 +120,9 @@ public class VariableRegistry {
|
||||||
*/
|
*/
|
||||||
public void register(String name, int value) {
|
public void register(String name, int value) {
|
||||||
register(name, Integer.toString(value));
|
register(name, Integer.toString(value));
|
||||||
register(name + "_hex", Integer.toString(value, 16));
|
register(name + _HEX_SUFFIX, Integer.toString(value, 16));
|
||||||
|
String _16_hex = String.format("\\\\x%02x\\\\x%02x", (value >> 8) & 0xFF, value & 0xFF);
|
||||||
|
register(name + _16_HEX_SUFFIX, _16_hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeDefinesToFile(String fileName) throws IOException {
|
public void writeDefinesToFile(String fileName) throws IOException {
|
||||||
|
|
|
@ -21,5 +21,7 @@ public class VariableRegistryTest {
|
||||||
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
|
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
|
||||||
// both decimal and hex values here
|
// both decimal and hex values here
|
||||||
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff"));
|
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff"));
|
||||||
|
|
||||||
|
assertEquals("\\x01\\x00", VariableRegistry.INSTANCE.applyVariables("@@var_16_hex@@"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue