开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from OneOS/OneOS
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (7)
标签 (4)
master
OneOS-V2.3.0
OneOS-V2.2.0
OneOS-V2.1.0
OneOS-V2.0.0-Beta
OneOS-V2.0.1
OneOS-V1.2.0-LTS
OneOS-v2.3.0
OneOS-v2.2.0
OneOS-V1.2.0
OneOS-V1.1.0
master
分支 (7)
标签 (4)
master
OneOS-V2.3.0
OneOS-V2.2.0
OneOS-V2.1.0
OneOS-V2.0.0-Beta
OneOS-V2.0.1
OneOS-V1.2.0-LTS
OneOS-v2.3.0
OneOS-v2.2.0
OneOS-V1.2.0
OneOS-V1.1.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (7)
标签 (4)
master
OneOS-V2.3.0
OneOS-V2.2.0
OneOS-V2.1.0
OneOS-V2.0.0-Beta
OneOS-V2.0.1
OneOS-V1.2.0-LTS
OneOS-v2.3.0
OneOS-v2.2.0
OneOS-V1.2.0
OneOS-V1.1.0
OneOS
/
components
/
shell
/
source
/
shell_process.c
OneOS
/
components
/
shell
/
source
/
shell_process.c
shell_process.c 14.06 KB
一键复制 编辑 原始数据 按行查看 历史
zhouping1 提交于 2022年04月21日 11:39 +08:00 . update OneOS-V2.2.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
/**
***********************************************************************************************************************
* Copyright (c) 2020, China Mobile Communications Group Co.,Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* @file shell_process.c
*
* @brief Process shell command.
*
* @revision
* Date Author Notes
* 2020年04月10日 OneOS Team First version.
***********************************************************************************************************************
*/
#include <oneos_config.h>
#include <shell.h>
#include <os_util.h>
#include <os_memory.h>
#include <os_assert.h>
#include <os_errno.h>
#include <string.h>
#ifdef OS_USING_VFS
#include <unistd.h>
#include <dirent.h>
#endif
#include "shell_internal.h"
#ifdef OS_USING_SHELL
static os_int32_t sh_split(char *cmd, os_size_t length, char *argv[SHELL_ARG_MAX])
{
char *ptr;
os_size_t position;
os_size_t argc;
os_size_t i;
ptr = cmd;
position = 0;
argc = 0;
while (position < length)
{
/* Strip bank and tab */
while (((*ptr == ' ') || (*ptr == '\t')) && position < length)
{
*ptr = '0円';
ptr++;
position++;
}
if (position >= length)
{
break;
}
if (argc >= SHELL_ARG_MAX)
{
os_kprintf("Too many args ! We only Use:\r\n");
for (i = 0; i < argc; i++)
{
os_kprintf("%s ", argv[i]);
}
os_kprintf("\r\n");
break;
}
/* Handle string */
if (*ptr == '"')
{
ptr++;
position++;
argv[argc] = ptr;
argc++;
/* Skip this string */
while (('"' != *ptr) && (position < length))
{
if ('\\' == *ptr)
{
if ('"' == *(ptr + 1))
{
ptr++;
position++;
}
}
ptr++;
position++;
}
if (position >= length)
{
break;
}
/* Skip '"' */
*ptr = '0円';
ptr++;
position++;
}
else
{
argv[argc] = ptr;
argc++;
while ((*ptr != ' ') && (*ptr != '\t') && (position < length))
{
ptr++;
position++;
}
if (position >= length)
{
break;
}
}
}
return argc;
}
static cmd_function_t sh_get_cmd_func(char *cmd, os_int32_t size)
{
sh_cmd_entry_t *syscall_tmp;
sh_cmd_entry_t *table_begin;
sh_cmd_entry_t *table_end;
cmd_function_t cmd_func;
os_uint16_t cmd_prefix_len;
cmd_func = OS_NULL;
sh_get_cmd_table(&table_begin, &table_end);
cmd_prefix_len = strlen("__cmd_");
for (syscall_tmp = table_begin; syscall_tmp < table_end; SH_NEXT_CMD_ENTRY(syscall_tmp))
{
if (strncmp(syscall_tmp->name, "__cmd_", cmd_prefix_len))
{
continue;
}
if (!strncmp(&syscall_tmp->name[cmd_prefix_len], cmd, size) &&
(syscall_tmp->name[cmd_prefix_len + size] == '0円'))
{
cmd_func = (cmd_function_t)syscall_tmp->func;
break;
}
}
return cmd_func;
}
static os_err_t sh_do_exec_cmd(char *cmd, os_size_t length, os_err_t *retp)
{
os_int32_t argc;
os_size_t cmd0_size;
cmd_function_t cmd_func;
char *argv[SHELL_ARG_MAX];
os_err_t ret;
OS_ASSERT(cmd);
OS_ASSERT(retp);
ret = OS_EOK;
cmd0_size = 0U;
/* Find the size of first command */
while ((cmd[cmd0_size] != ' ') && (cmd[cmd0_size] != '\t') && (cmd0_size < length))
{
cmd0_size++;
}
if (0U == cmd0_size)
{
os_kprintf("cmd 0 size \r\n");
ret = OS_ERROR;
}
else
{
(void)memset(argv, 0, sizeof(argv));
cmd_func = sh_get_cmd_func(cmd, cmd0_size);
argc = sh_split(cmd, length, argv);
if ((OS_NULL != cmd_func) && (0 != argc))
{
*retp = cmd_func(argc, argv);
}
else
{
ret = OS_ERROR;
}
}
return ret;
}
/**
***********************************************************************************************************************
* @brief Execute command.
*
* @param[in] cmd Command string, including command name and command arguments.
* @param[in] length Command string length.
*
* @return Execute command result.
* @retval OS_EOK Execute command success.
* @retval else Execute command failed.
***********************************************************************************************************************
*/
os_err_t sh_do_exec(char *cmd, os_size_t length)
{
char *tcmd;
os_err_t cmd_ret;
os_err_t ret;
ret = OS_EOK;
/* Strim the beginning of command */
while (((*cmd == ' ') || (*cmd == '\t')) && (length > 0))
{
cmd++;
length--;
}
if (length > 0)
{
ret = sh_do_exec_cmd(cmd, length, &cmd_ret);
if (OS_EOK == ret)
{
ret = cmd_ret;
}
else
{
/* Truncate the cmd at the first space. */
tcmd = cmd;
while ((*tcmd != ' ') && (*tcmd != '0円'))
{
tcmd++;
}
*tcmd = '0円';
os_kprintf("%s: command not found.\r\n", cmd);
}
}
return ret;
}
os_err_t sh_exec(const char *cmd)
{
char *cmd_str;
os_size_t cmd_length;
os_err_t ret;
OS_ASSERT(cmd != OS_NULL);
ret = OS_EOK;
cmd_length = strlen(cmd);
/* 1 is used to reserve space for '0円' */
cmd_str = (char *)os_malloc(cmd_length + 1);
if (OS_NULL == cmd_str)
{
ret = OS_ENOMEM;
}
else
{
(void)strcpy(cmd_str, cmd);
/* Here, the length of cmd is not contain '0円' */
ret = sh_do_exec(cmd_str, cmd_length);
os_free(cmd_str);
cmd_str = OS_NULL;
}
return ret;
}
static os_int32_t sh_string_same_part_length(const char *cmd_str1, const char *cmd_str2)
{
const char *cmd_str_tmp;
cmd_str_tmp = cmd_str1;
while ((*cmd_str_tmp != 0) && (*cmd_str2 != 0) && (*cmd_str_tmp == *cmd_str2))
{
cmd_str_tmp++;
cmd_str2++;
}
return (cmd_str_tmp - cmd_str1);
}
#ifdef OS_USING_VFS
static void sh_do_auto_complete_path(char *path, os_size_t size)
{
#define FULL_PATH_LEN_MAX 256
DIR *dir = OS_NULL;
struct dirent *dirent = OS_NULL;
char *full_path;
char *ptr;
char *index;
char *end_addr = path + size;
OS_ASSERT(OS_NULL != path);
full_path = (char *)os_malloc(FULL_PATH_LEN_MAX);
if (OS_NULL == full_path)
{
/* Out of memory */
os_kprintf("Malloc memory of full_path failed\r\n");
return;
}
memset(full_path, 0, FULL_PATH_LEN_MAX);
if (*path != '/')
{
getcwd(full_path, FULL_PATH_LEN_MAX);
if (full_path[strlen(full_path) - 1] != '/')
{
strcat(full_path, "/");
}
}
else
{
*full_path = '0円';
}
index = OS_NULL;
ptr = path;
for (;;)
{
if (*ptr == '/')
{
index = ptr + 1;
}
if (!(*ptr))
{
break;
}
ptr++;
}
if (OS_NULL == index)
{
index = path;
}
if (OS_NULL != index)
{
char *dest;
dest = index;
/* Fill the parent path */
ptr = full_path;
while (*ptr)
{
ptr++;
}
for (index = path; index != dest;)
{
*ptr++ = *index++;
}
*ptr = '0円';
dir = opendir(full_path);
if (OS_NULL == dir)
{
/* Open directory failed! */
os_free(full_path);
return;
}
/* Restore the index position */
index = dest;
}
/* Auto complete the file or directory name */
if ('0円' == *index)
{
/* Display all of files and directories */
for (;;)
{
dirent = readdir(dir);
if (OS_NULL == dirent)
{
break;
}
os_kprintf("%s\r\n", dirent->d_name);
}
}
else
{
os_size_t length;
os_size_t min_length;
min_length = 0;
for (;;)
{
dirent = readdir(dir);
if (OS_NULL == dirent)
{
break;
}
/* Matched the prefix string */
if (!strncmp(index, dirent->d_name, strlen(index)))
{
os_kprintf("%s\r\n", dirent->d_name);
if (0 == min_length)
{
min_length = strlen(dirent->d_name);
/* Save dirent name */
strncpy(full_path, dirent->d_name, FULL_PATH_LEN_MAX);
}
length = sh_string_same_part_length(dirent->d_name, full_path);
if (length < min_length)
{
min_length = length;
}
}
}
if (min_length)
{
if ((index + min_length + 1) >= end_addr)
{
min_length = end_addr - index - 1;
}
memcpy(index, full_path, min_length);
index[min_length] = '0円';
}
}
closedir(dir);
os_free(full_path);
#undef FULL_PATH_LEN_MAX
}
static os_bool_t sh_auto_complete_path(char *prefix, os_size_t size)
{
char *ptr;
const char *end_addr;
os_bool_t is_complete_path;
is_complete_path = OS_FALSE;
end_addr = prefix + size;
ptr = prefix + strlen(prefix);
/* Check whether a space in the prefix */
while (ptr != prefix)
{
if (*ptr == ' ')
{
is_complete_path = OS_TRUE;
sh_do_auto_complete_path(ptr + 1, end_addr - (ptr + 1));
break;
}
ptr--;
}
return is_complete_path;
}
#endif /* OS_USING_VFS */
/**
***********************************************************************************************************************
* @brief Auto complete the path name or command name.
*
* @param[in,out] prefix The prefix of path or command.
* @param[in] size The size of buffer.
*
* @return None.
***********************************************************************************************************************
*/
void sh_auto_complete(char *prefix, os_size_t size)
{
os_int32_t length;
os_int32_t min_length;
sh_cmd_entry_t *syscall_tmp;
sh_cmd_entry_t *syscall_begin;
sh_cmd_entry_t *syscall_end;
const char *name_ptr;
const char *cmd_name;
os_bool_t is_complete_path;
os_bool_t is_null_str;
os_kprintf("\r\n");
is_complete_path = OS_FALSE;
is_null_str = OS_FALSE;
if (*prefix == '0円')
{
sh_exec("help");
is_null_str = OS_TRUE;
}
#ifdef OS_USING_VFS
is_complete_path = sh_auto_complete_path(prefix, size);
#endif
if ((OS_FALSE == is_null_str) && (OS_FALSE == is_complete_path))
{
min_length = 0;
name_ptr = OS_NULL;
/* Checks in internal command */
sh_get_cmd_table(&syscall_begin, &syscall_end);
for (syscall_tmp = syscall_begin; syscall_tmp < syscall_end; SH_NEXT_CMD_ENTRY(syscall_tmp))
{
/* Skip shell function */
if (strncmp(syscall_tmp->name, "__cmd_", 6))
{
continue;
}
cmd_name = &syscall_tmp->name[6];
if (!strncmp(prefix, cmd_name, strlen(prefix)))
{
if (0 == min_length)
{
/* Set name_ptr */
name_ptr = cmd_name;
/* Set initial length */
min_length = strlen(name_ptr);
os_kprintf("\r\n");
os_kprintf("%s\r\n", cmd_name);
}
else
{
length = sh_string_same_part_length(name_ptr, cmd_name);
if (length < min_length)
{
min_length = length;
}
os_kprintf("%s\r\n", cmd_name);
}
}
}
/* Auto complete string */
if (OS_NULL != name_ptr)
{
min_length = (min_length > size) ? size : min_length;
strncpy(prefix, name_ptr, min_length);
}
}
os_kprintf("%s%s", sh_get_prompt(), prefix);
return;
}
#endif /* OS_USING_SHELL */
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

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

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

取消
提交

简介

OneOS是中国移动针对物联网领域推出的轻量级操作系统,具有可裁剪、跨平台、低功耗、高安全等特点,支持ARM Cortex-M/R/A、MIPS、RISC-V等主流CPU架构,兼容POSIX、CMSIS等标准接口,支持Micropython语言开发,提供图形化开发工具,能够有效提高开发效率并降低开发成本,帮助客户开发稳定可靠、安全易用的物联网应用。 官网地址:https://os.iot.10086.cn/
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/MicroOS/OneOS.git
git@gitee.com:MicroOS/OneOS.git
MicroOS
OneOS
OneOS
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

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