NAME
ort_lang_c_source
—
generate node.js implementation of
openradtool configuration
LIBRARY
library “libort-lang-nodejs”
SYNOPSIS
#include
<sys/queue.h>
#include <stdio.h>
#include <ort.h>
#include
<ort-lang-nodejs.h>
int
ort_lang_nodejs
(const struct
ort_lang_nodejs *args, const struct config *cfg,
FILE *f);
DESCRIPTION
Outputs a node.js implementation of the parsed configuration cfg to f. The values in args are as follows:
- unsigned int flags
- The bit-field of components to output.
The following components are output if specified:
ORT_LANG_NODEJS_CORE
- Generate the data structures.
ORT_LANG_NODEJS_DB
- Generate database routines. This stipulates a dependency on the "better-sqlite3" and "bcrypt" packages.
ORT_LANG_NODEJS_VALID
- Generate the validation namespace. This stipulates a dependency on the "validator" package.
If args is NULL
, it
defaults to all values being zero.
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 node.js as written to standard output.
struct config *cfg; struct ort_lang_nodejs args; memset(&args, 0, sizeof(struct ort_lang_nodejs)); args.flags = ORT_LANG_NODEJS_CORE|ORT_LANG_NODEJS_DB; 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_nodejs(&args, cfg, stdout)) err(1, "ort_lang_nodejs"); 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_nodejs(&args, cfg, stream)) err(1, "ort_lang_nodejs"); fclose(stream); /* Do something with buf of size bufsz. */ free(buf);