chore: migrate project into clean repository

This commit is contained in:
yuuux
2026-08-13 16:50:52 +08:00
commit d1d25a09e7
27405 changed files with 9422808 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(listenai-cmake REQUIRED HINTS $ENV{ARCS_BASE})
project(arcs)
listenai_add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE
src/main.cpp
)
listenai_include_directories(src)

View File

@@ -0,0 +1 @@
osource "$ARCS_BASE/Kconfig"

View File

@@ -0,0 +1,171 @@
C++ 正则表达式示例
===================
功能说明
--------
演示 C++ 标准库中正则表达式的使用,包括模式匹配、字符串搜索和分组提取等功能。本示例展示了如何使用 ``std::regex`` 进行文本处理和模式识别。
硬件连接
--------
无需外部连接,正则表达式为软件功能,不依赖硬件资源。
示例内容
--------
1. 基本模式匹配(``regex_search``)
2. 锚点匹配(``^`` 开头、``$`` 结尾)
3. 字符类和量词匹配
4. 分组提取和捕获
5. 多次匹配和迭代搜索
编译
--------
.. include:: /sample_build.rst
烧录固件
--------
.. include:: /sample_flash.rst
预期输出
--------
.. code-block:: text
=== C++ Regex Sample ===
1. Basic pattern matching:
Match: 'quick' in 'The quick brown fox'
Match: '^The' in 'The quick brown fox'
Match: 'fox$' in 'The quick brown fox'
Match: '\s[a-z]{5}\s' in 'The quick brown fox'
2. Extracting matches with groups:
Pattern: '([a-z]+)\s+([a-z]+)'
String: 'hello world'
Match 0: hello world
Match 1: hello
Match 2: world
Pattern: '(\d{4})-(\d{2})-(\d{2})'
String: 'Date: 2023-05-26'
Match 0: 2023-05-26
Match 1: 2023
Match 2: 05
Match 3: 26
Pattern: '([a-zA-Z]+) (\d+), (\d+)'
String: 'May 26, 2023'
Match 0: May 26, 2023
Match 1: May
Match 2: 26
Match 3: 2023
Regex Sample Completed
核心 API
--------
.. list-table::
:header-rows: 1
* - API
- 说明
* - ``std::regex``
- 正则表达式对象,用于存储编译后的模式
* - ``std::regex_search()``
- 在字符串中搜索匹配的模式
* - ``std::smatch``
- 匹配结果容器,存储匹配的子串
* - ``std::regex_match()``
- 检查整个字符串是否完全匹配模式
关键代码
--------
.. code-block:: cpp
// 基本模式匹配
void match_pattern(const string& pattern, const string& str) {
regex re(pattern);
if (regex_search(str, re)) {
cout << "Match: '" << pattern << "' in '" << str << "'" << endl;
} else {
cout << "No match: '" << pattern << "' in '" << str << "'" << endl;
}
}
// 提取匹配和分组
void extract_matches(const string& pattern, const string& str) {
regex re(pattern);
smatch matches;
cout << "Pattern: '" << pattern << "'" << endl;
cout << "String: '" << str << "'" << endl;
string::const_iterator searchStart(str.cbegin());
int i = 0;
while (regex_search(searchStart, str.cend(), matches, re)) {
for (size_t j = 0; j < matches.size(); ++j) {
cout << "Match " << i << ": " << matches[j].str() << endl;
i++;
}
searchStart = matches[0].second;
}
}
// 使用示例
match_pattern("quick", "The quick brown fox");
extract_matches("([a-z]+)\\s+([a-z]+)", "hello world");
正则表达式语法
--------------
常用元字符
~~~~~~~~~~
.. list-table::
:header-rows: 1
* - 元字符
- 说明
* - ``.``
- 匹配任意字符(除换行符)
* - ``^``
- 匹配字符串开头
* - ``$``
- 匹配字符串结尾
* - ``*``
- 匹配前一个字符 0 次或多次
* - ``+``
- 匹配前一个字符 1 次或多次
* - ``?``
- 匹配前一个字符 0 次或 1 次
* - ``{n}``
- 匹配前一个字符恰好 n 次
* - ``{n,m}``
- 匹配前一个字符 n 到 m 次
* - ``[abc]``
- 匹配字符类中的任意字符
* - ``\d``
- 匹配数字字符
* - ``\s``
- 匹配空白字符
* - ``()``
- 捕获分组
转义字符
~~~~~~~~
在 C++ 字符串中,反斜杠需要转义,因此正则表达式中的 ``\d`` 应写作 ``"\\d"``。
注意事项
--------
1. **转义字符**: 在 C++ 字符串字面量中,反斜杠需要转义,正则表达式 ``\d`` 应写作 ``"\\d"``
2. **性能考虑**: ``std::regex`` 对象可以重复使用,避免在循环中重复构造
3. **异常处理**: 无效的正则表达式模式会抛出 ``std::regex_error`` 异常
4. **匹配结果**: ``smatch[0]`` 包含完整匹配,``smatch[1]``、``smatch[2]`` 等包含捕获的分组
5. **迭代器**: 使用迭代器进行多次匹配时,需要更新搜索起始位置(``matches[0].second``)
6. **大小写敏感**: 默认情况下正则表达式区分大小写,如需忽略大小写可使用 ``std::regex_constants::icase`` 标志

