⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copy_func.c

📁 阿基米德操作系统的源代码
💻 C
字号:

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

#include "shell_head.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
int COPY_Func(void)
{
	int		temp_src_driver, temp_dest_driver;
	int		temp_src_no, temp_dest_no;

	int		temp_index, temp_index0;
	int		temp_flag;
	char  * temp_pChar;
	int		temp_filesize;
	int		temp_filesum;
	int		temp_Ret,temp_Ret0;

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

	temp_src_driver = temp_dest_driver = shell_driver;

	temp_index	= command_index;
	if (command_buf[temp_index + 2] == ':')
	{
		temp_flag	= 0;
		if ((command_buf[temp_index + 1] >= 'a') && (command_buf[temp_index + 1] <= 'z'))
		{
			temp_src_driver = command_buf[temp_index + 1] - 'a';
			temp_flag = 1;
		}
		if ((command_buf[temp_index + 1] >= 'A') && (command_buf[temp_index + 1] <= 'Z'))
		{
			temp_src_driver = command_buf[temp_index + 1] - 'A';
			temp_flag = 1;
		}
		if (temp_flag != 0)
		{
			command_buf[temp_index + 2] = command_buf[temp_index];
			command_index = command_index + 2;
		}
	}

	if (command_params == 2)
	{
		temp_index	= command_buf[temp_index];
		if (command_buf[temp_index + 2] == ':')
		{
			temp_flag	= 0;
			if ((command_buf[temp_index + 1] >= 'a') && (command_buf[temp_index + 1] <= 'z'))
			{
				temp_dest_driver = command_buf[temp_index + 1] - 'a';
				temp_flag = 1;
			}
			if ((command_buf[temp_index + 1] >= 'A') && (command_buf[temp_index + 1] <= 'Z'))
			{
				temp_dest_driver = command_buf[temp_index + 1] - 'A';
				temp_flag = 1;
			}
			if (temp_flag != 0)
			{
				command_buf[temp_index + 2] = command_buf[temp_index];
				command_buf[command_index]	= command_buf[command_index] + 2;
			}
		}
	}

	if ((temp_src_driver == 1) || (temp_dest_driver == 1))
	{
		the_screen_call18("\n\r    COPY bad parameters!");
		return -1;
	}

	///////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////
	temp_index = command_index + 1;
	while (command_buf[temp_index] != 0)
	{
		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    COPY bad parameters!");
			return -1;
		}
		temp_index++;
	}

	if (command_params == 2)
	{
		temp_index = command_buf[command_index] + 1;
		while (command_buf[temp_index] != 0)
		{
			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    COPY bad parameters!");
				return -1;
			}
			temp_index++;
		}
	}

	///////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////
	if (temp_src_driver != shell_driver)
	{
		temp_Ret = the_file_chdriver(temp_src_driver, path0_buf, 256);
		if (temp_Ret < 0)
		{
			temp_Ret = the_file_getpath(path0_buf, 256, NULL);
			for (temp_index = 0; temp_index < temp_Ret + 3; temp_index++)
				path_buf[temp_index] = path0_buf[temp_index];
			pathbuf_length = temp_Ret;

			the_screen_call18("\n\r    COPY bad parameters!");
			return -1;
		}
	}

	///////////////////////////////////////////////////////
	temp_pChar	= command_buf + command_index + 1;
	temp_Ret	= the_file_openEX(temp_pChar, O_RDONLY, 0, dir_buffer, 256);
	if (temp_Ret < 0)
	{
		if (temp_src_driver != shell_driver)
			temp_Ret = the_file_chdriver(shell_driver, path0_buf, 256);
		else
			temp_Ret = the_file_getpath(path0_buf, 256, NULL);
		for (temp_index = 0; temp_index < temp_Ret + 3; temp_index++)
			path_buf[temp_index] = path0_buf[temp_index];
		pathbuf_length = temp_Ret;

		the_screen_call18("\n\r    COPY bad parameters!");
		return -1;
	}
	temp_src_no		= temp_Ret;
	command_index	= command_buf[command_index];
	command_params	= command_params - 1;

	///////////////////////////////////////////////////////
	if (temp_dest_driver != temp_src_driver)
	{
		temp_Ret = the_file_chdriver(temp_dest_driver, path0_buf, 256);
		if (temp_Ret < 0)
		{
			the_file_close(temp_src_no);

			if (temp_src_driver != shell_driver)
				temp_Ret = the_file_chdriver(shell_driver, path0_buf, 256);
			else
				temp_Ret = the_file_getpath(path0_buf, 256, NULL);
			for (temp_index = 0; temp_index < temp_Ret + 3; temp_index++)
				path_buf[temp_index] = path0_buf[temp_index];
			pathbuf_length = temp_Ret;

			the_screen_call18("\n\r    COPY bad parameters!");
			return -1;
		}
	}

	///////////////////////////////////////////////////////
	temp_index		= 0;
	command_buf[0]	= 0;
	command_index	= command_index + 1;
	if (command_params != 0)
	{
		while (command_buf[command_index] != 0)
			command_buf[temp_index++] = command_buf[command_index++];
		command_buf[temp_index] = 0;
	}

	///////////////////////////////////////////////////////
	temp_flag = 0;
	if ((!temp_index) || (command_buf[temp_index - 1] == '\\'))
		temp_flag = 1;
	if (((temp_index == 1) && (command_buf[0] == '.')) || 
		((temp_index == 2) && (command_buf[0] == '.') && (command_buf[1] == '.')) ||
		((temp_index >= 2) && (command_buf[temp_index - 2] == '\\') && (command_buf[temp_index - 1] == '.')) ||
		((temp_index >= 3) && (command_buf[temp_index - 3] == '\\') && (command_buf[temp_index - 2] == '.') && (command_buf[temp_index - 1] == '.')))
	{
		command_buf[temp_index++]	= '\\';
		command_buf[temp_index]		= 0;
		temp_flag = 1;
	}

	///////////////////////////////////////////////////////
	if (!temp_flag)
	{
		temp_pChar	= command_buf;
		temp_Ret	= the_file_open(temp_pChar, (O_TRUNC | O_CREAT | O_WRONLY), (I_WRITE | I_READ));
		if (temp_Ret < 0)
		{
			command_buf[temp_index++]	= '\\';
			command_buf[temp_index]		= 0;
			temp_flag = 1;
		}
	}

	///////////////////////////////////////////////////////
	if (temp_flag != 0)
	{
		temp_index0 = 0;
		while (dir_buffer[temp_index0] != 0)
			command_buf[temp_index++] = dir_buffer[temp_index0++];
		command_buf[temp_index] = 0;

		temp_pChar	= command_buf;
		temp_Ret	= the_file_open(temp_pChar, (O_TRUNC | O_CREAT | O_WRONLY), (I_WRITE | I_READ));
	}
	
	///////////////////////////////////////////////////////
	if (temp_Ret < 0)
	{
		the_file_close(temp_src_no);
		
		if (temp_dest_driver != shell_driver)
			temp_Ret = the_file_chdriver(shell_driver, path0_buf, 256);
		else
			temp_Ret = the_file_getpath(path0_buf, 256, NULL);
		for (temp_index = 0; temp_index < temp_Ret + 3; temp_index++)
			path_buf[temp_index] = path0_buf[temp_index];
		pathbuf_length = temp_Ret;

		the_screen_call18("\n\r    COPY bad parameters!");
		return -1;
	}
	temp_dest_no = temp_Ret;

	//////////////////////////////////////////////
	temp_filesize = the_file_getsize(temp_src_no);
	temp_filesum  = 0;

	temp_Ret	  = the_file_read(temp_src_no, dir_buffer, 1024);
	while (temp_Ret != 0)
	{
		temp_Ret0		= the_file_write(temp_dest_no, dir_buffer, temp_Ret);
		temp_filesum	= temp_filesum + temp_Ret0;
		if (temp_Ret0  != temp_Ret)
			break;
		temp_Ret		= the_file_read(temp_src_no, dir_buffer, 1024);
	}

	if (temp_filesum != temp_filesize)
		the_screen_call18("\n\r    COPY have errors!");

	//////////////////////////////////////////////
	the_file_close(temp_src_no);
	the_file_close(temp_dest_no);
	if (temp_dest_driver != shell_driver)
		temp_Ret = the_file_chdriver(shell_driver, path0_buf, 256);
	else
		temp_Ret = the_file_getpath(path0_buf, 256, NULL);
	for (temp_index = 0; temp_index < temp_Ret + 3; temp_index++)
		path_buf[temp_index] = path0_buf[temp_index];
	pathbuf_length = temp_Ret;
	//////////////////////////////////////////////

	return 0;
}

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

⌨️ 快捷键说明

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