mbeckerle commented on a change in pull request #545:
URL: https://github.com/apache/daffodil/pull/545#discussion_r624218996



##########
File path: 
daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libruntime/errors.c
##########
@@ -17,34 +17,109 @@
 
 #include "errors.h"
 #include <assert.h>    // for assert
-#include <error.h>     // for error
 #include <inttypes.h>  // for PRId64
 #include <stdbool.h>   // for bool, false, true
-#include <stdio.h>     // for NULL, feof, ferror, FILE, size_t
-#include <stdlib.h>    // for EXIT_FAILURE
+#include <stdio.h>     // for fprintf, stderr, NULL, feof, ferror, FILE, 
size_t, stdout
+#include <stdlib.h>    // for exit, EXIT_FAILURE
 
-// error_message - return an internationalized error message
+// eof_or_error - get pointer to error if stream has eof or error indicator set
+
+const Error *
+eof_or_error(FILE *stream)
+{
+    if (feof(stream))
+    {
+        static Error error = {ERR_STREAM_EOF, {NULL}};
+        return &error;
+    }
+    else if (ferror(stream))
+    {
+        static Error error = {ERR_STREAM_ERROR, {NULL}};
+        return &error;
+    }
+    else
+    {
+        return NULL;
+    }
+}
+
+// get_diagnostics - get pointer to validation diagnostics
+
+Diagnostics *
+get_diagnostics(void)
+{
+    static Diagnostics diagnostics;
+    return &diagnostics;
+}
+
+// add_diagnostic - add a new error to validation diagnostics
+
+bool
+add_diagnostic(Diagnostics *diagnostics, const Error *error)
+{
+    if (diagnostics && error)
+    {
+        if (diagnostics->length < LIMIT_DIAGNOSTICS)
+        {
+            Error *err = &diagnostics->array[diagnostics->length++];
+            err->code = error->code;
+            err->s = error->s;
+            return true;
+        }
+    }
+    return false;
+}
+
+// error_message - get an internationalized error message
 
 static const char *
 error_message(enum ErrorCode code)

Review comment:
       That makes sense to me yes. We don't have to do this for this change 
set. We can do it subsequently if you prefer. But we definitely want libruntime 
to be usable from an application which has nothing whatsoever to do with CLIs 
nor XML,  and has its own error architecture used to create error messages from 
the error-codes coming back from the libruntime. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to