Skip to content

Commit

Permalink
refs #36: Add diagnostic options for missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
overtaker committed Feb 27, 2021
1 parent eef1a86 commit 8345689
Show file tree
Hide file tree
Showing 27 changed files with 380 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<ItemGroup>
<ClInclude Include="..\..\C-Sources\bsxml-json\array.h" />
<ClInclude Include="..\..\C-Sources\ED_locale.h" />
<ClInclude Include="..\..\C-Sources\ED_logging.h" />
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h" />
<ClInclude Include="..\..\C-Sources\inih\ini.h" />
<ClInclude Include="..\..\C-Sources\modelica\ModelicaUtilities.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<ClInclude Include="..\..\C-Sources\inih\ini.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\C-Sources\ED_logging.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ED_INIFile.def">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\C-Sources\ED_locale.h" />
<ClInclude Include="..\..\C-Sources\ED_logging.h" />
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h" />
<ClInclude Include="..\..\C-Sources\modelica\ModelicaUtilities.h" />
<ClInclude Include="..\..\C-Sources\parson\parson.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\C-Sources\ED_logging.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ED_JSONFile.def">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
<ItemGroup>
<ClInclude Include="..\..\C-Sources\bsxml-json\bsxml.h" />
<ClInclude Include="..\..\C-Sources\ED_locale.h" />
<ClInclude Include="..\..\C-Sources\ED_logging.h" />
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h" />
<ClInclude Include="..\..\C-Sources\modelica\ModelicaUtilities.h" />
<ClInclude Include="..\..\Include\ED_SSVFile.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\C-Sources\ED_logging.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ED_SSVFile.def">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\C-Sources\ED_locale.h" />
<ClInclude Include="..\..\C-Sources\ED_logging.h" />
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h" />
<ClInclude Include="..\..\C-Sources\libxls\include\libxls\brdb.c.h" />
<ClInclude Include="..\..\C-Sources\libxls\include\libxls\brdb.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@
<ClInclude Include="..\..\C-Sources\libxls\include\libxls\locale.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\C-Sources\ED_logging.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<ItemGroup>
<ClInclude Include="..\..\C-Sources\bsxml-json\bsxml.h" />
<ClInclude Include="..\..\C-Sources\ED_locale.h" />
<ClInclude Include="..\..\C-Sources\ED_logging.h" />
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h" />
<ClInclude Include="..\..\C-Sources\minizip\ioapi.h" />
<ClInclude Include="..\..\C-Sources\minizip\iowin32.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\C-Sources\ED_logging.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
<ItemGroup>
<ClInclude Include="..\..\C-Sources\bsxml-json\bsxml.h" />
<ClInclude Include="..\..\C-Sources\ED_locale.h" />
<ClInclude Include="..\..\C-Sources\ED_logging.h" />
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h" />
<ClInclude Include="..\..\C-Sources\modelica\ModelicaUtilities.h" />
<ClInclude Include="..\..\Include\ED_XMLFile.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<ClInclude Include="..\..\C-Sources\ED_ptrtrack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\C-Sources\ED_logging.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ED_XMLFile.def">
Expand Down
116 changes: 90 additions & 26 deletions ExternData/Resources/C-Sources/ED_INIFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define strdup _strdup
#endif
#include "ED_locale.h"
#include "ED_logging.h"
#include "ED_ptrtrack.h"
#include "array.h"
#include "ini.h"
Expand All @@ -52,6 +53,7 @@ typedef struct {
typedef struct {
char* fileName;
ED_LOCALE_TYPE loc;
ED_LOGGING_FUNC log;
cpo_array_t* sections;
} INIFile;

Expand Down Expand Up @@ -99,7 +101,7 @@ static int fillValues(void* userdata, const char* section, const char* key, cons
return 0;
}

void* ED_createINI(const char* fileName, int verbose)
void* ED_createINI(const char* fileName, int verbose, int detectMissingData)
{
int line;
INIFile* ini = (INIFile*)malloc(sizeof(INIFile));
Expand Down Expand Up @@ -130,6 +132,20 @@ void* ED_createINI(const char* fileName, int verbose)
return NULL;
}
ini->loc = ED_INIT_LOCALE;
switch (detectMissingData) {
case ED_LOG_NONE:
ini->log = ED_LogNone;
break;
case ED_LOG_DEBUG:
ini->log = ED_LogDebug;
break;
case ED_LOG_ERROR:
ini->log = ED_LogError;
break;
default:
ini->log = ED_LogWarning;
break;
}
ED_PTR_ADD(ini);
return ini;
}
Expand Down Expand Up @@ -178,29 +194,47 @@ double ED_getDoubleFromINI(void* _ini, const char* varName, const char* section,
if (pair != NULL) {
if (NULL != pair->value) {
if (ED_strtod(pair->value, ini->loc, &ret, strict)) {
ModelicaFormatError("Cannot read double value \"%s\" from file \"%s\"\n",
pair->value, ini->fileName);
if (section[0] != '\0') {
ModelicaFormatError("Cannot read double value \"%s\" of section \"%s\" "
"from file \"%s\"\n", pair->value, section, ini->fileName);
}
else {
ModelicaFormatError("Cannot read double value \"%s\" of default section "
"from file \"%s\"\n", pair->value, ini->fileName);
}
}
}
else {
ModelicaFormatError("Cannot read value for key \"%s\" from file \"%s\"\n",
varName, ini->fileName);
if (section[0] != '\0') {
ini->log("Cannot read value for key \"%s\" of section \"%s\" from file \"%s\"\n",
varName, section, ini->fileName);
}
else {
ini->log("Cannot read value for key \"%s\" of default section from file \"%s\"\n",
varName, ini->fileName);
}
*exist = 0;
}
}
else {
ModelicaFormatMessage("Cannot read key \"%s\" from file \"%s\"\n",
varName, ini->fileName);
if (section[0] != '\0') {
ini->log("Cannot read key \"%s\" of section \"%s\" from file \"%s\"\n",
varName, section, ini->fileName);
}
else {
ini->log("Cannot read key \"%s\" of default section from file \"%s\"\n",
varName, ini->fileName);
}
*exist = 0;
}
}
else {
if (strlen(section) > 0) {
ModelicaFormatMessage("Cannot read section \"%s\" from file \"%s\"\n",
if (section[0] != '\0') {
ini->log("Cannot read section \"%s\" from file \"%s\"\n",
section, ini->fileName);
}
else {
ModelicaFormatMessage("Cannot read empty section from file \"%s\"\n",
ini->log("Cannot read default section from file \"%s\"\n",
ini->fileName);
}
*exist = 0;
Expand Down Expand Up @@ -228,24 +262,36 @@ const char* ED_getStringFromINI(void* _ini, const char* varName, const char* sec
return (const char*)ret;
}
else {
ModelicaFormatError("Cannot read value for key \"%s\" from file \"%s\"\n",
varName, ini->fileName);
if (section[0] != '\0') {
ini->log("Cannot read value for key \"%s\" of section \"%s\" from file \"%s\"\n",
varName, section, ini->fileName);
}
else {
ini->log("Cannot read value for key \"%s\" of default section from file \"%s\"\n",
varName, ini->fileName);
}
*exist = 0;
}
}
else {
ModelicaFormatMessage("Cannot read key \"%s\" from file \"%s\"\n",
varName, ini->fileName);
if (section[0] != '\0') {
ini->log("Cannot read key \"%s\" of section \"%s\" from file \"%s\"\n",
varName, section, ini->fileName);
}
else {
ini->log("Cannot read key \"%s\" of default section from file \"%s\"\n",
varName, ini->fileName);
}
*exist = 0;
}
}
else {
if (strlen(section) > 0) {
ModelicaFormatMessage("Cannot read section \"%s\" from file \"%s\"\n",
if (section[0] != '\0') {
ini->log("Cannot read section \"%s\" from file \"%s\"\n",
section, ini->fileName);
}
else {
ModelicaFormatMessage("Cannot read empty section from file \"%s\"\n",
ini->log("Cannot read default section from file \"%s\"\n",
ini->fileName);
}
*exist = 0;
Expand All @@ -270,29 +316,47 @@ int ED_getIntFromINI(void* _ini, const char* varName, const char* section, int s
if (pair != NULL) {
if (NULL != pair->value) {
if (ED_strtol(pair->value, ini->loc, &ret, strict)) {
ModelicaFormatError("Cannot read int value \"%s\" from file \"%s\"\n",
pair->value, ini->fileName);
if (section[0] != '\0') {
ModelicaFormatError("Cannot read int value \"%s\" of section \"%s\" "
"from file \"%s\"\n", pair->value, section, ini->fileName);
}
else {
ModelicaFormatError("Cannot read int value \"%s\" of default section "
"from file \"%s\"\n", pair->value, ini->fileName);
}
}
}
else {
ModelicaFormatError("Cannot read value for key \"%s\" from file \"%s\"\n",
varName, ini->fileName);
if (section[0] != '\0') {
ini->log("Cannot read value for key \"%s\" of section \"%s\" from file \"%s\"\n",
varName, section, ini->fileName);
}
else {
ini->log("Cannot read value for key \"%s\" of default section from file \"%s\"\n",
varName, ini->fileName);
}
*exist = 0;
}
}
else {
ModelicaFormatMessage("Cannot read key \"%s\" from file \"%s\"\n",
varName, ini->fileName);
if (section[0] != '\0') {
ini->log("Cannot read key \"%s\" of section \"%s\" from file \"%s\"\n",
varName, section, ini->fileName);
}
else {
ini->log("Cannot read key \"%s\" of default section from file \"%s\"\n",
varName, ini->fileName);
}
*exist = 0;
}
}
else {
if (strlen(section) > 0) {
ModelicaFormatMessage("Cannot read section \"%s\" from file \"%s\"\n",
if (section[0] != '\0') {
ini->log("Cannot read section \"%s\" from file \"%s\"\n",
section, ini->fileName);
}
else {
ModelicaFormatMessage("Cannot read empty section from file \"%s\"\n",
ini->log("Cannot read default section from file \"%s\"\n",
ini->fileName);
}
*exist = 0;
Expand Down
26 changes: 21 additions & 5 deletions ExternData/Resources/C-Sources/ED_JSONFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define strdup _strdup
#endif
#include "ED_locale.h"
#include "ED_logging.h"
#include "ED_ptrtrack.h"
#include "parson.h"
#include "ModelicaUtilities.h"
Expand All @@ -48,9 +49,10 @@ typedef struct {
JSON_Value* rootValue;
JSON_Object* root;
ED_LOCALE_TYPE loc;
ED_LOGGING_FUNC log;
} JSONFile;

void* ED_createJSON(const char* fileName, int verbose)
void* ED_createJSON(const char* fileName, int verbose, int detectMissingData)
{
JSONFile* json = (JSONFile*)malloc(sizeof(JSONFile));
if (json == NULL) {
Expand Down Expand Up @@ -82,6 +84,20 @@ void* ED_createJSON(const char* fileName, int verbose)
/* ModelicaFormatMessage("Loaded JSON data:\n%s\n", json_serialize_to_string(rootValue)); */

json->loc = ED_INIT_LOCALE;
switch (detectMissingData) {
case ED_LOG_NONE:
json->log = ED_LogNone;
break;
case ED_LOG_DEBUG:
json->log = ED_LogDebug;
break;
case ED_LOG_ERROR:
json->log = ED_LogError;
break;
default:
json->log = ED_LogWarning;
break;
}
ED_PTR_ADD(json);
return json;
}
Expand Down Expand Up @@ -133,7 +149,7 @@ double ED_getDoubleFromJSON(void* _json, const char* varName, int* exist)
}
}
else {
ModelicaFormatMessage("Cannot find numeric value \"%s\" in file \"%s\"\n",
json->log("Cannot find numeric value \"%s\" in file \"%s\"\n",
varName, json->fileName);
*exist = 0;
}
Expand Down Expand Up @@ -162,7 +178,7 @@ const char* ED_getStringFromJSON(void* _json, const char* varName, int* exist)
}
}
else {
ModelicaFormatMessage("Cannot find string value \"%s\" in file \"%s\"\n",
json->log("Cannot find string value \"%s\" in file \"%s\"\n",
varName, json->fileName);
*exist = 0;
}
Expand Down Expand Up @@ -204,7 +220,7 @@ int ED_getIntFromJSON(void* _json, const char* varName, int* exist)
}
}
else {
ModelicaFormatMessage("Cannot find numeric value \"%s\" in file \"%s\"\n",
json->log("Cannot find numeric value \"%s\" in file \"%s\"\n",
varName, json->fileName);
*exist = 0;
}
Expand Down Expand Up @@ -244,7 +260,7 @@ int ED_getBooleanFromJSON(void* _json, const char* varName, int* exist)
}
}
else {
ModelicaFormatMessage("Cannot find boolean value \"%s\" in file \"%s\"\n",
json->log("Cannot find boolean value \"%s\" in file \"%s\"\n",
varName, json->fileName);
*exist = 0;
}
Expand Down
Loading

0 comments on commit 8345689

Please sign in to comment.