The example shows how to iterate over symbolic atoms.
#include <stdlib.h>
#include <stdio.h>
typedef struct string_buffer {
char *string;
size_t string_n;
} string_buffer_t;
void free_string_buffer(string_buffer_t *buf) {
if (buf->string) {
free(buf->string);
buf->string = NULL;
buf->string_n = 0;
}
}
bool ret = true;
char *string;
size_t n;
if (buf->string_n < n) {
if (!(string = (char*)realloc(buf->string, sizeof(*buf->string) * n))) {
goto error;
}
buf->string = string;
buf->string_n = n;
}
printf("%s", buf->string);
goto out;
error:
ret = false;
out:
return ret;
}
int main(int argc, char const **argv) {
char const *error_message;
string_buffer_t buf = {NULL, 0};
int ret = 0;
printf("Symbolic atoms:\n");
for (;;) {
bool equal, fact, external;
if (equal) { break; }
printf(" ");
if (!print_symbol(symbol, &buf)) { goto error; }
if (fact) { printf(", fact"); }
if (external) { printf(", external"); }
printf("\n");
}
goto out;
error:
printf("%s\n", error_message);
out:
free_string_buffer(&buf);
return ret;
}