The example shows how to used the backend to extend a grounded program.
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
bool ret = true;
size_t atoms_n;
char *str = NULL;
size_t str_n = 0;
goto error;
}
printf("Model:");
for (it = atoms, ie = atoms + atoms_n; it != ie; ++it) {
size_t n;
char *str_new;
if (str_n < n) {
if (!(str_new = (char*)realloc(str, sizeof(*str) * n))) {
goto error;
}
str = str_new;
str_n = n;
}
printf(" %s", str);
}
printf("\n");
goto out;
error:
ret = false;
out:
if (atoms) { free(atoms); }
if (str) { free(str); }
return ret;
}
bool ret = true;
while (true) {
if (model) { print_model(model); }
else { break; }
}
goto out;
error:
ret = false;
out:
}
int main(int argc, char const **argv) {
char const *error_message;
int ret = 0;
size_t offset;
char const *atom_strings[] = {"a", "b", "c"};
offset = 0;
for (char const **it = atom_strings, **ie = it + sizeof(atom_strings) / sizeof(*atom_strings); it != ie; ++it) {
bool equal;
assert(!equal); (void)equal;
atom_ids[offset++] = lit;
}
body[0] = atom_ids[0];
body[1] = atom_ids[1];
if (!
clingo_backend_rule(backend,
false, &atom_ids[3], 1, body,
sizeof(body)/
sizeof(*body))) {
goto error; }
body[1] = atom_ids[2];
if (!
clingo_backend_rule(backend,
false, NULL, 0, body,
sizeof(body)/
sizeof(*body))) {
goto error; }
if (!solve(ctl, &solve_ret)) { goto error; }
goto out;
error:
printf("%s\n", error_message);
out:
return ret;
}