fx.term: convert to new assembly build system
This commit is contained in:
+49
-23
@@ -1,11 +1,13 @@
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <fx/term/tty.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
static void get_error_id(
|
||||
const struct fx_error_vendor *vendor, const struct fx_error *error,
|
||||
char *out, size_t max)
|
||||
const struct fx_error_vendor *vendor,
|
||||
const struct fx_error *error,
|
||||
char *out,
|
||||
size_t max)
|
||||
{
|
||||
const char *vendor_name = NULL;
|
||||
const char *error_name = NULL;
|
||||
@@ -38,7 +40,8 @@ static void get_error_id(
|
||||
}
|
||||
|
||||
static void print_template_parameter(
|
||||
const struct fx_error_template_parameter *params, size_t nr_params,
|
||||
const struct fx_error_template_parameter *params,
|
||||
size_t nr_params,
|
||||
const char *param_name)
|
||||
{
|
||||
const struct fx_error_template_parameter *param = NULL;
|
||||
@@ -122,7 +125,8 @@ static void print_template_parameter(
|
||||
}
|
||||
|
||||
static void print_content(
|
||||
const struct fx_error_template_parameter *params, size_t nr_params,
|
||||
const struct fx_error_template_parameter *params,
|
||||
size_t nr_params,
|
||||
const char *s)
|
||||
{
|
||||
if (!s) {
|
||||
@@ -214,13 +218,16 @@ static void print_content(
|
||||
|
||||
static void print_submsg(const struct fx_error *error)
|
||||
{
|
||||
const struct fx_error_definition *error_def = fx_error_get_definition(error);
|
||||
const struct fx_error_definition *error_def
|
||||
= fx_error_get_definition(error);
|
||||
const struct fx_error_submsg *submsg = fx_error_get_first_submsg(error);
|
||||
|
||||
while (submsg) {
|
||||
enum fx_error_submsg_type type = fx_error_submsg_get_type(submsg);
|
||||
enum fx_error_submsg_type type
|
||||
= fx_error_submsg_get_type(submsg);
|
||||
const char *content = fx_error_submsg_get_content(submsg);
|
||||
const struct fx_error_msg *msg = fx_error_submsg_get_msg(submsg);
|
||||
const struct fx_error_msg *msg
|
||||
= fx_error_submsg_get_msg(submsg);
|
||||
const struct fx_error_template_parameter *params
|
||||
= fx_error_submsg_get_template_parameters(submsg);
|
||||
|
||||
@@ -229,16 +236,21 @@ static void print_submsg(const struct fx_error *error)
|
||||
switch (type) {
|
||||
case FX_ERROR_SUBMSG_ERROR:
|
||||
fx_tty_printf(
|
||||
fx_stdtty_err, 0, "[bright_red,bold]>[reset] ");
|
||||
fx_stdtty_err,
|
||||
0,
|
||||
"[bright_red,bold]>[reset] ");
|
||||
break;
|
||||
case FX_ERROR_SUBMSG_WARNING:
|
||||
fx_tty_printf(
|
||||
fx_stdtty_err, 0,
|
||||
fx_stdtty_err,
|
||||
0,
|
||||
"[bright_yellow,bold]>[reset] ");
|
||||
break;
|
||||
case FX_ERROR_SUBMSG_INFO:
|
||||
fx_tty_printf(
|
||||
fx_stdtty_err, 0, "[bright_cyan,bold]>[reset] ");
|
||||
fx_stdtty_err,
|
||||
0,
|
||||
"[bright_cyan,bold]>[reset] ");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -246,11 +258,14 @@ static void print_submsg(const struct fx_error *error)
|
||||
|
||||
if (msg) {
|
||||
print_content(
|
||||
params, FX_ERROR_TEMPLATE_PARAMETER_MAX,
|
||||
params,
|
||||
FX_ERROR_TEMPLATE_PARAMETER_MAX,
|
||||
fx_error_msg_get_content(msg));
|
||||
} else if (content) {
|
||||
print_content(
|
||||
params, FX_ERROR_TEMPLATE_PARAMETER_MAX, content);
|
||||
params,
|
||||
FX_ERROR_TEMPLATE_PARAMETER_MAX,
|
||||
content);
|
||||
}
|
||||
|
||||
fx_tty_printf(fx_stdtty_err, 0, "\n");
|
||||
@@ -293,8 +308,11 @@ static void print_stack_trace(const struct fx_error *error)
|
||||
file = get_short_filepath(file);
|
||||
|
||||
fx_tty_printf(
|
||||
fx_stdtty_err, 0,
|
||||
" [dark_grey]at %s() (%s:%u)[reset]\n", func, file,
|
||||
fx_stdtty_err,
|
||||
0,
|
||||
" [dark_grey]at %s() (%s:%u)[reset]\n",
|
||||
func,
|
||||
file,
|
||||
line);
|
||||
|
||||
frame = fx_error_get_next_stack_frame(error, frame);
|
||||
@@ -302,14 +320,17 @@ static void print_stack_trace(const struct fx_error *error)
|
||||
}
|
||||
|
||||
static void report_error(
|
||||
const fx_error *error, fx_error_report_flags flags, bool caused_by)
|
||||
const fx_error *error,
|
||||
fx_error_report_flags flags,
|
||||
bool caused_by)
|
||||
{
|
||||
const fx_error_vendor *vendor = fx_error_get_vendor(error);
|
||||
|
||||
char error_id[128];
|
||||
get_error_id(vendor, error, error_id, sizeof error_id);
|
||||
|
||||
const struct fx_error_definition *error_def = fx_error_get_definition(error);
|
||||
const struct fx_error_definition *error_def
|
||||
= fx_error_get_definition(error);
|
||||
fx_error_status_code code = fx_error_get_status_code(error);
|
||||
const char *description = fx_error_get_description(error);
|
||||
const struct fx_error_template_parameter *params
|
||||
@@ -317,12 +338,14 @@ static void report_error(
|
||||
|
||||
if (!description && vendor) {
|
||||
description = fx_error_vendor_get_status_code_description(
|
||||
vendor, code);
|
||||
vendor,
|
||||
code);
|
||||
}
|
||||
|
||||
if (caused_by) {
|
||||
fx_tty_printf(
|
||||
fx_stdtty_err, 0,
|
||||
fx_stdtty_err,
|
||||
0,
|
||||
" [green]->[reset] caused by [bright_red,bold]ERROR ");
|
||||
} else {
|
||||
fx_tty_printf(fx_stdtty_err, 0, "[bright_red,bold]==> ERROR ");
|
||||
@@ -339,12 +362,14 @@ static void report_error(
|
||||
if (msg) {
|
||||
fx_tty_printf(fx_stdtty_err, 0, ": ");
|
||||
print_content(
|
||||
params, FX_ERROR_TEMPLATE_PARAMETER_MAX,
|
||||
params,
|
||||
FX_ERROR_TEMPLATE_PARAMETER_MAX,
|
||||
fx_error_msg_get_content(msg));
|
||||
} else if (description) {
|
||||
fx_tty_printf(fx_stdtty_err, 0, ": ");
|
||||
print_content(
|
||||
params, FX_ERROR_TEMPLATE_PARAMETER_MAX,
|
||||
params,
|
||||
FX_ERROR_TEMPLATE_PARAMETER_MAX,
|
||||
description);
|
||||
}
|
||||
}
|
||||
@@ -366,7 +391,8 @@ static void report_error(
|
||||
}
|
||||
|
||||
void fx_enhanced_error_reporter(
|
||||
const struct fx_error *error, fx_error_report_flags flags)
|
||||
const struct fx_error *error,
|
||||
fx_error_report_flags flags)
|
||||
{
|
||||
report_error(error, flags, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user