Utility class which writes same line both to stdout and file

This commit is contained in:
rusefi 2019-06-17 20:21:32 -04:00
parent 26a94c6def
commit e6b0e0625a
23 changed files with 151 additions and 79 deletions

3
firmware/.gitignore vendored
View File

@ -1,2 +1,5 @@
openocd openocd
benchmark.txt benchmark.txt
gen_config.log
gen_config_board.log
gen_enum_to_string.log

View File

@ -1,10 +1,10 @@
#include "global.h" #include "global.h"
#include "rusefi_enums.h" #include "rusefi_enums.h"
#include "rusefi_hw_enums.h" #include "rusefi_hw_enums.h"
// auto-generated from rusefi_hw_enums.h // was generated automatically by rusEfi tool from rusefi_hw_enums.h
// auto-generated from rusefi_enums.h // was generated automatically by rusEfi tool from rusefi_enums.h
// by enum2string.jar tool // by enum2string.jar tool
// on Tue Jun 04 12:17:32 EDT 2019 // on Mon Jun 17 19:49:25 EDT 2019
// see also gen_config_and_enums.bat // see also gen_config_and_enums.bat
@ -533,8 +533,6 @@ case Force_4_bytes_size_cranking_ignition_mode:
} }
const char *getDebug_mode_e(debug_mode_e value){ const char *getDebug_mode_e(debug_mode_e value){
switch(value) { switch(value) {
case DBG_ETB_LOGIC:
return "DBG_ETB_LOGIC";
case DBG_36: case DBG_36:
return "DBG_36"; return "DBG_36";
case DBG_37: case DBG_37:
@ -567,6 +565,8 @@ case DBG_ELECTRONIC_THROTTLE_PID:
return "DBG_ELECTRONIC_THROTTLE_PID"; return "DBG_ELECTRONIC_THROTTLE_PID";
case DBG_EL_ACCEL: case DBG_EL_ACCEL:
return "DBG_EL_ACCEL"; return "DBG_EL_ACCEL";
case DBG_ETB_LOGIC:
return "DBG_ETB_LOGIC";
case DBG_EXECUTOR: case DBG_EXECUTOR:
return "DBG_EXECUTOR"; return "DBG_EXECUTOR";
case DBG_FSIO_ADC: case DBG_FSIO_ADC:
@ -751,6 +751,8 @@ case MIATA_NA6_MAP:
return "MIATA_NA6_MAP"; return "MIATA_NA6_MAP";
case MIATA_NA6_VAF: case MIATA_NA6_VAF:
return "MIATA_NA6_VAF"; return "MIATA_NA6_VAF";
case MICRO_RUS_EFI:
return "MICRO_RUS_EFI";
case MINIMAL_PINS: case MINIMAL_PINS:
return "MINIMAL_PINS"; return "MINIMAL_PINS";
case MINI_COOPER_R50: case MINI_COOPER_R50:
@ -785,8 +787,6 @@ case TEST_ISSUE_366_BOTH:
return "TEST_ISSUE_366_BOTH"; return "TEST_ISSUE_366_BOTH";
case TEST_ISSUE_366_RISE: case TEST_ISSUE_366_RISE:
return "TEST_ISSUE_366_RISE"; return "TEST_ISSUE_366_RISE";
case MICRO_RUS_EFI:
return "MICRO_RUS_EFI";
case TLE8888_BENCH_ENGINE: case TLE8888_BENCH_ENGINE:
return "TLE8888_BENCH_ENGINE"; return "TLE8888_BENCH_ENGINE";
case TOYOTA_2JZ_GTE_VVTi: case TOYOTA_2JZ_GTE_VVTi:

View File

@ -1,7 +1,7 @@
// auto-generated from rusefi_hw_enums.h // was generated automatically by rusEfi tool from rusefi_hw_enums.h
// auto-generated from rusefi_enums.h // was generated automatically by rusEfi tool from rusefi_enums.h
// by enum2string.jar tool // by enum2string.jar tool
// on Tue Jun 04 12:17:32 EDT 2019 // on Mon Jun 17 19:49:25 EDT 2019
// see also gen_config_and_enums.bat // see also gen_config_and_enums.bat

View File

@ -2,13 +2,16 @@
rem This batch files reads rusefi_config.txt and produses firmware persistent configuration headers rem This batch files reads rusefi_config.txt and produses firmware persistent configuration headers
rem the storage section of rusefi.ini is updated as well rem the storage section of rusefi.ini is updated as well
rm gen_config.log
rm gen_config_board.log
rem lazy is broken - TS input is not considered a change rem lazy is broken - TS input is not considered a change
rm build/config.gen rm build/config.gen
mkdir build mkdir build
java -Drusefi.generator.lazyfile.enabled=true ^ java -DSystemOut.name=gen_config ^
-Drusefi.generator.lazyfile.enabled=true ^
-jar ../java_tools/ConfigDefinition.jar ^ -jar ../java_tools/ConfigDefinition.jar ^
-definition integration\rusefi_config.txt ^ -definition integration\rusefi_config.txt ^
-romraider integration ^ -romraider integration ^

View File

@ -16,7 +16,8 @@ echo BOARDNAME=%BOARDNAME%
rem lazy is broken - TS input is not considered a change rem lazy is broken - TS input is not considered a change
rm build/config.gen rm build/config.gen
java -cp ../java_tools/ConfigDefinition.jar;../java_tools/configuration_definition/lib/snakeyaml.jar ^ java -DSystemOut.name=gen_config_board ^
-cp ../java_tools/ConfigDefinition.jar;../java_tools/configuration_definition/lib/snakeyaml.jar ^
com.rusefi.board_generator.BoardReader ^ com.rusefi.board_generator.BoardReader ^
-board %BOARDNAME% ^ -board %BOARDNAME% ^
-firmware_path . ^ -firmware_path . ^
@ -25,7 +26,8 @@ java -cp ../java_tools/ConfigDefinition.jar;../java_tools/configuration_definiti
-enumInputFile controllers/algo/rusefi_hw_enums.h -enumInputFile controllers/algo/rusefi_hw_enums.h
java -jar ../java_tools/ConfigDefinition.jar ^ java -DSystemOut.name=gen_config_board ^
-jar ../java_tools/ConfigDefinition.jar ^
-definition integration\rusefi_config.txt ^ -definition integration\rusefi_config.txt ^
-ts_destination tunerstudio ^ -ts_destination tunerstudio ^
-ts_output_name rusefi_%BOARDNAME%.ini ^ -ts_output_name rusefi_%BOARDNAME%.ini ^

View File

@ -1,6 +1,9 @@
rem This batch files reads rusefi_enums.h and produses auto_generated_enums.* files rem This batch files reads rusefi_enums.h and produses auto_generated_enums.* files
java -jar ../java_tools/enum2string.jar ^ rm gen_enum_to_string.log
java -DSystemOut.name=gen_enum_to_string ^
-jar ../java_tools/enum2string.jar ^
-inputPath . ^ -inputPath . ^
-outputPath controllers/algo ^ -outputPath controllers/algo ^
-enumInputFile controllers/algo/rusefi_enums.h ^ -enumInputFile controllers/algo/rusefi_enums.h ^

View File

@ -1,6 +1,6 @@
package com.rusefi.config.generated; package com.rusefi.config.generated;
// this file was generated automatically by ConfigDefinition.jar based on integration\rusefi_config.txt Sun Jun 16 22:17:51 EDT 2019 // this file was generated automatically by rusEfi tool ConfigDefinition.jar based on integration\rusefi_config.txt Mon Jun 17 19:57:03 EDT 2019
import com.rusefi.config.*; import com.rusefi.config.*;

Binary file not shown.

View File

@ -4,12 +4,12 @@ import com.rusefi.output.CHeaderConsumer;
import com.rusefi.output.ConfigurationConsumer; import com.rusefi.output.ConfigurationConsumer;
import com.rusefi.output.JavaFieldsConsumer; import com.rusefi.output.JavaFieldsConsumer;
import com.rusefi.output.TSProjectConsumer; import com.rusefi.output.TSProjectConsumer;
import com.rusefi.util.IoUtils;
import com.rusefi.util.LazyFile; import com.rusefi.util.LazyFile;
import com.rusefi.util.SystemOut;
import java.io.*; import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
@ -23,8 +23,7 @@ import java.util.List;
@SuppressWarnings("StringConcatenationInsideStringBufferAppend") @SuppressWarnings("StringConcatenationInsideStringBufferAppend")
public class ConfigDefinition { public class ConfigDefinition {
public static final String EOL = "\n"; public static final String EOL = "\n";
public static final Charset CHARSET = StandardCharsets.ISO_8859_1; public static final String GENERATED_AUTOMATICALLY_TAG = LazyFile.LAZY_FILE_TAG + "ConfigDefinition.jar based on ";
public static final String GENERATED_AUTOMATICALLY_TAG = "was generated automatically by ConfigDefinition.jar based on ";
public static String MESSAGE; public static String MESSAGE;
private static final String ROM_RAIDER_XML_TEMPLATE = "rusefi_template.xml"; private static final String ROM_RAIDER_XML_TEMPLATE = "rusefi_template.xml";
@ -45,7 +44,7 @@ public class ConfigDefinition {
try { try {
doJob(args); doJob(args);
} catch (Throwable e) { } catch (Throwable e) {
System.out.println(e); SystemOut.println(e);
e.printStackTrace(); e.printStackTrace();
System.exit(-1); System.exit(-1);
} }
@ -53,7 +52,7 @@ public class ConfigDefinition {
private static void doJob(String[] args) throws IOException { private static void doJob(String[] args) throws IOException {
if (args.length < 2) { if (args.length < 2) {
System.out.println("Please specify\r\n" SystemOut.println("Please specify\r\n"
+ KEY_DEFINITION + " x\r\n" + KEY_DEFINITION + " x\r\n"
+ KEY_TS_DESTINATION + " x\r\n" + KEY_TS_DESTINATION + " x\r\n"
+ KEY_C_DESTINATION + " x\r\n" + KEY_C_DESTINATION + " x\r\n"
@ -100,14 +99,14 @@ public class ConfigDefinition {
MESSAGE = GENERATED_AUTOMATICALLY_TAG + definitionInputFile + " " + new Date(); MESSAGE = GENERATED_AUTOMATICALLY_TAG + definitionInputFile + " " + new Date();
System.out.println("Reading from " + definitionInputFile); SystemOut.println("Reading from " + definitionInputFile);
String currentMD5 = getDefinitionMD5(definitionInputFile); String currentMD5 = getDefinitionMD5(definitionInputFile);
if (skipRebuildFile != null) { if (skipRebuildFile != null) {
boolean nothingToDoHere = needToSkipRebuild(skipRebuildFile, currentMD5); boolean nothingToDoHere = needToSkipRebuild(skipRebuildFile, currentMD5);
if (nothingToDoHere) { if (nothingToDoHere) {
System.out.println("Nothing to do here according to " + skipRebuildFile + " hash " + currentMD5); SystemOut.println("Nothing to do here according to " + skipRebuildFile + " hash " + currentMD5);
return; return;
} }
} }
@ -115,7 +114,7 @@ public class ConfigDefinition {
for (String prependFile : prependFiles) for (String prependFile : prependFiles)
readPrependValues(prependFile); readPrependValues(prependFile);
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), CHARSET.name())); BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
ReaderState state = new ReaderState(); ReaderState state = new ReaderState();
List<ConfigurationConsumer> destinations = new ArrayList<>(); List<ConfigurationConsumer> destinations = new ArrayList<>();
@ -145,7 +144,7 @@ public class ConfigDefinition {
processTextTemplate(inputFileName, romRaiderDestination); processTextTemplate(inputFileName, romRaiderDestination);
} }
if (skipRebuildFile != null) { if (skipRebuildFile != null) {
System.out.println("Writing " + currentMD5 + " to " + skipRebuildFile); SystemOut.println("Writing " + currentMD5 + " to " + skipRebuildFile);
PrintWriter writer = new PrintWriter(new FileWriter(skipRebuildFile)); PrintWriter writer = new PrintWriter(new FileWriter(skipRebuildFile));
writer.write(currentMD5); writer.write(currentMD5);
writer.close(); writer.close();
@ -186,8 +185,8 @@ public class ConfigDefinition {
} }
private static void processTextTemplate(String inputFileName, String outputFileName) throws IOException { private static void processTextTemplate(String inputFileName, String outputFileName) throws IOException {
System.out.println("Reading from " + inputFileName); SystemOut.println("Reading from " + inputFileName);
System.out.println("Writing to " + outputFileName); SystemOut.println("Writing to " + outputFileName);
VariableRegistry.INSTANCE.put("generator_message", ConfigDefinition.GENERATED_AUTOMATICALLY_TAG + new Date()); VariableRegistry.INSTANCE.put("generator_message", ConfigDefinition.GENERATED_AUTOMATICALLY_TAG + new Date());

View File

@ -1,9 +1,8 @@
package com.rusefi; package com.rusefi;
import com.rusefi.util.SystemOut;
import com.rusefi.test.ConfigFieldParserTest; import com.rusefi.test.ConfigFieldParserTest;
import java.io.IOException;
import java.io.Writer;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -101,9 +100,9 @@ public class ConfigField {
boolean isIterate = "iterate".equalsIgnoreCase(matcher.group(5)); boolean isIterate = "iterate".equalsIgnoreCase(matcher.group(5));
ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySize, ConfigField field = new ConfigField(state, name, comment, arraySizeAsText, type, arraySize,
tsInfo, isIterate); tsInfo, isIterate);
System.out.println("type " + type); SystemOut.println("type " + type);
System.out.println("name " + name); SystemOut.println("name " + name);
System.out.println("comment " + comment); SystemOut.println("comment " + comment);
return field; return field;
} }

View File

@ -1,6 +1,7 @@
package com.rusefi; package com.rusefi;
import com.rusefi.output.ConfigurationConsumer; import com.rusefi.output.ConfigurationConsumer;
import com.rusefi.util.SystemOut;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -147,14 +148,14 @@ public class ReaderState {
} }
ConfigStructure structure = new ConfigStructure(name, comment, withPrefix); ConfigStructure structure = new ConfigStructure(name, comment, withPrefix);
state.stack.push(structure); state.stack.push(structure);
System.out.println("Starting structure " + structure.getName()); SystemOut.println("Starting structure " + structure.getName());
} }
private static void handleEndStruct(ReaderState state, List<ConfigurationConsumer> consumers) throws IOException { private static void handleEndStruct(ReaderState state, List<ConfigurationConsumer> consumers) throws IOException {
if (state.stack.isEmpty()) if (state.stack.isEmpty())
throw new IllegalStateException("Unexpected end_struct"); throw new IllegalStateException("Unexpected end_struct");
ConfigStructure structure = state.stack.pop(); ConfigStructure structure = state.stack.pop();
System.out.println("Ending structure " + structure.getName()); SystemOut.println("Ending structure " + structure.getName());
structure.addAlignmentFill(state); structure.addAlignmentFill(state);
state.structures.put(structure.getName(), structure); state.structures.put(structure.getName(), structure);

View File

@ -1,5 +1,7 @@
package com.rusefi; package com.rusefi;
import com.rusefi.util.SystemOut;
import java.util.Objects; import java.util.Objects;
/** /**
@ -64,7 +66,7 @@ public class TypesHelper {
return "S08"; return "S08";
if (UINT8_T.equals(type)) if (UINT8_T.equals(type))
return "U08"; return "U08";
System.out.println("No TS type convesion for " + type); SystemOut.println("No TS type conversion for " + type);
return type; return type;
} }

View File

@ -1,6 +1,7 @@
package com.rusefi; package com.rusefi;
import com.rusefi.util.LazyFile; import com.rusefi.util.LazyFile;
import com.rusefi.util.SystemOut;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
@ -51,10 +52,10 @@ public class VariableRegistry extends TreeMap<String, String> {
public void register(String var, String value) { public void register(String var, String value) {
if (containsKey(var)) { if (containsKey(var)) {
System.out.println("Not redefining " + var); SystemOut.println("Not redefining " + var);
return; return;
} }
System.out.println("Registering " + var + " as " + value); SystemOut.println("Registering " + var + " as " + value);
put(var, value); put(var, value);
cAllDefinitions.put(var, "#define " + var + " " + value + EOL); cAllDefinitions.put(var, "#define " + var + " " + value + EOL);
@ -65,11 +66,11 @@ public class VariableRegistry extends TreeMap<String, String> {
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);
System.out.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); javaDefinitions.put(var, "\tpublic static final int " + var + " = " + intValue + ";" + EOL);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
System.out.println("Not an integer: " + value); SystemOut.println("Not an integer: " + value);
if (isQuoted(value) && !var.trim().endsWith(ConfigField.ENUM_SUFFIX)) { if (isQuoted(value) && !var.trim().endsWith(ConfigField.ENUM_SUFFIX)) {
// quoted and not with enum suffix means plain string define statement // quoted and not with enum suffix means plain string define statement
@ -96,7 +97,7 @@ public class VariableRegistry extends TreeMap<String, String> {
} }
public void writeNumericsToFile(String fileName) throws IOException { public void writeNumericsToFile(String fileName) throws IOException {
System.out.println("Writing to " + fileName); SystemOut.println("Writing to " + fileName);
LazyFile cHeader = new LazyFile(fileName); LazyFile cHeader = new LazyFile(fileName);
cHeader.write("//\n// " + ConfigDefinition.GENERATED_AUTOMATICALLY_TAG + ConfigDefinition.definitionInputFile + "\n//\n\n"); cHeader.write("//\n// " + ConfigDefinition.GENERATED_AUTOMATICALLY_TAG + ConfigDefinition.definitionInputFile + "\n//\n\n");

View File

@ -2,6 +2,7 @@ package com.rusefi.board_generator;
import com.rusefi.EnumsReader; import com.rusefi.EnumsReader;
import com.rusefi.enum_reader.Value; import com.rusefi.enum_reader.Value;
import com.rusefi.util.SystemOut;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import java.io.*; import java.io.*;
@ -18,7 +19,7 @@ public class BoardReader {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
if (args.length < 2) { if (args.length < 2) {
System.out.println("Please specify\r\n" SystemOut.println("Please specify\r\n"
+ KEY_BOARD_NAME + " x\r\n" + KEY_BOARD_NAME + " x\r\n"
+ KEY_FIRMWARE_PATH + " x\r\n" + KEY_FIRMWARE_PATH + " x\r\n"
); );
@ -44,7 +45,7 @@ public class BoardReader {
Yaml yaml = new Yaml(); Yaml yaml = new Yaml();
Map<String, Object> data = yaml.load(new FileReader(firmwarePath + "/config/boards/" + boardName + "/mapping.yaml")); Map<String, Object> data = yaml.load(new FileReader(firmwarePath + "/config/boards/" + boardName + "/mapping.yaml"));
System.out.println(data); SystemOut.println(data);
BufferedWriter bw = new BufferedWriter(new FileWriter(outputPath + File.separator + boardName + "_prefix.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter(outputPath + File.separator + boardName + "_prefix.txt"));
@ -65,7 +66,7 @@ public class BoardReader {
Map<String, Value> enumMap = EnumsReader.enums.get(headerEnumName); Map<String, Value> enumMap = EnumsReader.enums.get(headerEnumName);
Objects.requireNonNull(enumMap, "enum for " + headerEnumName); Objects.requireNonNull(enumMap, "enum for " + headerEnumName);
System.out.println(enumMap.size()); SystemOut.println(enumMap.size());
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();

View File

@ -1,5 +1,7 @@
package com.rusefi.ldmp; package com.rusefi.ldmp;
import com.rusefi.util.SystemOut;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
@ -33,12 +35,12 @@ public class LiveDocsMetaParser {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
String fileName = args[0]; String fileName = args[0];
String destinationPath = args[1]; String destinationPath = args[1];
System.out.println(fileName); SystemOut.println(fileName);
if (!new File(fileName).exists()) if (!new File(fileName).exists())
throw new IllegalStateException("Not found " + fileName); throw new IllegalStateException("Not found " + fileName);
String content = readLineByLine(fileName); String content = readLineByLine(fileName);
List<Request> r = parse(content); List<Request> r = parse(content);
System.out.println(r); SystemOut.println(r);
String className = "ThermistorMeta"; String className = "ThermistorMeta";
@ -53,27 +55,27 @@ public class LiveDocsMetaParser {
List<Request> result = new ArrayList<>(); List<Request> result = new ArrayList<>();
string = string.replaceAll("[()>]", " "); string = string.replaceAll("[()>]", " ");
System.out.println(string); SystemOut.println(string);
Scanner s = new Scanner(string); Scanner s = new Scanner(string);
while (s.hasNext()) { while (s.hasNext()) {
String token = s.next(); String token = s.next();
//System.out.println(token); //SystemOut.println(token);
if (DISPLAY_CONFIG.equals(token)) { if (DISPLAY_CONFIG.equals(token)) {
if (s.hasNext()) { if (s.hasNext()) {
String config = s.next(); String config = s.next();
System.out.println("REQ CONF " + config); SystemOut.println("REQ CONF " + config);
result.add(new ConfigRequest(config)); result.add(new ConfigRequest(config));
} }
} else if (DISPLAY_TEXT.equals(token)) { } else if (DISPLAY_TEXT.equals(token)) {
if (s.hasNext()) { if (s.hasNext()) {
String config = s.next(); String config = s.next();
System.out.println("REQ TEXT " + config); SystemOut.println("REQ TEXT " + config);
result.add(new TextRequest(config)); result.add(new TextRequest(config));
} }
} else if (DISPLAY_FIELD.equals(token)) { } else if (DISPLAY_FIELD.equals(token)) {
if (s.hasNext()) { if (s.hasNext()) {
String config = s.next(); String config = s.next();
System.out.println("REQ FIELD " + config); SystemOut.println("REQ FIELD " + config);
result.add(new FieldRequest(config)); result.add(new FieldRequest(config));
} }
} else if (DISPLAY_IF.equals(token)) { } else if (DISPLAY_IF.equals(token)) {
@ -84,7 +86,7 @@ public class LiveDocsMetaParser {
String config = s.next(); String config = s.next();
System.out.println("REQ TEXT " + config); SystemOut.println("REQ TEXT " + config);
IfRequest ifRequest = new IfRequest(variable); IfRequest ifRequest = new IfRequest(variable);
result.add(ifRequest); result.add(ifRequest);
@ -110,7 +112,7 @@ public class LiveDocsMetaParser {
} else if (DISPLAY_SENSOR.equals(token)) { } else if (DISPLAY_SENSOR.equals(token)) {
if (s.hasNext()) { if (s.hasNext()) {
String config = s.next(); String config = s.next();
System.out.println("REQ SENSOR " + config); SystemOut.println("REQ SENSOR " + config);
result.add(new SensorRequest(config)); result.add(new SensorRequest(config));
} }
} }

View File

@ -5,6 +5,7 @@ import com.rusefi.ConfigField;
import com.rusefi.ConfigStructure; import com.rusefi.ConfigStructure;
import com.rusefi.TypesHelper; import com.rusefi.TypesHelper;
import com.rusefi.util.LazyFile; import com.rusefi.util.LazyFile;
import com.rusefi.util.SystemOut;
import java.io.IOException; import java.io.IOException;
@ -18,7 +19,7 @@ public class CHeaderConsumer implements ConfigurationConsumer {
private final LazyFile cHeader; private final LazyFile cHeader;
public CHeaderConsumer(String destCHeader) { public CHeaderConsumer(String destCHeader) {
System.out.println("Writing C header to " + destCHeader); SystemOut.println("Writing C header to " + destCHeader);
cHeader = new LazyFile(destCHeader); cHeader = new LazyFile(destCHeader);
cHeader.write("// this section " + ConfigDefinition.MESSAGE + EOL); cHeader.write("// this section " + ConfigDefinition.MESSAGE + EOL);
cHeader.write("// begin" + EOL); cHeader.write("// begin" + EOL);

View File

@ -2,10 +2,11 @@ package com.rusefi.output;
import com.rusefi.*; import com.rusefi.*;
import com.rusefi.util.LazyFile; import com.rusefi.util.LazyFile;
import com.rusefi.util.SystemOut;
import java.io.*; import java.io.*;
import static com.rusefi.ConfigDefinition.CHARSET; import static com.rusefi.util.IoUtils.CHARSET;
import static com.rusefi.ConfigDefinition.EOL; import static com.rusefi.ConfigDefinition.EOL;
public class TSProjectConsumer implements ConfigurationConsumer { public class TSProjectConsumer implements ConfigurationConsumer {
@ -100,7 +101,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
private void writeTunerStudioFile(String tsPath, String fieldsSection) throws IOException { private void writeTunerStudioFile(String tsPath, String fieldsSection) throws IOException {
TsFileContent tsContent = readTsFile(tsPath); TsFileContent tsContent = readTsFile(tsPath);
System.out.println("Got " + tsContent.getPrefix().length() + "/" + tsContent.getPostfix().length() + " of " + TS_FILE_INPUT_NAME); SystemOut.println("Got " + tsContent.getPrefix().length() + "/" + tsContent.getPostfix().length() + " of " + TS_FILE_INPUT_NAME);
// File.getPath() would eliminate potential separator at the end of the path // File.getPath() would eliminate potential separator at the end of the path
String fileName = new File(tsPath).getPath() + File.separator + TS_FILE_OUTPUT_NAME; String fileName = new File(tsPath).getPath() + File.separator + TS_FILE_OUTPUT_NAME;

Binary file not shown.

View File

@ -1,6 +1,8 @@
package com.rusefi; package com.rusefi;
import com.rusefi.enum_reader.Value; import com.rusefi.enum_reader.Value;
import com.rusefi.util.LazyFile;
import com.rusefi.util.SystemOut;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
@ -30,7 +32,7 @@ public class EnumToString {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
if (args.length < 4) { if (args.length < 4) {
System.out.println("Please specify at least\n\n" + SystemOut.println("Please specify at least\n\n" +
KEY_INPUT_PATH + "XXX\r\n" + KEY_INPUT_PATH + "XXX\r\n" +
// KEY_INPUT_FILE + "XXX" + // KEY_INPUT_FILE + "XXX" +
KEY_OUTPUT + "XXX\r\n" KEY_OUTPUT + "XXX\r\n"
@ -63,7 +65,7 @@ public class EnumToString {
cppFileContent.insert(0, includesSection); cppFileContent.insert(0, includesSection);
headerFileContent.insert(0, includesSection); headerFileContent.insert(0, includesSection);
System.out.println("includesSection:\r\n" + includesSection + "end of includesSection\r\n"); SystemOut.println("includesSection:\r\n" + includesSection + "end of includesSection\r\n");
cppFileContent.insert(0, "#include \"global.h\"\r\n"); cppFileContent.insert(0, "#include \"global.h\"\r\n");
headerFileContent.insert(0, bothFilesHeader.toString()); headerFileContent.insert(0, bothFilesHeader.toString());
@ -75,21 +77,22 @@ public class EnumToString {
} }
private static void writeCppAndHeaderFiles(String outFileName) throws IOException { private static void writeCppAndHeaderFiles(String outFileName) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(outFileName + ".cpp")); LazyFile bw = new LazyFile(outFileName + ".cpp");
bw.write(cppFileContent.toString()); bw.write(cppFileContent.toString());
bw.close(); bw.close();
bw = new BufferedWriter(new FileWriter(outFileName + ".h")); bw = new LazyFile(outFileName + ".h");
bw.write(headerFileContent.toString()); bw.write(headerFileContent.toString());
bw.close(); bw.close();
} }
private static void consumeFile(String inputPath, String inFileName) throws IOException { private static void consumeFile(String inputPath, String inFileName) throws IOException {
File f = new File(inputPath + File.separator + inFileName); File f = new File(inputPath + File.separator + inFileName);
System.out.println("Reading from " + inFileName); SystemOut.println("Reading from " + inFileName);
String simpleFileName = f.getName(); String simpleFileName = f.getName();
bothFilesHeader.insert(0, "// auto-generated from " + simpleFileName + "\r\n"); bothFilesHeader.insert(0, "// " +
LazyFile.LAZY_FILE_TAG + " from " + simpleFileName + "\r\n");
includesSection.append("#include \"" + simpleFileName + "\"\r\n"); includesSection.append("#include \"" + simpleFileName + "\"\r\n");
EnumsReader.process(new FileReader(inFileName)); EnumsReader.process(new FileReader(inFileName));

View File

@ -1,14 +1,13 @@
package com.rusefi; package com.rusefi;
import com.rusefi.enum_reader.Value; import com.rusefi.enum_reader.Value;
import com.rusefi.util.SystemOut;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet;
public class EnumsReader { public class EnumsReader {
private final static Map<String, Value> currentValues = new TreeMap<>(); private final static Map<String, Value> currentValues = new TreeMap<>();
@ -23,13 +22,13 @@ public class EnumsReader {
line = removeSpaces(line); line = removeSpaces(line);
if (line.startsWith("typedefenum{") || line.startsWith("typedefenum__attribute__")) { if (line.startsWith("typedefenum{") || line.startsWith("typedefenum__attribute__")) {
System.out.println("Entering enum"); SystemOut.println("Entering enum");
currentValues.clear(); currentValues.clear();
isInsideEnum = true; isInsideEnum = true;
} else if (line.startsWith("}") && line.endsWith(";")) { } else if (line.startsWith("}") && line.endsWith(";")) {
isInsideEnum = false; isInsideEnum = false;
line = line.substring(1, line.length() - 1); line = line.substring(1, line.length() - 1);
System.out.println("Ending enum " + line); SystemOut.println("Ending enum " + line);
enums.put(line, new TreeMap<>(currentValues)); enums.put(line, new TreeMap<>(currentValues));
} else { } else {
line = line.replaceAll("//.+", ""); line = line.replaceAll("//.+", "");
@ -42,7 +41,7 @@ public class EnumsReader {
value = line.substring(index + 1); value = line.substring(index + 1);
line = line.substring(0, index); line = line.substring(0, index);
} }
System.out.println("Line " + line); SystemOut.println("Line " + line);
currentValues.put(line, new Value(line, value)); currentValues.put(line, new Value(line, value));
} }
} }

View File

@ -0,0 +1,8 @@
package com.rusefi.util;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
public class IoUtils {
public static final Charset CHARSET = StandardCharsets.ISO_8859_1;
}

View File

@ -1,10 +1,6 @@
package com.rusefi.util; package com.rusefi.util;
import com.rusefi.ConfigDefinition;
import java.io.*; import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Scanner; import java.util.Scanner;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -13,11 +9,12 @@ import java.util.regex.Pattern;
* This file would override file content only of content has changed, disregarding the magic tag line. * This file would override file content only of content has changed, disregarding the magic tag line.
*/ */
public class LazyFile { public class LazyFile {
public static final String LAZY_FILE_TAG = "was generated automatically by rusEfi tool ";
private static final String PROPERTY_NAME = "rusefi.generator.lazyfile.enabled"; private static final String PROPERTY_NAME = "rusefi.generator.lazyfile.enabled";
private static boolean ENABLED = Boolean.getBoolean(PROPERTY_NAME); private static boolean ENABLED = Boolean.getBoolean(PROPERTY_NAME);
static { static {
System.out.println(PROPERTY_NAME + "=" + ENABLED); SystemOut.println(PROPERTY_NAME + "=" + ENABLED);
} }
private String filename; private String filename;
@ -31,7 +28,7 @@ public class LazyFile {
public void write(String line) { public void write(String line) {
content.append(line); content.append(line);
if (!line.contains(ConfigDefinition.GENERATED_AUTOMATICALLY_TAG)) if (!line.contains(LAZY_FILE_TAG))
contentWithoutTag.append(line); contentWithoutTag.append(line);
} }
@ -39,20 +36,20 @@ public class LazyFile {
String fileContent = unifySpaces(readCurrentContent(filename)); String fileContent = unifySpaces(readCurrentContent(filename));
String newContent = unifySpaces(contentWithoutTag.toString().trim()); String newContent = unifySpaces(contentWithoutTag.toString().trim());
if (fileContent.equals(newContent)) { if (fileContent.equals(newContent)) {
System.out.println(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content"); SystemOut.println(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content");
return; return;
} }
for (int i = 0; i < Math.min(fileContent.length(), newContent.length()); i++) { for (int i = 0; i < Math.min(fileContent.length(), newContent.length()); i++) {
if (fileContent.charAt(i) != newContent.charAt(i)) { if (fileContent.charAt(i) != newContent.charAt(i)) {
System.out.println(getClass().getSimpleName() + " " + filename + ": Not same at " + i); SystemOut.println(getClass().getSimpleName() + " " + filename + ": Not same at " + i);
if (i > 15 && i < fileContent.length() - 6 && i < newContent.length() - 6) { if (i > 15 && i < fileContent.length() - 6 && i < newContent.length() - 6) {
System.out.println("file " + fileContent.substring(i - 15, i + 5)); SystemOut.println("file " + fileContent.substring(i - 15, i + 5));
System.out.println("newContent " + newContent.substring(i - 15, i + 5)); SystemOut.println("newContent " + newContent.substring(i - 15, i + 5));
} }
break; break;
} }
} }
Writer fw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filename), ConfigDefinition.CHARSET)); Writer fw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filename), IoUtils.CHARSET));
fw.write(content.toString()); fw.write(content.toString());
fw.close(); fw.close();
} }
@ -64,12 +61,12 @@ public class LazyFile {
private String readCurrentContent(String filename) throws IOException { private String readCurrentContent(String filename) throws IOException {
if (!new File(filename).exists()) if (!new File(filename).exists())
return ""; return "";
Scanner in = new Scanner(Paths.get(filename), ConfigDefinition.CHARSET.name()); Scanner in = new Scanner(Paths.get(filename), IoUtils.CHARSET.name());
Pattern pat = Pattern.compile(".*\\R|.+\\z"); Pattern pat = Pattern.compile(".*\\R|.+\\z");
String line; String line;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
while ((line = in.findWithinHorizon(pat, 0)) != null) { while ((line = in.findWithinHorizon(pat, 0)) != null) {
if (!line.contains(ConfigDefinition.GENERATED_AUTOMATICALLY_TAG)) if (!line.contains(LAZY_FILE_TAG))
sb.append(line); sb.append(line);
} }
return sb.toString(); return sb.toString();

View File

@ -0,0 +1,47 @@
package com.rusefi.util;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Utility class which writes same line both to stdout and file
*/
//@ThreadSafe
public class SystemOut {
private static final String LOG = ".log";
private static PrintWriter logFile;
public static void println(String line) {
System.out.println(line);
try {
openFileIfNeeded();
logFile.write(line + "\r\n");
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
private static synchronized void openFileIfNeeded() throws IOException {
if (logFile != null)
return;
String fileName = System.getProperty("SystemOut.name", "rusefi_tool") + LOG;
System.out.println("Opening " + fileName);
logFile = new PrintWriter(new FileWriter(fileName, true));
}
@SuppressWarnings("ThrowablePrintedToSystemOut")
public static void println(Throwable param) {
System.out.println(param);
try {
openFileIfNeeded();
param.printStackTrace(logFile);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public static void println(Object object) {
println(object == null ? "(null)" : object.toString());
}
}