40 lines
717 B
Bash
40 lines
717 B
Bash
#!/bin/bash
|
|
|
|
# 检查参数
|
|
if [ $# -ne 1 ]; then
|
|
echo "用法: $0 <文件名(不带扩展名)>"
|
|
exit 1
|
|
fi
|
|
|
|
filename="$1"
|
|
upper_filename=$(echo "$filename" | tr '[:lower:]' '[:upper:]')
|
|
|
|
# 创建目录(如果不存在)
|
|
mkdir -p ./include/solution ./src ./tests
|
|
|
|
# 创建 ./include/solution/a.h
|
|
cat > ./include/solution/"$filename".h <<EOF
|
|
#ifndef INC_${upper_filename}_H
|
|
#define INC_${upper_filename}_H
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|
|
EOF
|
|
|
|
# 创建 ./src/a.c
|
|
cat > ./src/"$filename".c <<EOF
|
|
#include <solution/$filename.h>
|
|
EOF
|
|
|
|
# 创建 ./tests/test_a.cpp
|
|
cat > ./tests/test_"$filename".cpp <<EOF
|
|
#include <gtest/gtest.h>
|
|
#include <solution/$filename.h>
|
|
EOF
|