Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (3)
Tags (5)
master
user-defined-rule
clang
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (3)
Tags (5)
master
user-defined-rule
clang
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (3)
Tags (5)
master
user-defined-rule
clang
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
cpps
/
src
/
run.cpp
cpps
/
src
/
run.cpp
run.cpp 2.76 KB
Copy Edit Raw Blame History
duyanning authored 2022年01月17日 22:47 +08:00 . 改个错别字, 注释里的
#include "config.h"
#include "global.h"
#include "ArgvQuote.h"
void run()
{
if (run_by == "exec") {
MINILOG0("run using execv()");
char** script_argv = original_argv + script_pos;
//const char* const env[] = { exec_cmd_env_vars.c_str(),
// nullptr };
// 复制父进程(cpps)的环境变量
char** env;
{
extern char** environ;
// 测算environ所指数组的长度
int n = 0;
for (char** p = environ; *p; p++) {
n++;
}
// 为复制环境变量分配内存
env = new char* [n + 1 + 1]; // 1个是exec_cmd_env_vars, 1个是最后的nullptr
// 复制
int i = 0;
for (char** p = environ; *p; p++, i++) {
//strcpy(env[i], *p);
env[i] = *p; // 直接指向父进程的环境变量
}
assert(i == n);
// 只为唯一新增的环境变量分配空间
env[i] = new char[exec_cmd_env_vars.length()+1]; // 这片内存没有释放的必要
strcpy(env[i], exec_cmd_env_vars.c_str());
env[i+1] = nullptr;
}
#ifdef _WIN32
for (int i = 0; i < script_argc; i++) {
//cout << "script_argv[" << i << "]: " << script_argv[i] << endl;
string argument{ script_argv[i] };
string quoted_argument;
ArgvQuote(argument, quoted_argument, false);
script_argv[i] = new char[quoted_argument.size() + 1];
strcpy(script_argv[i], quoted_argument.c_str());
}
assert(script_argv[script_argc] == nullptr);
// Windows没有exec功能,但有个_exec函数来模拟exec。
// 可是_exec创建了一个子进程,往往子进程还没有结束,父进程就已经结束了。
// 导致命令行窗口的输出混乱。所以我们用_spawnv。
_spawnve(_P_WAIT, exe_path.string().c_str(), script_argv, env);
#else
execve(exe_path.c_str(), script_argv, const_cast<char* const *>(env));
#endif
//delete[] env; // 没必要, 压根执行不到这
}
else if (run_by == "system") {
MINILOG0("run using system()");
string script_args;
// if (vm.count("args")) {
// for (auto a : vm["args"].as<vector<string>>()) {
// script_args += " '"; // 把脚本的参数用单引号括起来,避免通配符展开。该展开的通配符在解释器执行时已经展开过了
// script_args += a;
// script_args += "'";
// }
// }
for (int i = 1; i < script_argc; i++) {
script_args += " '"; // 把脚本的参数用单引号括起来,避免通配符展开。该展开的通配符在解释器执行时已经展开过了
script_args += original_argv[script_pos + i];
script_args += "'";
}
string cmd_line = exe_path.string();
cmd_line += script_args;
MINILOG0("final cmd line: " << cmd_line);
// 运行产生的可执行文件
system(cmd_line.c_str());
}
else {
cout << "unsupported run-by: " << run_by << endl;
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

C++脚本(伪)解释器/C++项目(零Makefile)构建系统引擎/支持GCC, MinGW, Visual C++, Clang Pseudo Interpreter for C++ Script / C++ Project Build System Engine with Zero Makefiles / Supporting GCC, MinGW, Visual C++, Clang
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/duyanning/cpps.git
git@gitee.com:duyanning/cpps.git
duyanning
cpps
cpps
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /