style: auto-format C/C++ sources with clang-format

This commit is contained in:
Leonmmcoset
2026-04-25 06:29:00 +00:00
committed by github-actions[bot]
parent 02a24e47d5
commit a9626ef736

View File

@@ -60,8 +60,8 @@ static int ush_browser_is_http_url(const char *text) {
return 0; return 0;
} }
return (text[0] == 'h' && text[1] == 't' && text[2] == 't' && text[3] == 'p' && text[4] == ':' && return (text[0] == 'h' && text[1] == 't' && text[2] == 't' && text[3] == 'p' && text[4] == ':' && text[5] == '/' &&
text[5] == '/' && text[6] == '/') text[6] == '/')
? 1 ? 1
: 0; : 0;
} }
@@ -557,8 +557,8 @@ static int ush_browser_parse_content_length(const char *value, u64 value_len, u6
return 1; return 1;
} }
static int ush_browser_parse_http_headers(const char *raw, u64 raw_len, u64 *out_body_off, int *out_chunked, u64 *out_content_len, static int ush_browser_parse_http_headers(const char *raw, u64 raw_len, u64 *out_body_off, int *out_chunked,
int *out_has_content_len, int *out_compressed) { u64 *out_content_len, int *out_has_content_len, int *out_compressed) {
u64 header_end = 0ULL; u64 header_end = 0ULL;
u64 i; u64 i;
u64 off; u64 off;
@@ -953,7 +953,8 @@ static int ush_browser_fetch_http(const char *url_text, char *out_html, u64 out_
break; break;
} }
if (is_chunked != 0) { if (is_chunked != 0) {
int complete = ush_browser_is_chunked_body_complete(ush_browser_http_raw_buf + body_off, raw_len - body_off); int complete =
ush_browser_is_chunked_body_complete(ush_browser_http_raw_buf + body_off, raw_len - body_off);
if (complete < 0) { if (complete < 0) {
goto cleanup; goto cleanup;
} }
@@ -982,8 +983,8 @@ static int ush_browser_fetch_http(const char *url_text, char *out_html, u64 out_
u64 maybe_body_off = 0ULL; u64 maybe_body_off = 0ULL;
if (ush_browser_find_http_header_end(ush_browser_http_raw_buf, raw_len, &maybe_body_off) != 0) { if (ush_browser_find_http_header_end(ush_browser_http_raw_buf, raw_len, &maybe_body_off) != 0) {
if (ush_browser_parse_http_headers(ush_browser_http_raw_buf, raw_len, &body_off, &is_chunked, &content_length, if (ush_browser_parse_http_headers(ush_browser_http_raw_buf, raw_len, &body_off, &is_chunked,
&has_content_length, &is_compressed) == 0) { &content_length, &has_content_length, &is_compressed) == 0) {
goto cleanup; goto cleanup;
} }
@@ -999,7 +1000,8 @@ static int ush_browser_fetch_http(const char *url_text, char *out_html, u64 out_
break; break;
} }
if (is_chunked != 0) { if (is_chunked != 0) {
int complete = ush_browser_is_chunked_body_complete(ush_browser_http_raw_buf + body_off, raw_len - body_off); int complete =
ush_browser_is_chunked_body_complete(ush_browser_http_raw_buf + body_off, raw_len - body_off);
if (complete < 0) { if (complete < 0) {
goto cleanup; goto cleanup;
} }
@@ -1030,8 +1032,8 @@ static int ush_browser_fetch_http(const char *url_text, char *out_html, u64 out_
} }
if (is_chunked != 0) { if (is_chunked != 0) {
if (ush_browser_decode_chunked_body(ush_browser_http_raw_buf + body_off, raw_len - body_off, out_html, out_html_cap, if (ush_browser_decode_chunked_body(ush_browser_http_raw_buf + body_off, raw_len - body_off, out_html,
out_size) == 0) { out_html_cap, out_size) == 0) {
goto cleanup; goto cleanup;
} }
} else { } else {
@@ -1211,15 +1213,16 @@ static int ush_browser_css_color_is_blue(const char *value, u64 value_len) {
} }
normalized[at] = '\0'; normalized[at] = '\0';
if (ush_streq(normalized, "blue") != 0 || ush_streq(normalized, "#00f") != 0 || ush_streq(normalized, "#0000ff") != 0 || if (ush_streq(normalized, "blue") != 0 || ush_streq(normalized, "#00f") != 0 ||
ush_streq(normalized, "rgb(0,0,255)") != 0) { ush_streq(normalized, "#0000ff") != 0 || ush_streq(normalized, "rgb(0,0,255)") != 0) {
return 1; return 1;
} }
return 0; return 0;
} }
static void ush_browser_css_apply_declarations(const char *decl, u64 decl_len, int *io_link_blue, int *io_link_underline) { static void ush_browser_css_apply_declarations(const char *decl, u64 decl_len, int *io_link_blue,
int *io_link_underline) {
u64 pos = 0ULL; u64 pos = 0ULL;
if (decl == (const char *)0 || io_link_blue == (int *)0 || io_link_underline == (int *)0) { if (decl == (const char *)0 || io_link_blue == (int *)0 || io_link_underline == (int *)0) {
@@ -1285,7 +1288,8 @@ static void ush_browser_css_apply_declarations(const char *decl, u64 decl_len, i
ush_browser_line_has_token_icase(decl + value_start, value_end - value_start, "unset") != 0) { ush_browser_line_has_token_icase(decl + value_start, value_end - value_start, "unset") != 0) {
/* keep previous style */ /* keep previous style */
} else { } else {
*io_link_blue = (ush_browser_css_color_is_blue(decl + value_start, value_end - value_start) != 0) ? 1 : 0; *io_link_blue =
(ush_browser_css_color_is_blue(decl + value_start, value_end - value_start) != 0) ? 1 : 0;
} }
} }
} }
@@ -1312,11 +1316,11 @@ static int ush_browser_css_selector_targets_anchor(const char *selector, u64 sel
prev == '>' || prev == '+' || prev == '~') prev == '>' || prev == '+' || prev == '~')
? 1 ? 1
: 0; : 0;
int next_ok = (next == ' ' || next == '\t' || next == '\r' || next == '\n' || next == ',' || next == '\0' || int next_ok =
next == '.' || next == '#' || next == ':' || next == '[' || next == '>' || next == '+' || (next == ' ' || next == '\t' || next == '\r' || next == '\n' || next == ',' || next == '\0' ||
next == '~') next == '.' || next == '#' || next == ':' || next == '[' || next == '>' || next == '+' || next == '~')
? 1 ? 1
: 0; : 0;
if (prev_ok != 0 && next_ok != 0) { if (prev_ok != 0 && next_ok != 0) {
return 1; return 1;
@@ -1389,7 +1393,8 @@ static void ush_browser_collect_style_text(GumboNode *node, char *out, u64 out_c
} }
if (node->type == GUMBO_NODE_ELEMENT || node->type == GUMBO_NODE_TEMPLATE || node->type == GUMBO_NODE_DOCUMENT) { if (node->type == GUMBO_NODE_ELEMENT || node->type == GUMBO_NODE_TEMPLATE || node->type == GUMBO_NODE_DOCUMENT) {
GumboVector *children = (node->type == GUMBO_NODE_DOCUMENT) ? &node->v.document.children : &node->v.element.children; GumboVector *children =
(node->type == GUMBO_NODE_DOCUMENT) ? &node->v.document.children : &node->v.element.children;
u64 i; u64 i;
for (i = 0ULL; i < (u64)children->length; i++) { for (i = 0ULL; i < (u64)children->length; i++) {
@@ -1416,7 +1421,8 @@ static void ush_browser_css_scan_style_nodes(GumboNode *node) {
} }
if (node->type == GUMBO_NODE_ELEMENT || node->type == GUMBO_NODE_TEMPLATE || node->type == GUMBO_NODE_DOCUMENT) { if (node->type == GUMBO_NODE_ELEMENT || node->type == GUMBO_NODE_TEMPLATE || node->type == GUMBO_NODE_DOCUMENT) {
GumboVector *children = (node->type == GUMBO_NODE_DOCUMENT) ? &node->v.document.children : &node->v.element.children; GumboVector *children =
(node->type == GUMBO_NODE_DOCUMENT) ? &node->v.document.children : &node->v.element.children;
u64 i; u64 i;
for (i = 0ULL; i < (u64)children->length; i++) { for (i = 0ULL; i < (u64)children->length; i++) {
@@ -1545,10 +1551,10 @@ static void ush_browser_collect_anchor_link(GumboNode *node) {
ush_copy(text, (u64)sizeof(text), "(link)"); ush_copy(text, (u64)sizeof(text), "(link)");
} }
ush_copy(ush_browser_links[ush_browser_link_count].text, (u64)sizeof(ush_browser_links[ush_browser_link_count].text), ush_copy(ush_browser_links[ush_browser_link_count].text,
text); (u64)sizeof(ush_browser_links[ush_browser_link_count].text), text);
ush_copy(ush_browser_links[ush_browser_link_count].href, (u64)sizeof(ush_browser_links[ush_browser_link_count].href), ush_copy(ush_browser_links[ush_browser_link_count].href,
href->value); (u64)sizeof(ush_browser_links[ush_browser_link_count].href), href->value);
ush_browser_link_count++; ush_browser_link_count++;
} }
@@ -1565,7 +1571,8 @@ static int ush_browser_find_title_node(GumboNode *node, char *out, u64 out_cap)
} }
if (node->type == GUMBO_NODE_ELEMENT || node->type == GUMBO_NODE_TEMPLATE || node->type == GUMBO_NODE_DOCUMENT) { if (node->type == GUMBO_NODE_ELEMENT || node->type == GUMBO_NODE_TEMPLATE || node->type == GUMBO_NODE_DOCUMENT) {
GumboVector *children = (node->type == GUMBO_NODE_DOCUMENT) ? &node->v.document.children : &node->v.element.children; GumboVector *children =
(node->type == GUMBO_NODE_DOCUMENT) ? &node->v.document.children : &node->v.element.children;
u64 i; u64 i;
for (i = 0ULL; i < (u64)children->length; i++) { for (i = 0ULL; i < (u64)children->length; i++) {
@@ -1654,7 +1661,8 @@ static void ush_browser_walk_dom(GumboNode *node) {
} }
} }
static int ush_browser_read_file(const ush_state *sh, const char *arg, char *out_html, u64 out_html_cap, u64 *out_size) { static int ush_browser_read_file(const ush_state *sh, const char *arg, char *out_html, u64 out_html_cap,
u64 *out_size) {
char abs_path[USH_PATH_MAX]; char abs_path[USH_PATH_MAX];
u64 fd; u64 fd;
u64 total = 0ULL; u64 total = 0ULL;
@@ -1770,8 +1778,8 @@ static void ush_browser_print_rendered(const char *source_desc) {
ush_writeln(""); ush_writeln("");
ush_writeln("[links]"); ush_writeln("[links]");
for (k = 0ULL; k < ush_browser_link_count; k++) { for (k = 0ULL; k < ush_browser_link_count; k++) {
(void)printf(" [%llu] " USH_BROWSER_ANSI_BLUE_UNDERLINE "%s" USH_BROWSER_ANSI_RESET " -> " (void)printf(" [%llu] " USH_BROWSER_ANSI_BLUE_UNDERLINE "%s" USH_BROWSER_ANSI_RESET
USH_BROWSER_ANSI_BLUE_UNDERLINE "%s" USH_BROWSER_ANSI_RESET "\n", " -> " USH_BROWSER_ANSI_BLUE_UNDERLINE "%s" USH_BROWSER_ANSI_RESET "\n",
(unsigned long long)(k + 1ULL), ush_browser_links[k].text, ush_browser_links[k].href); (unsigned long long)(k + 1ULL), ush_browser_links[k].text, ush_browser_links[k].href);
} }
} }
@@ -1782,8 +1790,8 @@ static int ush_browser_is_https_url(const char *text) {
return 0; return 0;
} }
return (text[0] == 'h' && text[1] == 't' && text[2] == 't' && text[3] == 'p' && text[4] == 's' && return (text[0] == 'h' && text[1] == 't' && text[2] == 't' && text[3] == 'p' && text[4] == 's' && text[5] == ':' &&
text[5] == ':' && text[6] == '/' && text[7] == '/') text[6] == '/' && text[7] == '/')
? 1 ? 1
: 0; : 0;
} }
@@ -2027,8 +2035,8 @@ static int ush_browser_resolve_http_href(const char *base_source, const char *hr
} }
if (base.port == 80U) { if (base.port == 80U) {
if (snprintf(out_source, (unsigned long)out_size, "http://%s%s%s", base.host, base_path_only, href_no_frag) <= if (snprintf(out_source, (unsigned long)out_size, "http://%s%s%s", base.host, base_path_only,
0) { href_no_frag) <= 0) {
return 0; return 0;
} }
} else { } else {
@@ -2118,7 +2126,8 @@ static int ush_browser_resolve_href(const char *base_source, const char *href, c
return ush_browser_resolve_local_href(base_source, href, out_source, out_size); return ush_browser_resolve_local_href(base_source, href, out_source, out_size);
} }
static int ush_browser_load_source(const ush_state *sh, const char *source, char *out_html, u64 out_html_cap, u64 *out_size) { static int ush_browser_load_source(const ush_state *sh, const char *source, char *out_html, u64 out_html_cap,
u64 *out_size) {
if (sh == (const ush_state *)0 || source == (const char *)0 || out_html == (char *)0 || out_size == (u64 *)0) { if (sh == (const ush_state *)0 || source == (const char *)0 || out_html == (char *)0 || out_size == (u64 *)0) {
return 0; return 0;
} }
@@ -2161,8 +2170,10 @@ static int ush_browser_push_history(char history[][USH_BROWSER_SOURCE_MAX], u64
return 1; return 1;
} }
static int ush_browser_pop_history(char history[][USH_BROWSER_SOURCE_MAX], u64 *io_count, char *out_source, u64 out_size) { static int ush_browser_pop_history(char history[][USH_BROWSER_SOURCE_MAX], u64 *io_count, char *out_source,
if (history == (char(*)[USH_BROWSER_SOURCE_MAX])0 || io_count == (u64 *)0 || out_source == (char *)0 || out_size == 0ULL) { u64 out_size) {
if (history == (char(*)[USH_BROWSER_SOURCE_MAX])0 || io_count == (u64 *)0 || out_source == (char *)0 ||
out_size == 0ULL) {
return 0; return 0;
} }
@@ -2276,7 +2287,8 @@ static int ush_cmd_browser(const ush_state *sh, const char *arg) {
} }
for (;;) { for (;;) {
if (ush_browser_load_source(sh, current_source, ush_browser_html_buf, (u64)sizeof(ush_browser_html_buf), &html_size) == 0) { if (ush_browser_load_source(sh, current_source, ush_browser_html_buf, (u64)sizeof(ush_browser_html_buf),
&html_size) == 0) {
if (ush_browser_is_https_url(current_source) != 0) { if (ush_browser_is_https_url(current_source) != 0) {
ush_writeln("browser: https:// is not supported yet"); ush_writeln("browser: https:// is not supported yet");
} else if (ush_browser_is_http_url(current_source) != 0) { } else if (ush_browser_is_http_url(current_source) != 0) {
@@ -2285,7 +2297,8 @@ static int ush_cmd_browser(const ush_state *sh, const char *arg) {
ush_writeln("browser: file read failed"); ush_writeln("browser: file read failed");
} }
if (loaded_once == 0 || ush_browser_pop_history(history, &history_count, current_source, (u64)sizeof(current_source)) == 0) { if (loaded_once == 0 ||
ush_browser_pop_history(history, &history_count, current_source, (u64)sizeof(current_source)) == 0) {
return 0; return 0;
} }
ush_writeln("browser: returned to previous page"); ush_writeln("browser: returned to previous page");
@@ -2294,7 +2307,8 @@ static int ush_cmd_browser(const ush_state *sh, const char *arg) {
if (ush_browser_render_html(ush_browser_html_buf, html_size) == 0) { if (ush_browser_render_html(ush_browser_html_buf, html_size) == 0) {
ush_writeln("browser: parse/render failed"); ush_writeln("browser: parse/render failed");
if (loaded_once == 0 || ush_browser_pop_history(history, &history_count, current_source, (u64)sizeof(current_source)) == 0) { if (loaded_once == 0 ||
ush_browser_pop_history(history, &history_count, current_source, (u64)sizeof(current_source)) == 0) {
return 0; return 0;
} }
ush_writeln("browser: returned to previous page"); ush_writeln("browser: returned to previous page");
@@ -2317,7 +2331,8 @@ static int ush_cmd_browser(const ush_state *sh, const char *arg) {
continue; continue;
} }
if (ush_streq(input_line, "q") != 0 || ush_streq(input_line, "quit") != 0 || ush_streq(input_line, "exit") != 0) { if (ush_streq(input_line, "q") != 0 || ush_streq(input_line, "quit") != 0 ||
ush_streq(input_line, "exit") != 0) {
return 1; return 1;
} }
@@ -2343,9 +2358,9 @@ static int ush_cmd_browser(const ush_state *sh, const char *arg) {
} }
ush_zero(next_source, (u64)sizeof(next_source)); ush_zero(next_source, (u64)sizeof(next_source));
if ((input_line[0] == 'o' && input_line[1] == ' ') || (input_line[0] == 'o' && input_line[1] == 'p' && if ((input_line[0] == 'o' && input_line[1] == ' ') ||
input_line[2] == 'e' && input_line[3] == 'n' && (input_line[0] == 'o' && input_line[1] == 'p' && input_line[2] == 'e' && input_line[3] == 'n' &&
input_line[4] == ' ')) { input_line[4] == ' ')) {
const char *payload = (input_line[1] == ' ') ? (input_line + 2) : (input_line + 5); const char *payload = (input_line[1] == ' ') ? (input_line + 2) : (input_line + 5);
while (*payload == ' ') { while (*payload == ' ') {
payload++; payload++;
@@ -2374,10 +2389,12 @@ static int ush_cmd_browser(const ush_state *sh, const char *arg) {
continue; continue;
} }
if (ush_browser_is_http_url(next_source) == 0 && ush_browser_is_https_url(next_source) == 0 && next_source[0] != '/') { if (ush_browser_is_http_url(next_source) == 0 && ush_browser_is_https_url(next_source) == 0 &&
next_source[0] != '/') {
char resolved_target[USH_BROWSER_SOURCE_MAX]; char resolved_target[USH_BROWSER_SOURCE_MAX];
if (ush_browser_resolve_href(current_source, next_source, resolved_target, (u64)sizeof(resolved_target)) != 0) { if (ush_browser_resolve_href(current_source, next_source, resolved_target, (u64)sizeof(resolved_target)) !=
0) {
ush_copy(next_source, (u64)sizeof(next_source), resolved_target); ush_copy(next_source, (u64)sizeof(next_source), resolved_target);
} else if (ush_resolve_path(sh, next_source, resolved_target, (u64)sizeof(resolved_target)) != 0) { } else if (ush_resolve_path(sh, next_source, resolved_target, (u64)sizeof(resolved_target)) != 0) {
ush_copy(next_source, (u64)sizeof(next_source), resolved_target); ush_copy(next_source, (u64)sizeof(next_source), resolved_target);
@@ -2391,7 +2408,6 @@ static int ush_cmd_browser(const ush_state *sh, const char *arg) {
(void)ush_browser_push_history(history, &history_count, current_source); (void)ush_browser_push_history(history, &history_count, current_source);
ush_copy(current_source, (u64)sizeof(current_source), next_source); ush_copy(current_source, (u64)sizeof(current_source), next_source);
} }
} }
int cleonos_app_main(void) { int cleonos_app_main(void) {