View File

@@ -0,0 +1,177 @@
#!/bin/bash
set -e
usage() {
echo "使用方式: $0 [选项]"
echo "选项:"
echo " -S, --Source <path> 指定项目源码路径 (默认为当前脚本所在目录)"
echo " -t, --target <target> 指定构建目标 (如 menuconfig)"
echo " -C, --Clean 清理构建目录"
echo " -B, --build 构建输出目录"
echo " -h, --help 显示此帮助信息"
echo " -r, --release 以 Release 模式构建 (移除 DEBUG_PATH 信息)"
echo " -w, --warnings-as-errors 将警告视为错误"
echo " -D<var>=<value> 传递 CMake 变量 (可多次使用)"
echo ""
echo "示例:"
echo " $0 -S samples/helloworld -DBOARD=arcs_mini 指定板型构建"
echo " $0 -S samples/helloworld -DBOARD=arcs_evb 使用 EVB 板型"
echo " $0 -S samples/helloworld -t menuconfig -DBOARD=arcs_mini 运行 menuconfig"
echo " $0 -C -S samples/helloworld -DBOARD=arcs_mini 清理并重新构建"
echo " $0 -S samples/helloworld -DBOARD=my_board -DBOARD_SEARCH_PATH=/path/to/boards 使用自定义板型"
exit 1
}
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
PROJECT_PATH="$SCRIPT_DIR"
TARGET=""
CLEAN=false
OUTPUT="build"
WARNINGS_AS_ERRORS=false
RELEASE=false
ARCS_BASE_DIR_NAME="arcs-sdk"
ARCS_DEV_TOOLS_DIR_NAME="listenai-dev-tools"
ARCS_DEV_TOOL_TOOLCHAIN_DIR_NAME="gcc"
ARCS_DEV_TOOL_LISTENAI_TOOLS_DIR_NAME="listenai-tools"
find_arcs_base() {
local current_dir=$(cd "$(dirname "$0")" && pwd)
local dir_name="$ARCS_BASE_DIR_NAME"
while [ "$current_dir" != "/" ]; do
if [ -d "$current_dir/$dir_name" ]; then
echo "Found ARCS_BASE: $current_dir/$dir_name"
export ARCS_BASE="$current_dir/$dir_name"
return 0
fi
current_dir=$(dirname "$current_dir")
done
echo "ARCS_BASE not found, Please add ARCS_BASE environment variable or set ARCS_BASE_DIR_NAME to the correct directory."
echo "Current Target ARCS_BASE directory name: $ARCS_BASE_DIR_NAME."
exit 1
}
find_dev_tools() {
local current_dir=$(cd "$(dirname "$0")" && pwd)
local dir_name="$ARCS_DEV_TOOLS_DIR_NAME"
echo "trying to find $dir_name in parent directories..."
while [ "$current_dir" != "/" ]; do
if [ -d "$current_dir/$dir_name" ]; then
echo "Found $dir_name: $current_dir/$dir_name"
if [ -d "$current_dir/$dir_name/$ARCS_DEV_TOOL_LISTENAI_TOOLS_DIR_NAME" ]; then
echo "Found LISTENAI_TOOLS_PATH: $current_dir/$dir_name/$ARCS_DEV_TOOL_LISTENAI_TOOLS_DIR_NAME"
export LISTENAI_TOOLS_PATH="$current_dir/$dir_name/$ARCS_DEV_TOOL_LISTENAI_TOOLS_DIR_NAME"
fi
if [ -d "$current_dir/$dir_name/$ARCS_DEV_TOOL_TOOLCHAIN_DIR_NAME" ]; then
echo "Found NUCLEI_TOOLCHAIN_PATH: $current_dir/$dir_name/$ARCS_DEV_TOOL_TOOLCHAIN_DIR_NAME"
export NUCLEI_TOOLCHAIN_PATH="$current_dir/$dir_name/$ARCS_DEV_TOOL_TOOLCHAIN_DIR_NAME"
fi
return 0
fi
current_dir=$(dirname "$current_dir")
done
}
while [[ $# -gt 0 ]]; do
case $1 in
-S|--Source)
PROJECT_PATH="$2"
shift 2
;;
-B|--build)
OUTPUT="$2"
shift 2
;;
-t|--target)
TARGET="$2"
shift 2
;;
-C|--Clean)
CLEAN=true
shift 1
;;
-w|--warnings-as-errors)
WARNINGS_AS_ERRORS=true
shift 1
;;
-h|--help)
usage
;;
-r|--release)
RELEASE=true
shift 1
;;
-D*)
CMAKE_VARS+=("$1")
shift 1
;;
*)
echo "未知参数: $1"
usage
;;
esac
done
echo "Source: $PROJECT_PATH"
echo "Target: $TARGET"
echo "Clean : $CLEAN"
if [ -z "$LISTENAI_TOOLS_PATH" ] || [ -z "$NUCLEI_TOOLCHAIN_PATH" ]; then
find_dev_tools
fi
if [ -z "${LISTENAI_TOOLS_PATH}" ]; then
export LISTENAI_TOOLS_PATH="请添加 LISTENAI_TOOLS_PATH 环境变量,或在此行设置正确的路径"
echo "请添加 LISTENAI_TOOLS_PATH 环境变量或者修改脚本后, 注释脚本第 $LINENO 行";exit 1;
fi
if [ -z "${NUCLEI_TOOLCHAIN_PATH}" ]; then
export NUCLEI_TOOLCHAIN_PATH="请添加 NUCLEI_TOOLCHAIN_PATH 环境变量,或在此行设置正确的路径"
echo "请添加 NUCLEI_TOOLCHAIN_PATH 环境变量或者修改脚本后, 注释脚本第 $LINENO 行";exit 1;
fi
############### 下面代码不用修改 ##################
# 构建工具的位置
CMAKE_PROGRAM="$LISTENAI_TOOLS_PATH/cmake/bin/cmake"
NINJA_PROGRAM="$LISTENAI_TOOLS_PATH/ninja/ninja"
# 配置环境变量 ARCS_BASE
if [ -z "$ARCS_BASE" ]; then
find_arcs_base
fi
if [ "$CLEAN" = true ]; then
rm -rf $OUTPUT
fi
# Initialize CMAKE_VARS array if it doesn't exist
declare -a CMAKE_VARS
# Add warnings-as-errors flag if enabled
if [ "$WARNINGS_AS_ERRORS" = true ]; then
CMAKE_VARS+=("-DCMAKE_C_FLAGS=-Werror")
CMAKE_VARS+=("-DCMAKE_CXX_FLAGS=-Werror")
echo "Treating warnings as errors"
fi
# Add release flags if enabled
if [ "$RELEASE" = true ]; then
CMAKE_VARS+=("-DENABLE_DEBUG_PATH=OFF")
echo "Release mode enabled (-DENABLE_DEBUG_PATH=OFF)"
fi
$CMAKE_PROGRAM -B "$OUTPUT" -G Ninja -S "$PROJECT_PATH" \
-DCMAKE_MAKE_PROGRAM="$NINJA_PROGRAM" \
"${CMAKE_VARS[@]}"
if [ -z "$TARGET" ]; then
$CMAKE_PROGRAM --build "$OUTPUT" -j4
else
$CMAKE_PROGRAM --build "$OUTPUT" --target "$TARGET"
fi

