added conditional messages to find command with "-a" option and include condition prefix for CSV format
also allow passing scan messages with --checkconfig and --scanconfig (without --inject) be more verbose on errors in configuration files improved code style
This commit is contained in:
@@ -39,7 +39,7 @@ void contrib_tem_register() {
|
||||
DataTypeList::getInstance()->add(new TemParamDataType("TEM_P"));
|
||||
}
|
||||
|
||||
result_t TemParamDataType::derive(int divisor, size_t bitCount, const NumberDataType* &derived) const {
|
||||
result_t TemParamDataType::derive(int divisor, size_t bitCount, const NumberDataType** derived) const {
|
||||
if (divisor == 0) {
|
||||
divisor = 1;
|
||||
}
|
||||
@@ -47,27 +47,26 @@ result_t TemParamDataType::derive(int divisor, size_t bitCount, const NumberData
|
||||
bitCount = m_bitCount;
|
||||
}
|
||||
if (divisor == 1 && bitCount == 16) {
|
||||
derived = this;
|
||||
*derived = this;
|
||||
return RESULT_OK;
|
||||
}
|
||||
return RESULT_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
result_t TemParamDataType::readSymbols(const SymbolString& input,
|
||||
const size_t offset, const size_t length,
|
||||
ostringstream& output, OutputFormat outputFormat) const {
|
||||
result_t TemParamDataType::readSymbols(size_t offset, size_t length, const SymbolString& input,
|
||||
OutputFormat outputFormat, ostream* output) const {
|
||||
unsigned int value = 0;
|
||||
|
||||
result_t result = readRawValue(input, offset, length, value);
|
||||
result_t result = readRawValue(offset, length, input, &value);
|
||||
if (result != RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (value == m_replacement) {
|
||||
if (outputFormat & OF_JSON) {
|
||||
output << "null";
|
||||
*output << "null";
|
||||
} else {
|
||||
output << NULL_VALUE;
|
||||
*output << NULL_VALUE;
|
||||
}
|
||||
return RESULT_OK;
|
||||
}
|
||||
@@ -80,31 +79,29 @@ result_t TemParamDataType::readSymbols(const SymbolString& input,
|
||||
num = (value & 0x7f); // num in bits 0...6
|
||||
}
|
||||
if (outputFormat & OF_JSON) {
|
||||
output << '"';
|
||||
*output << '"';
|
||||
}
|
||||
output << setfill('0') << setw(2) << dec << static_cast<int>(grp) << '-' << setw(3) << static_cast<int>(num);
|
||||
*output << setfill('0') << setw(2) << dec << static_cast<int>(grp) << '-' << setw(3) << static_cast<int>(num);
|
||||
if (outputFormat & OF_JSON) {
|
||||
output << '"';
|
||||
*output << '"';
|
||||
}
|
||||
output << setfill(' ') << setw(0); // reset
|
||||
*output << setfill(' ') << setw(0); // reset
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
result_t TemParamDataType::writeSymbols(istringstream& input,
|
||||
const size_t offset, const size_t length,
|
||||
SymbolString& output, size_t* usedLength) const {
|
||||
result_t TemParamDataType::writeSymbols(const size_t offset, const size_t length, istringstream* input,
|
||||
SymbolString* output, size_t* usedLength) const {
|
||||
unsigned int value;
|
||||
int grp, num;
|
||||
string token;
|
||||
|
||||
const char* str = input.str().c_str();
|
||||
if (strcmp(str, NULL_VALUE) == 0) {
|
||||
if (input->str() == NULL_VALUE) {
|
||||
value = m_replacement; // replacement value
|
||||
} else {
|
||||
if (input.eof() || !getline(input, token, '-')) {
|
||||
string token;
|
||||
if (input->eof() || !getline(*input, token, '-')) {
|
||||
return RESULT_ERR_EOF; // incomplete
|
||||
}
|
||||
str = token.c_str();
|
||||
const char* str = token.c_str();
|
||||
if (str == NULL || *str == 0) {
|
||||
return RESULT_ERR_EOF; // input too short
|
||||
}
|
||||
@@ -113,7 +110,7 @@ result_t TemParamDataType::writeSymbols(istringstream& input,
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
if (input.eof() || !getline(input, token, '-')) {
|
||||
if (input->eof() || !getline(*input, token, '-')) {
|
||||
return RESULT_ERR_EOF; // incomplete
|
||||
}
|
||||
str = token.c_str();
|
||||
@@ -128,7 +125,7 @@ result_t TemParamDataType::writeSymbols(istringstream& input,
|
||||
if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) {
|
||||
return RESULT_ERR_OUT_OF_RANGE; // value out of range
|
||||
}
|
||||
if (output.isMaster()) {
|
||||
if (output->isMaster()) {
|
||||
value = grp | (num << 8); // grp in bits 0...5, num in bits 8...13
|
||||
} else {
|
||||
value = (grp << 7) | num; // grp in bits 7...11, num in bits 0...6
|
||||
|
||||
@@ -46,21 +46,19 @@ class TemParamDataType : public NumberDataType {
|
||||
* Constructs a new instance.
|
||||
* @param id the type identifier.
|
||||
*/
|
||||
explicit TemParamDataType(const string id)
|
||||
explicit TemParamDataType(const string& id)
|
||||
: NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0, NULL) {}
|
||||
|
||||
// @copydoc
|
||||
result_t derive(int divisor, size_t bitCount, const NumberDataType* &derived) const override;
|
||||
result_t derive(int divisor, size_t bitCount, const NumberDataType** derived) const override;
|
||||
|
||||
// @copydoc
|
||||
result_t readSymbols(const SymbolString& input,
|
||||
const size_t offset, const size_t length,
|
||||
ostringstream& output, OutputFormat outputFormat) const override;
|
||||
result_t readSymbols(size_t offset, size_t length, const SymbolString& input,
|
||||
const OutputFormat outputFormat, ostream* output) const override;
|
||||
|
||||
// @copydoc
|
||||
result_t writeSymbols(istringstream& input,
|
||||
const size_t offset, const size_t length,
|
||||
SymbolString& output, size_t* usedLength) const override;
|
||||
result_t writeSymbols(size_t offset, size_t length, istringstream* input,
|
||||
SymbolString* output, size_t* usedLength) const override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,31 +54,31 @@ class TestReader : public MappedFileReader {
|
||||
TestReader(DataFieldTemplates* templates, bool isSet, bool isMasterDest)
|
||||
: MappedFileReader::MappedFileReader(true), m_templates(templates), m_isSet(isSet), m_isMasterDest(isMasterDest),
|
||||
m_fields(NULL) {}
|
||||
result_t getFieldMap(vector<string>& row, string& errorDescription, const string preferLanguage) const override {
|
||||
if (row.empty()) {
|
||||
row.push_back("*name");
|
||||
row.push_back("part");
|
||||
row.push_back("type");
|
||||
row.push_back("divisor/values");
|
||||
row.push_back("unit");
|
||||
row.push_back("comment");
|
||||
result_t getFieldMap(const string& preferLanguage, vector<string>* row, string* errorDescription) const override {
|
||||
if (row->empty()) {
|
||||
row->push_back("*name");
|
||||
row->push_back("part");
|
||||
row->push_back("type");
|
||||
row->push_back("divisor/values");
|
||||
row->push_back("unit");
|
||||
row->push_back("comment");
|
||||
return RESULT_OK;
|
||||
}
|
||||
if (row[0][0] != '*') {
|
||||
if ((*row)[0][0] != '*') {
|
||||
return RESULT_ERR_INVALID_ARG;
|
||||
}
|
||||
return RESULT_OK; // leave it to DataField::create
|
||||
}
|
||||
result_t addFromFile(map<string, string>& row, vector< map<string, string> >& subRows,
|
||||
string& errorDescription, const string filename, unsigned int lineNo) override {
|
||||
if (!row.empty() || subRows.empty()) {
|
||||
result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
|
||||
vector< map<string, string> >* subRows, string* errorDescription) override {
|
||||
if (!row->empty() || subRows->empty()) {
|
||||
cout << "read line " << static_cast<unsigned>(lineNo) << ": read error: got "
|
||||
<< static_cast<unsigned>(row.size()) << "/0 main, " << static_cast<unsigned>(subRows.size())
|
||||
<< static_cast<unsigned>(row->size()) << "/0 main, " << static_cast<unsigned>(subRows->size())
|
||||
<< "/>=3 sub" << endl;
|
||||
return RESULT_ERR_EOF;
|
||||
}
|
||||
cout << "read line " << static_cast<unsigned>(lineNo) << ": read OK" << endl;
|
||||
return DataField::create(subRows, errorDescription, m_templates, m_fields, m_isSet, false, m_isMasterDest);
|
||||
return DataField::create(m_isSet, false, m_isMasterDest, MAX_POS, m_templates, subRows, errorDescription, &m_fields);
|
||||
}
|
||||
private:
|
||||
DataFieldTemplates* m_templates;
|
||||
@@ -118,7 +118,7 @@ int main() {
|
||||
istringstream dummystr("#");
|
||||
string errorDescription;
|
||||
vector<string> row;
|
||||
templates->readLineFromStream(dummystr, errorDescription, "inline", lineNo, row);
|
||||
templates->readLineFromStream("inline", false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
const DataField* fields = NULL;
|
||||
for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
|
||||
string check[5] = checks[i];
|
||||
@@ -156,7 +156,7 @@ int main() {
|
||||
lineNo = 0;
|
||||
dummystr.clear();
|
||||
dummystr.str("#");
|
||||
result = reader.readLineFromStream(dummystr, errorDescription, "inline", lineNo, row);
|
||||
result = reader.readLineFromStream("inline", false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": reader header error: " << getResultCode(result) << ", " << errorDescription
|
||||
<< endl;
|
||||
@@ -164,7 +164,7 @@ int main() {
|
||||
continue;
|
||||
}
|
||||
lineNo = baseLine + i;
|
||||
result = reader.readLineFromStream(isstr, errorDescription, "", lineNo, row);
|
||||
result = reader.readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
fields = reader.m_fields;
|
||||
|
||||
if (result != RESULT_OK) {
|
||||
@@ -178,7 +178,7 @@ int main() {
|
||||
continue;
|
||||
}
|
||||
cout << "\"" << check[0] << "\"=\"";
|
||||
fields->dump(cout);
|
||||
fields->dump(&cout);
|
||||
cout << "\": create OK" << endl;
|
||||
|
||||
ostringstream output;
|
||||
@@ -194,21 +194,21 @@ int main() {
|
||||
cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
}
|
||||
result = fields->read(mstr, 0, output, 0, -1, false);
|
||||
result = fields->read(mstr, 0, false, NULL, -1, 0, -1, &output);
|
||||
if (result >= RESULT_OK) {
|
||||
result = fields->read(sstr, 0, output, 0, -1, !output.str().empty());
|
||||
result = fields->read(sstr, 0, !output.str().empty(), NULL, -1, 0, -1, &output);
|
||||
}
|
||||
if (failedRead) {
|
||||
if (result >= RESULT_OK) {
|
||||
cout << " failed read " << fields->getName() << " >" << check[2] << " " << check[3]
|
||||
cout << " failed read " << fields->getName(-1) << " >" << check[2] << " " << check[3]
|
||||
<< "< error: unexpectedly succeeded" << endl;
|
||||
error = true;
|
||||
} else {
|
||||
cout << " failed read " << fields->getName() << " >" << check[2] << " " << check[3]
|
||||
cout << " failed read " << fields->getName(-1) << " >" << check[2] << " " << check[3]
|
||||
<< "< OK" << endl;
|
||||
}
|
||||
} else if (result < RESULT_OK) {
|
||||
cout << " read " << fields->getName() << " >" << check[2] << " " << check[3]
|
||||
cout << " read " << fields->getName(-1) << " >" << check[2] << " " << check[3]
|
||||
<< "< error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
} else {
|
||||
@@ -217,21 +217,21 @@ int main() {
|
||||
}
|
||||
|
||||
istringstream input(expectStr);
|
||||
result = fields->write(input, writeMstr, 0);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeMstr, NULL);
|
||||
if (result >= RESULT_OK) {
|
||||
result = fields->write(input, writeSstr, 0);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeSstr, NULL);
|
||||
}
|
||||
if (failedWrite) {
|
||||
if (result >= RESULT_OK) {
|
||||
cout << " failed write " << fields->getName() << " >"
|
||||
cout << " failed write " << fields->getName(-1) << " >"
|
||||
<< expectStr << "< error: unexpectedly succeeded" << endl;
|
||||
error = true;
|
||||
} else {
|
||||
cout << " failed write " << fields->getName() << " >"
|
||||
cout << " failed write " << fields->getName(-1) << " >"
|
||||
<< expectStr << "< OK" << endl;
|
||||
}
|
||||
} else if (result < RESULT_OK) {
|
||||
cout << " write " << fields->getName() << " >" << expectStr
|
||||
cout << " write " << fields->getName(-1) << " >" << expectStr
|
||||
<< "< error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user