NAME
ort_lang_sql —
generate SQL schema of openradtool
configuration
LIBRARY
library “libort-lang-sql”
SYNOPSIS
#include
<sys/queue.h>
#include <stdio.h>
#include <ort.h>
#include <ort-lang-sql.h>
int
ort_lang_sql(const struct sql
*args, const struct config *cfg,
FILE *f);
DESCRIPTION
Outputs the SQL schema of the parsed configuration
cfg to f. The output is tailored
to sqlite3(1). The
args is currently ignored and may be
NULL.
RETURN VALUES
Returns zero on failure, non-zero on success. Failure only occurs with memory allocation errors or when writing to f.
EXAMPLES
The following emits a configuration as read from standard input to SQL as written to standard output.
struct config *cfg; struct ort_lang_sql args; memset(&args, 0, sizeof(struct ort_lang_sql)); if ((cfg = ort_config_alloc()) == NULL) err(1, NULL); if (!ort_parse_file(cfg, stdin, "<stdin>")) errx(1, "ort_parse_file"); if (!ort_parse_close(cfg)) errx(1, "ort_parse_close"); if (!ort_lang_sql(&args, cfg, stdout)) err(1, "ort_lang_sql"); ort_config_free(cfg);
Alternatively, this could be converted into a string:
char *buf = NULL; size_t bufsz = 0; /* Read and parse configuration as above... */ if ((stream = open_memstream(&buf, &bufsz)) == NULL) err(1, "open_memstream"); if (!ort_lang_sql(&args, cfg, stream)) err(1, "ort_lang_sql"); fclose(stream); /* Do something with buf of size bufsz. */ free(buf);