View File

View File

@@ -0,0 +1,8 @@
tests:
samples.cpp.regex:
programmer: arcs
runner: uart
log_analyzer:
type: "regex"
pattern: "Regex Sample Completed"

View File

@@ -0,0 +1,57 @@
#include <iostream>
#include <string>
#include <regex>
using namespace std;
void match_pattern(const string& pattern, const string& str) {
regex re(pattern);
if (regex_search(str, re)) {
cout << "Match: '" << pattern << "' in '" << str << "'" << endl;
} else {
cout << "No match: '" << pattern << "' in '" << str << "'" << endl;
}
}
void extract_matches(const string& pattern, const string& str) {
regex re(pattern);
smatch matches;
cout << "Pattern: '" << pattern << "'" << endl;
cout << "String: '" << str << "'" << endl;
string::const_iterator searchStart(str.cbegin());
int i = 0;
while (regex_search(searchStart, str.cend(), matches, re)) {
for (size_t j = 0; j < matches.size(); ++j) {
cout << "Match " << i << ": " << matches[j].str() << endl;
i++;
}
searchStart = matches[0].second;
}
if (i == 0) {
cout << "No matches found for pattern '" << pattern
<< "' in string '" << str << "'" << endl;
}
}
int main(int argc, char **argv) {
cout << "=== C++ Regex Sample ===\n" << endl;
// Basic pattern matching
cout << "1. Basic pattern matching:" << endl;
match_pattern("quick", "The quick brown fox");
match_pattern("^The", "The quick brown fox");
match_pattern("fox$", "The quick brown fox");
match_pattern("\\s[a-z]{5}\\s", "The quick brown fox");
cout << "\n2. Extracting matches with groups:" << endl;
extract_matches("([a-z]+)\\s+([a-z]+)", "hello world");
extract_matches("(\\d{4})-(\\d{2})-(\\d{2})", "Date: 2023-05-26");
extract_matches("([a-zA-Z]+) (\\d+), (\\d+)", "May 26, 2023");
cout << "Regex Sample Completed\r\n";
return 0;
}