mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-12-01 16:56:34 +01:00
- charset module renamed to encoding (decode/encode kept)
- time: get_time_ms → y_gettime, sleep_ms → y_sleep
- time: delete get_time_us, get_time_delta, sleep_s
- string: strdup2 → y_strdup, wcsdup2 → y_wcsdup
- string: strtolower → y_strlower, strtrim → y_strtrim
- string: wcstrim → y_wcstrim, strhash → y_strhash
- string: strreplace → y_strreplace, strsplit → y_strsplit
- string: delete wcsreplace, cmdsplit
- math: delete y_iround, y_pow2
- timer module migrated from yutil to ptk as internal timer_scheduler
- WinMain simplified to use __argc/__argv instead of cmdsplit
BREAKING CHANGE: all renamed yutil public APIs require downstream
to update function names. Deleted APIs require code changes:
- get_time_us: use y_gettime() for ms timestamps
- get_time_delta: use y_gettime() - start instead
- sleep_s: use y_sleep(ms) with millisecond argument
- wcsreplace: no replacement, had zero callers
- cmdsplit: WinMain now uses __argc/__argv from CRT
- timer_list_*: migrated to ptk timer_scheduler_*;
ptk_reset_timer still available for external use
86 lines
2.3 KiB
C
86 lines
2.3 KiB
C
/*
|
|
* lib/css/src/style_parser.c
|
|
*
|
|
* Copyright (c) 2023-2026, Liu Chao <hello@lcui.dev> All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* This file is part of LCUI, distributed under the MIT License found
|
|
* in the LICENSE.TXT file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "../include/css.h"
|
|
|
|
static char *getdirname(const char *path)
|
|
{
|
|
char *dirname;
|
|
size_t i, pos;
|
|
for (i = 0, pos = SIZE_MAX; path[i]; ++i) {
|
|
if (path[i] == '/') {
|
|
pos = i;
|
|
}
|
|
}
|
|
if (pos > i) {
|
|
return NULL;
|
|
}
|
|
dirname = malloc(sizeof(char) * i);
|
|
if (!dirname) {
|
|
return NULL;
|
|
}
|
|
for (i = 0; i < pos; ++i) {
|
|
dirname[i] = path[i];
|
|
}
|
|
dirname[i] = 0;
|
|
return dirname;
|
|
}
|
|
|
|
void css_style_parser_init(css_style_parser_t *parser, const char *space)
|
|
{
|
|
parser->property = NULL;
|
|
parser->style_handler = NULL;
|
|
parser->style_handler_arg = NULL;
|
|
list_create(&parser->selectors);
|
|
if (space) {
|
|
parser->space = y_strdup(space);
|
|
parser->dirname = getdirname(parser->space);
|
|
} else {
|
|
parser->dirname = NULL;
|
|
parser->space = NULL;
|
|
}
|
|
}
|
|
|
|
void css_style_parser_destroy(css_style_parser_t *parser)
|
|
{
|
|
list_destroy(&parser->selectors,
|
|
(list_item_destructor_t)css_selector_destroy);
|
|
if (parser->dirname) {
|
|
free(parser->dirname);
|
|
}
|
|
if (parser->space) {
|
|
free(parser->space);
|
|
}
|
|
if (parser->property) {
|
|
free(parser->property);
|
|
}
|
|
parser->space = NULL;
|
|
parser->dirname = NULL;
|
|
parser->property = NULL;
|
|
}
|
|
|
|
void css_style_parser_commit(css_style_parser_t *parser)
|
|
{
|
|
list_node_t *node;
|
|
|
|
/* 将记录的样式表添加至匹配到的选择器中 */
|
|
for (list_each(node, &parser->selectors)) {
|
|
css_add_style_decl(node->data, parser->style, parser->space);
|
|
}
|
|
list_destroy(&parser->selectors,
|
|
(list_item_destructor_t)css_selector_destroy);
|
|
css_style_decl_destroy(parser->style);
|
|
}
|