aqhome-react: finish new network reading code, improved debugging helper code.

This commit is contained in:
Martin Preuss
2024-04-18 22:40:13 +02:00
parent 2443fbca9f
commit e486a7e69d
11 changed files with 103 additions and 92 deletions

View File

@@ -21,6 +21,7 @@
#include <gwenhywfar/text.h>
#include <gwenhywfar/debug.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -91,29 +92,38 @@ int AQHomeReact_ReadUnitNetFiles(AQHOME_REACT *aqh)
AQHREACT_UNIT *AQHomeReact_FindAndReadDataDirNetwork(AQHOME_REACT *aqh, const char *networkName)
{
AQHREACT_UNIT *unit;
GWEN_BUFFER *bufFilename;
GWEN_BUFFER *bufPath;
if (aqh && networkName) {
AQHREACT_UNIT *unit;
GWEN_BUFFER *bufFilename;
GWEN_BUFFER *bufPath;
const char *s;
bufFilename=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendArgs(bufFilename, "aqhome/react/networks/%s.xml", networkName);
bufPath=AQH_FindPathOfDataFile(GWEN_Buffer_GetStart(bufFilename));
if (bufPath==NULL) {
DBG_ERROR(NULL, "Network file \"%s\" not found in data folders", GWEN_Buffer_GetStart(bufFilename));
bufFilename=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendString(bufFilename, "aqhome/react/networks/");
s=networkName;
while(*s)
GWEN_Buffer_AppendByte(bufFilename, tolower((unsigned char) *(s++)));
GWEN_Buffer_AppendString(bufFilename, ".xml");
bufPath=AQH_FindPathOfDataFile(GWEN_Buffer_GetStart(bufFilename));
if (bufPath==NULL) {
DBG_ERROR(NULL, "Network file \"%s\" not found in data folders", GWEN_Buffer_GetStart(bufFilename));
GWEN_Buffer_free(bufFilename);
return NULL;
}
GWEN_Buffer_free(bufFilename);
return NULL;
}
GWEN_Buffer_free(bufFilename);
unit=_readNetworkFromFile(aqh, GWEN_Buffer_GetStart(bufPath));
if (unit==NULL) {
DBG_ERROR(NULL, "Error reading network from file \"%s\"", GWEN_Buffer_GetStart(bufPath));
unit=_readNetworkFromFile(aqh, GWEN_Buffer_GetStart(bufPath));
if (unit==NULL) {
DBG_ERROR(NULL, "Error reading network from file \"%s\"", GWEN_Buffer_GetStart(bufPath));
GWEN_Buffer_free(bufPath);
return NULL;
}
GWEN_Buffer_free(bufPath);
return NULL;
return unit;
}
GWEN_Buffer_free(bufPath);
return unit;
return NULL;
}