The example shows how to extend the clingo application.It behaves like a normal normal clingo but adds one option to override the default program part to ground.
Example calls
$ cat example.lp
b.
#program test.
t.
$ ./application --program test example.lp
example version 1.0.0
Reading from example.lp
Solving...
Answer: 1
t
SATISFIABLE
Models : 1+
Calls : 1
Time : 0.004s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.004s
Code
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct options {
char const *program;
} options_t;
char const *name(void *data) {
(void)data;
return "example";
}
char const *version(void *data) {
(void)data;
return "1.0.0";
}
bool ret = true;
while (true) {
if (!model) { break; }
}
goto out;
error:
ret = false;
out:
}
bool parse_option(char const *value, void *data) {
char **program = (char **)data;
if (!(*program = (char *)malloc(strlen(value) + 1))) {
return false;
}
strcpy(*program, value);
return true;
}
options_t *options_ = (options_t*)data;
return clingo_options_add(options,
"Example",
"program",
"Override the default program part to ground", parse_option, &options_->program,
false,
"<prog>");
}
bool main_loop(
clingo_control_t *ctl,
char const *
const *files,
size_t size,
void *data) {
options_t *options = (options_t*)data;
bool ret = true;
clingo_part_t parts[] = {{ options->program ? options->program :
"base", NULL, 0 }};
char const *const *file;
for (file = files; file != files + size; ++file) {
}
if (size == 0) {
}
if (!solve(ctl)) { goto error; }
goto out;
error:
ret = false;
out:
return ret;
}
int main(int argc, char const **argv) {
options_t options = { NULL };
}