cd_func.c

来自「阿基米德操作系统的源代码」· C语言 代码 · 共 62 行

C
62
字号

//////////////////////////////////////////////////////////////////////////
#include "general.h"
#include "s_isdirreg.h"
#include "the_syscalls.h"

#include "shell_head.h"
//////////////////////////////////////////////////////////////////////////
int CD_Func(void)
{
	int    temp_index;
	char * temp_pChar;
	int	   temp_Ret;
	int	   i;

	if ((command_params == 0) || (command_params > 1))
	{
		the_screen_call18("\n\r    CD bad parameters!");
		return -1;
	}

	temp_index = command_index + 1;
	while (command_buf[temp_index])
	{
		if ((command_buf[temp_index] == '/') ||
			(command_buf[temp_index] == ':') ||
			(command_buf[temp_index] == '|') ||
			(command_buf[temp_index] == '*') ||
			(command_buf[temp_index] == '?'))
		{
			the_screen_call18("\n\r    CD bad parameters!");
			return -1;
		}		
		temp_index++;
	}

	if (temp_index - command_index - 1 + pathbuf_length > 240)
	{
		the_screen_call18("\n\r    CD bad parameters!");
		return -1;
	}
	
	temp_pChar = command_buf + command_index + 1;
	temp_Ret   = the_file_chdir(temp_pChar,path0_buf,256);
	if (temp_Ret < 0)
	{
		the_screen_call18("\n\r    CD bad parameters!");
		return -1;
	}

	for (i = 0; i < temp_Ret + 3; i++)
		path_buf[i] = path0_buf[i];

	pathbuf_length = temp_Ret;

	return 0;
}

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?