NAME
ort_lang_c_source
—
generate JavaScript (TypeScript)
interface to ort data
LIBRARY
library “libort-lang-javascript”
SYNOPSIS
#include
<sys/queue.h>
#include <stdio.h>
#include <ort.h>
#include
<ort-lang-javascript.h>
int
ort_lang_javascript
(const struct
ort_lang_javascript *args, const struct config
*cfg, FILE *f);
DESCRIPTION
Outputs a TypeScript file to f from the parsed configuration cfg. The output consists of a namespace containing classes to populate HTML5 DOM trees. The classes accept input usually produced by ort_lang_c_header(3) or ort_lang_nodejs(3). Parameters are in args. The values in args are as follows:
- const char *ext_privMethods
- This string consists of classes and functions required by the produced code. It should be set to the contents of ortPrivate.ts.
- const char *ns
- If not
NULL
and non-empty, the name of the top-level namespace. This is not checked for correctness beyond that it be non-empty. - unsigned flags
- Bit-field of output options.
The following output options are available:
ORT_LANG_JS_EXPORT
- Mark the top-level namespace as “export”.
If args is NULL
, it
is set to a structure initialised to zero and using the default namespace
name “ort”. This will inhibit printing of the
ext_privMethods data, which is probably not
desired.
The output is documented in typedoc.
RETURN VALUES
Returns zero on failure, non-zero on success. Failure only occurs with memory allocation errors or when writing to f.
FILES
- ortPrivate.ts
- Helper classes and functions that must be specified as ext_privMethods in the configuration. This is usually installed in /usr/local/share/openradtool.
EXAMPLES
The following emits formatting routines to standard output as read from standard input. It assumes that buf has been initialised to the contents of ortPrivate.ts.
struct config *cfg; struct ort_lang_javascript args; FILE *f; memset(&args, 0, sizeof(struct ort_lang_javascript)); args.ext_privMethods = buf; 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_javascript(&args, cfg, stdout)) err(1, "ort_lang_javascript"); 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_javascript(&args, cfg, stream)) err(1, "ort_lang_javascript"); fclose(stream); /* Do something with buf of size bufsz. */ free(buf);