Console commands are broken #1671
This commit is contained in:
parent
c20ee800b8
commit
2b06b4a0fc
Binary file not shown.
|
@ -0,0 +1,14 @@
|
|||
<component name="libraryTable">
|
||||
<library name="httpclient">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpclient.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpcore.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpmime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpmime-javadoc.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpclient-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="json-simple">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/json-simple-1.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -2,6 +2,7 @@ package com.rusefi;
|
|||
|
||||
import com.rusefi.util.LazyFile;
|
||||
import com.rusefi.util.SystemOut;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
@ -17,6 +18,7 @@ import static com.rusefi.ReaderState.MULT_TOKEN;
|
|||
public class VariableRegistry {
|
||||
public static final String _16_HEX_SUFFIX = "_16_hex";
|
||||
public static final String _HEX_SUFFIX = "_hex";
|
||||
public static final String CHAR_SUFFIX = "_char";
|
||||
private static final String HEX_PREFIX = "0x";
|
||||
private final TreeMap<String, String> data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
public static final VariableRegistry INSTANCE = new VariableRegistry();
|
||||
|
@ -51,9 +53,17 @@ public class VariableRegistry {
|
|||
}
|
||||
|
||||
public void register(String var, String value) {
|
||||
value = doRegister(var, value);
|
||||
if (value == null)
|
||||
return;
|
||||
tryToRegisterAsInteger(var, value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String doRegister(String var, String value) {
|
||||
if (data.containsKey(var)) {
|
||||
SystemOut.println("Not redefining " + var);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
value = applyVariables(value);
|
||||
int multPosition = value.indexOf(MULT_TOKEN);
|
||||
|
@ -72,7 +82,7 @@ public class VariableRegistry {
|
|||
cAllDefinitions.put(var, "#define " + var + " " + value + EOL);
|
||||
}
|
||||
}
|
||||
tryToRegisterAsInteger(var, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String str) {
|
||||
|
@ -110,6 +120,9 @@ public class VariableRegistry {
|
|||
} else if (isQuoted(value, '\'')) {
|
||||
// quoted and not with enum suffix means plain string define statement
|
||||
javaDefinitions.put(var, "\tpublic static final char " + var + " = " + value + ";" + EOL);
|
||||
char charValue = value.charAt(1);
|
||||
registerHex(var + CHAR_SUFFIX, charValue);
|
||||
doRegister(var + CHAR_SUFFIX, Character.toString(charValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,6 +146,10 @@ public class VariableRegistry {
|
|||
*/
|
||||
public void register(String name, int value) {
|
||||
register(name, Integer.toString(value));
|
||||
registerHex(name, value);
|
||||
}
|
||||
|
||||
private void registerHex(String name, int value) {
|
||||
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);
|
||||
|
@ -168,6 +185,10 @@ public class VariableRegistry {
|
|||
javaDefinitions.clear();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
public void put(String key, String value) {
|
||||
data.put(key, value);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@ package com.rusefi.test;
|
|||
import com.rusefi.VariableRegistry;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.rusefi.VariableRegistry._16_HEX_SUFFIX;
|
||||
import static com.rusefi.VariableRegistry._HEX_SUFFIX;
|
||||
import static com.rusefi.VariableRegistry.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
|
@ -13,17 +12,29 @@ import static org.junit.Assert.assertEquals;
|
|||
public class VariableRegistryTest {
|
||||
@Test
|
||||
public void testReplace() {
|
||||
VariableRegistry.INSTANCE.clear();
|
||||
|
||||
VariableRegistry.INSTANCE.register("var", 256);
|
||||
VariableRegistry registry = new VariableRegistry();
|
||||
registry.register("var", 256);
|
||||
assertEquals(3, registry.size());
|
||||
|
||||
// trivial key-value substitution
|
||||
assertEquals("256", VariableRegistry.INSTANCE.applyVariables("@@var@@"));
|
||||
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
|
||||
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
|
||||
assertEquals("256", registry.applyVariables("@@var@@"));
|
||||
assertEquals("ab256", registry.applyVariables("ab@@var@@"));
|
||||
assertEquals("ab256cd", registry.applyVariables("ab@@var@@cd"));
|
||||
// both decimal and hex values here
|
||||
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var" + _HEX_SUFFIX + "@@fff"));
|
||||
assertEquals("aa256qwe100fff", registry.applyVariables("aa@@var@@qwe@@var" + _HEX_SUFFIX + "@@fff"));
|
||||
|
||||
assertEquals("\\x01\\x00", VariableRegistry.INSTANCE.applyVariables("@@var" + _16_HEX_SUFFIX + "@@"));
|
||||
assertEquals("\\x01\\x00", registry.applyVariables("@@var" + _16_HEX_SUFFIX + "@@"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharHexUsage() {
|
||||
VariableRegistry registry = new VariableRegistry();
|
||||
registry.register("SD_r", "'r'");
|
||||
|
||||
assertEquals(4, registry.size());
|
||||
assertEquals("ab72", registry.applyVariables("ab@@SD_r" + CHAR_SUFFIX + _HEX_SUFFIX +
|
||||
"@@"));
|
||||
assertEquals("ab'r'", registry.applyVariables("ab@@SD_r@@"));
|
||||
assertEquals("abr", registry.applyVariables("ab@@SD_r" + CHAR_SUFFIX + "@@"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue