Browse Source

Improve TTL output formatting.

scossu 4 weeks ago
parent
commit
7503b5d4b8
1 changed files with 7 additions and 5 deletions
  1. 7 5
      src/codec/codec_ttl.c

+ 7 - 5
src/codec/codec_ttl.c

@@ -231,7 +231,9 @@ gr_to_ttl_iter (void *h, char **res_p) {
 
 
     VOLK_Term *s = NULL;
     VOLK_Term *s = NULL;
     char *res = *res_p;  // Result string will be reallocated.
     char *res = *res_p;  // Result string will be reallocated.
-    RCCK (VOLK_term_set_next (it->subjects, &it->s_cur, &s));
+    VOLK_rc rc = VOLK_term_set_next (it->subjects, &it->s_cur, &s);
+    if (rc == VOLK_END) return rc;  // Return without logging error.
+    RCCK (rc);  // Log error or warning for anything else.
 
 
     term_to_ttl (s, &res);
     term_to_ttl (s, &res);
 
 
@@ -241,7 +243,7 @@ gr_to_ttl_iter (void *h, char **res_p) {
     VOLK_LinkMapIterator *lmit = VOLK_link_map_iter_new (lmap);
     VOLK_LinkMapIterator *lmit = VOLK_link_map_iter_new (lmap);
     VOLK_Term *p = NULL;
     VOLK_Term *p = NULL;
     VOLK_TermSet *o_ts = NULL;
     VOLK_TermSet *o_ts = NULL;
-    char *p_join = " ";
+    char *p_join = "\n    ";  // Newline & indent after subject.
     // Begin predicate loop.
     // Begin predicate loop.
     while (VOLK_link_map_next (lmit, &p, &o_ts) != VOLK_END) {
     while (VOLK_link_map_next (lmit, &p, &o_ts) != VOLK_END) {
         // Add predicate representation.
         // Add predicate representation.
@@ -251,7 +253,7 @@ gr_to_ttl_iter (void *h, char **res_p) {
         if (UNLIKELY (!tmp)) goto memfail;
         if (UNLIKELY (!tmp)) goto memfail;
         res = strcat (strcat (tmp, p_join), it->p_str);
         res = strcat (strcat (tmp, p_join), it->p_str);
 
 
-        p_join = " ; ";
+        p_join = " ;\n    ";
 
 
         // Add objects for predicate.
         // Add objects for predicate.
         size_t i = 0;
         size_t i = 0;
@@ -264,11 +266,11 @@ gr_to_ttl_iter (void *h, char **res_p) {
                     res, strlen (res) + strlen (it->o_str) + strlen (o_join) + 1);
                     res, strlen (res) + strlen (it->o_str) + strlen (o_join) + 1);
             if (UNLIKELY (!tmp)) goto memfail;
             if (UNLIKELY (!tmp)) goto memfail;
             res = strcat (strcat (tmp, o_join), it->o_str);
             res = strcat (strcat (tmp, o_join), it->o_str);
-            o_join = " , ";
+            o_join = " ,\n        ";  // Double indent for objects.
         }
         }
     }
     }
 
 
-    char *s_sep = " .\n";
+    char *s_sep = "\n.\n\n";  // Period goes on its own line for visibility.
     char *tmp = realloc (res, strlen (res) + strlen (s_sep) + 1);
     char *tmp = realloc (res, strlen (res) + strlen (s_sep) + 1);
     if (UNLIKELY (!tmp)) goto memfail;
     if (UNLIKELY (!tmp)) goto memfail;