24 .
id =
"frontend-diag",
25 .name =
"Diagnostic query tool",
28 .author =
"Elliot Haisley",
29 .desc =
"Cthulhu diagnostic lookup and query tool",
36 .
name =
"diagnostics",
37 .brief =
"Diagnostic query options"
44 .brief =
"Print info about all available languages",
45 .args =
CT_ARGS(kPrintLangsArgs),
50 static const cfg_info_t kPrintSingleLangInfo = {
52 .brief =
"Print information about a specific language",
53 .args =
CT_ARGS(kPrintSingleLangArgs),
60 .brief =
"Print all available diagnostics for all languages",
61 .args =
CT_ARGS(kPrintDiagInfoArgs),
66 static const cfg_info_t kPrintSingleDiagInfo = {
68 .brief =
"Print all available diagnostics for a specific language",
69 .args =
CT_ARGS(kPrintSingleDiagInfoArgs)
96 lang_choices[0] = none_choice;
98 for (
size_t i = 0; i < len; i++)
107 lang_choices[i + 1] = choice;
111 .options = lang_choices,
128 .print_all_langs = print_all_langs,
129 .print_one_lang = print_one_lang,
131 .print_all_diags = print_all_diags,
132 .print_one_diag = print_one_diag,
150 CTASSERTF(old == NULL,
"duplicate diagnostic id: %s (old message %s)", diag->
id, old->
brief);
158 for (
size_t i = 0; i < diagnostics.
count; i++)
164 static size_t count_diagnostics(
const typevec_t *langs)
169 for (
size_t i = 0; i < len; i++)
196 io_printf(io,
" version: %d.%d.%d\n", major, minor, patch);
204 io_printf(io,
"%zu available languages:\n", len);
205 for (
size_t i = 0; i < len; i++)
208 print_lang_info(io, lang);
219 int main(
int argc,
const char **argv)
234 for (
size_t i = 0; i < len; i++)
237 if (mod->
type & eModLanguage)
243 tool_t tool = make_config(langs, arena);
256 print_all_langs(io, langs);
268 print_lang_info(io, lang);
278 size_t count = count_diagnostics(langs) + common.
count;
285 add_diagnostics(&ctx, common);
288 for (
size_t i = 0; i < lang_count; i++)
302 io_printf(io,
"%zu diagnostics:\n", diag_count);
303 for (
size_t i = 0; i < diag_count; i++)
306 print_diagnostic(io, diag);
308 if (i + 1 < diag_count)
322 if (lang_diag_index != 0)
328 io_printf(io,
"%zu diagnostics for %s:\n", diag_count, info.
name);
330 for (
size_t i = 0; i < diag_count; i++)
333 print_diagnostic(io, diag);
335 if (i + 1 < diag_count)
348 for (
size_t i = 0; i < posarg_count; i++)
354 io_printf(io,
"unknown diagnostic: %s\n", arg);
358 print_diagnostic(io, diag);
360 if (i + 1 < posarg_count)
int main(int argc, const char **argv)
CT_BROKER_API broker_t * broker_new(const frontend_t *frontend, arena_t *arena)
CT_CONFIG_API cfg_field_t * config_enum(cfg_group_t *group, const cfg_info_t *info, cfg_enum_t cfg)
add a new choice field to a configuration group
CT_CONFIG_API cfg_field_t * config_bool(cfg_group_t *group, const cfg_info_t *info, bool initial)
add a new yes/no field to a configuration group
CT_PUREFN CT_CONFIG_API bool cfg_bool_value(const cfg_field_t *field)
get the current boolean value of a configuration field
CT_PUREFN CT_CONFIG_API size_t cfg_enum_value(const cfg_field_t *field)
get the current enum value of a configuration field
#define CT_ARG_LONG(name)
CT_CONFIG_API cfg_group_t * config_root(const cfg_info_t *info, arena_t *arena)
create a new configuration group
#define CT_VERSION_MAJOR(version)
returns the major version of version
#define CT_VERSION_MINOR(version)
returns the minor version of version
#define CT_NEW_VERSION(major, minor, patch)
creates a new ctu_version_t from major, minor and patch
#define CT_VERSION_PATCH(version)
returns the patch version of version
#define CT_EXIT_OK
no user errors or internal errors
CT_NODISCARD CT_CONSTFN CT_EVENTS_API diagnostic_list_t get_common_diagnostics(void)
get all common diagnostics
CT_MEMORY_API arena_t * get_global_arena(void)
get the global memory arena
CT_NODISCARD CT_STD_API map_t * map_optimal(size_t size, hash_info_t info, arena_t *arena)
create a new map with an optimal size
CT_STD_API void map_set(map_t *map, const void *key, void *value)
set a key-value pair in a map
CT_NODISCARD CT_PUREFN CT_STD_API void * map_get(const map_t *map, const void *key)
get a value from a map
CT_IO_API os_error_t io_close(INOUT_NOTNULL io_t *io)
destroy an IO object
CT_IO_API io_t * io_stdout(void)
get the global stdout IO object
CT_IO_API size_t io_printf(io_t *io, STA_FORMAT_STRING const char *fmt,...)
printf to an io object
CT_SUPPORT_API void support_load_default_modules(support_t *support)
load all default modules
CT_SUPPORT_API typevec_t * support_get_modules(support_t *support)
CT_SUPPORT_API support_t * support_new(broker_t *broker, loader_t *loader, arena_t *arena)
create a support instance from an existing loader and broker configures the broker with the modules i...
#define ARENA_MALLOC(size, name, parent, arena)
allocate memory from a custom allocator
STA_RET_STRING CT_CONSTFN CT_NOTIFY_API const char * severity_string(severity_t severity)
get the name of a severity
#define CTASSERTF(expr,...)
assert a condition with a message and optional format arguments
CT_SETUP_API setup_init_t setup_parse(int argc, const char **argv, setup_options_t setup)
parse the command line
CT_PUREFN CT_SETUP_API bool setup_should_exit(const setup_init_t *init)
accessor functions
CT_SETUP_API void setup_default(arena_t *arena)
initialise the runtime with default options
CT_SETUP_API setup_options_t setup_options(version_info_t info, cfg_group_t *root)
setup default options
CT_PUREFN CT_SETUP_API int setup_exit_code(const setup_init_t *init)
get the exit code
CT_STD_API const hash_info_t kTypeInfoString
type information for a c style string
CT_STD_API void * typevec_push(typevec_t *vec, const void *src)
push a value onto the vector
CT_NODISCARD CT_PUREFN CT_STD_API size_t typevec_len(const typevec_t *vec)
get the length of a vector
CT_NODISCARD CT_STD_API typevec_t * typevec_new(size_t width, size_t len, arena_t *arena)
create a new typed vector on the heap
CT_NODISCARD CT_PUREFN CT_STD_API void * typevec_offset(const typevec_t *vec, size_t index)
get a pointer to the value at the given index
CT_NODISCARD CT_PUREFN CT_STD_API void * vector_get(const vector_t *vector, size_t index)
get a value from a vector
CT_NODISCARD CT_PUREFN CT_STD_API size_t vector_len(const vector_t *vector)
get the length of a vector
CT_SUPPORT_API loader_t * loader_new(arena_t *arena)
a choice in a set of options
STA_FIELD_STRING const char * text
the name of this choice
a choice from a set of options
information about a configuration field
STA_FIELD_STRING const char * name
the name of this field
size_t count
the number of diagnostics in the list
const diagnostic_t *const * diagnostics
the list of diagnostics
const char * brief
a brief description of the diagnostic a single line description of the diagnostic
const char * id
the id of the diagnostic should be in the format [A-Z]{2,3}[0-9]{4} e.g. CLI0001 this is not enforced...
severity_t severity
the severity of the diagnostic
const char * description
a description of the diagnostic a more involved description of the diagnostic this is optional
the frontend running the mediator
module_info_t info
information about the frontend
a language driver support capabilities
module_info_t info
common information about the language
common information about anything the broker supports
version_info_t version
the version of the module
diagnostic_list_t diagnostics
all diagnostics associated with this module
const char * id
unique id for the module
const char * name
the human readable name for the module
the result of parsing the command line
vector_t * posargs
the parsed position arguments
default options shared by all tools
A vector with a fixed type size.
a generic vector of pointers
version information for a driver/interface/plugin
const char * license
the license of this component
const char * author
the author of this component
const char * desc
a short description of this component
ctu_version_t version
the version info for this component