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

📄 ee.c

📁 EE Text Editor in standard UNIX
💻 C
📖 第 1 页 / 共 5 页
字号:
		wmove(com_win, 0, 0);		wclrtoeol(com_win);		wprintw(com_win, "written by Hugh Mahon");	}	else if (compare(cmd_str, VERSION, FALSE))	{		wmove(com_win, 0, 0);		wclrtoeol(com_win);		wprintw(com_win, "%s", version);	}	else if (compare(cmd_str, CASE, FALSE))		case_sen = TRUE;	else if (compare(cmd_str, NOCASE, FALSE))		case_sen = FALSE;	else if (compare(cmd_str, EXPAND, FALSE))		expand_tabs = TRUE;	else if (compare(cmd_str, NOEXPAND, FALSE))		expand_tabs = FALSE;	else if (compare(cmd_str, Exit_string, FALSE))		finish();	else if (compare(cmd_str, chinese_cmd, FALSE))	{		ee_chinese = TRUE;#ifdef NCURSE		nc_setattrib(A_NC_BIG5);#endif /* NCURSE */	}	else if (compare(cmd_str, nochinese_cmd, FALSE))	{		ee_chinese = FALSE;#ifdef NCURSE		nc_clearattrib(A_NC_BIG5);#endif /* NCURSE */	}	else if (compare(cmd_str, QUIT_string, FALSE))		quit(0);	else if (*cmd_str == '!')	{		cmd_str++;		if ((*cmd_str == ' ') || (*cmd_str == 9))			cmd_str = next_word(cmd_str);		sh_command(cmd_str);	}	else if ((*cmd_str == '<') && (!in_pipe))	{		in_pipe = TRUE;		shell_fork = FALSE;		cmd_str++;		if ((*cmd_str == ' ') || (*cmd_str == '\t'))			cmd_str = next_word(cmd_str);		command(cmd_str);		in_pipe = FALSE;		shell_fork = TRUE;	}	else if ((*cmd_str == '>') && (!out_pipe))	{		out_pipe = TRUE;		cmd_str++;		if ((*cmd_str == ' ') || (*cmd_str == '\t'))			cmd_str = next_word(cmd_str);		command(cmd_str);		out_pipe = FALSE;	}	else	{		wmove(com_win, 0, 0);		wclrtoeol(com_win);		wprintw(com_win, unkn_cmd_str, cmd_str);	}	if (cmd_str2 != NULL)		free(cmd_str2);}int scan(line, offset, column)	/* determine horizontal position for get_string	*/char *line;int offset;int column;{	char *stemp;	int i;	int j;	stemp = line;	i = 0;	j = column;	while (i < offset)	{		i++;		j += len_char(*stemp, j);		stemp++;	}	return(j);}char *get_string(prompt, advance)	/* read string from input on command line */char *prompt;		/* string containing user prompt message	*/int advance;		/* if true, skip leading spaces and tabs	*/{	char *string;	char *tmp_string;	char *nam_str;	char *g_point;	int tmp_int;	int g_horz, g_position, g_pos;	int esc_flag;	g_point = tmp_string = malloc(512);	wmove(com_win,0,0);	wclrtoeol(com_win);	waddstr(com_win, prompt);	wrefresh(com_win);	nam_str = tmp_string;	clear_com_win = TRUE;	g_horz = g_position = scan(prompt, strlen(prompt), 0);	g_pos = 0;	do	{		esc_flag = FALSE;		in = wgetch(com_win);		if (in == -1)			exit(0);		if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))		{			tmp_int = g_horz;			g_pos--;			g_horz = scan(g_point, g_pos, g_position);			tmp_int = tmp_int - g_horz;			for (; 0 < tmp_int; tmp_int--)			{				if ((g_horz+tmp_int) < (last_col - 1))				{					waddch(com_win, '\010');					waddch(com_win, ' ');					waddch(com_win, '\010');				}			}			nam_str--;		}		else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))		{			if (in == '\026')	/* control-v, accept next character verbatim	*/			{			/* allows entry of ^m, ^j, and ^h	*/				esc_flag = TRUE;				in = wgetch(com_win);				if (in == -1)					exit(0);			}			*nam_str = in;			g_pos++;			if (((in < ' ') || (in > 126)) && (g_horz < (last_col - 1)))				g_horz += out_char(com_win, in, g_horz);			else			{				g_horz++;				if (g_horz < (last_col - 1))					waddch(com_win, in);			}			nam_str++;		}		wrefresh(com_win);		if (esc_flag)			in = (char) NULL;	} while ((in != '\n') && (in != '\r'));	*nam_str = (char) NULL;	nam_str = tmp_string;	if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))		nam_str = next_word(nam_str);	string = malloc(strlen(nam_str) + 1);	strcpy(string, nam_str);	free(tmp_string);	wrefresh(com_win);	return(string);}int compare(string1, string2, sensitive)	/* compare two strings	*/char *string1;char *string2;int sensitive;{	char *strng1;	char *strng2;	int tmp;	int equal;	strng1 = string1;	strng2 = string2;	tmp = 0;	if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == (char) NULL) || (*strng2 == (char) NULL))		return(FALSE);	equal = TRUE;	while (equal)	{		if (sensitive)		{			if (*strng1 != *strng2)				equal = FALSE;		}		else		{			if (toupper(*strng1) != toupper(*strng2))				equal = FALSE;		}		strng1++;		strng2++;		if ((*strng1 == (char) NULL) || (*strng2 == (char) NULL) || (*strng1 == ' ') || (*strng2 == ' '))			break;		tmp++;	}	return(equal);}void goto_line(cmd_str)char *cmd_str;{	int number;	int i;	char *ptr;	char *direction;	struct text *t_line;	ptr = cmd_str;	i= 0;	while ((*ptr >='0') && (*ptr <= '9'))	{		i= i * 10 + (*ptr - '0');		ptr++;	}	number = i;	i = 0;	t_line = curr_line;	while ((t_line->line_number > number) && (t_line->prev_line != NULL))	{		i++;		t_line = t_line->prev_line;		direction = "u";	}	while ((t_line->line_number < number) && (t_line->next_line != NULL))	{		i++;		direction = "d";		t_line = t_line->next_line;	}	if ((i < 30) && (i > 0))	{		move_rel(direction, i);	}	else	{		curr_line = t_line;		point = curr_line->line;		position = 1;		midscreen((last_line / 2), point);		scr_pos = scr_horz;	}	wmove(com_win, 0, 0);	wclrtoeol(com_win);	wprintw(com_win, line_num_str, curr_line->line_number);	wmove(text_win, scr_vert, (scr_horz - horiz_offset));}void midscreen(line, pnt)	/* put current line in middle of screen	*/int line;unsigned char *pnt;{	struct text *mid_line;	int i;	line = min(line, last_line);	mid_line = curr_line;	for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)		curr_line = curr_line->prev_line;	scr_vert = scr_horz = 0;	wmove(text_win, 0, 0);	draw_screen();	scr_vert = i;	curr_line = mid_line;	scanline(pnt);	wmove(text_win, scr_vert, (scr_horz - horiz_offset));}void get_options(numargs, arguments)	/* get arguments from command line	*/int numargs;char *arguments[];{	char *buff;	int count;	struct files *temp_names;	char *name;	char *ptr;	int no_more_opts = FALSE;	/*	 |	see if editor was invoked as 'ree' (restricted mode)	 */	if (!(name = strrchr(arguments[0], '/')))		name = arguments[0];	else		name++;	if (!strcmp(name, "ree"))		restricted = TRUE;	top_of_stack = NULL;	input_file = FALSE;	recv_file = FALSE;	count = 1;	while ((count < numargs)&& (!no_more_opts))	{		buff = arguments[count];		if (!strcmp("-i", buff))		{			info_window = FALSE;		}		else if (!strcmp("-e", buff))		{			expand_tabs = FALSE;		}		else if (!strcmp("-h", buff))		{			nohighlight = TRUE;		}		else if (!strcmp("-?", buff))		{			fprintf(stderr, usage0, arguments[0]);			fprintf(stderr, usage1);			fprintf(stderr, usage2);			fprintf(stderr, usage3);			fprintf(stderr, usage4);			exit(1);		}		else if ((*buff == '+') && (start_at_line == NULL))		{			buff++;			start_at_line = buff;		}		else if (!(strcmp("--", buff)))			no_more_opts = TRUE;		else		{			count--;			no_more_opts = TRUE;		}		count++;	}	while (count < numargs)	{		buff = arguments[count];		if (top_of_stack == NULL)		{			temp_names = top_of_stack = name_alloc();		}		else		{			temp_names->next_name = name_alloc();			temp_names = temp_names->next_name;		}		ptr = temp_names->name = malloc(strlen(buff) + 1);		while (*buff != (char) NULL)		{			*ptr = *buff;			buff++;			ptr++;		}		*ptr = (char) NULL;		temp_names->next_name = NULL;		input_file = TRUE;		recv_file = TRUE;		count++;	}}void check_fp()		/* open or close files according to flags */{	int line_num;	int temp;	struct stat buf;	clear_com_win = TRUE;	tmp_vert = scr_vert;	tmp_horz = scr_horz;	tmp_line = curr_line;	if (input_file)	{		in_file_name = tmp_file = top_of_stack->name;		top_of_stack = top_of_stack->next_name;	}	temp = stat(tmp_file, &buf);	buf.st_mode &= ~07777;	if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))	{		wprintw(com_win, file_is_dir_msg, tmp_file);		wrefresh(com_win);		if (input_file)		{			quit(0);			return;		}		else			return;	}	if ((get_fd = open(tmp_file, O_RDONLY)) == -1)	{		wmove(com_win, 0, 0);		wclrtoeol(com_win);		if (input_file)			wprintw(com_win, new_file_msg, tmp_file);		else			wprintw(com_win, cant_open_msg, tmp_file);		wrefresh(com_win);		wmove(text_win, scr_vert, (scr_horz - horiz_offset));		wrefresh(text_win);		recv_file = FALSE;		input_file = FALSE;		return;	}	else		get_file(tmp_file);	recv_file = FALSE;	line_num = curr_line->line_number;	scr_vert = tmp_vert;	scr_horz = tmp_horz;	if (input_file)		curr_line= first_line;	else		curr_line = tmp_line;	point = curr_line->line;	draw_screen();	if (input_file)	{		input_file = FALSE;		if (start_at_line != NULL)		{			line_num = atoi(start_at_line) - 1;			move_rel("d", line_num);			line_num = 0;			start_at_line = NULL;		}	}	else	{		wmove(com_win, 0, 0);		wclrtoeol(com_win);		text_changes = TRUE;		if ((tmp_file != NULL) && (*tmp_file != (char) NULL))			wprintw(com_win, file_read_fin_msg, tmp_file);	}	wrefresh(com_win);	wmove(text_win, scr_vert, (scr_horz - horiz_offset));	wrefresh(text_win);}void get_file(file_name)	/* read specified file into current buffer	*/char *file_name;{	int can_read;		/* file has at least one character	*/	int length;		/* length of line read by read		*/	int append;		/* should text be appended to current line */	struct text *temp_line;	char ro_flag = FALSE;	if (recv_file)		/* if reading a file			*/	{		wmove(com_win, 0, 0);		wclrtoeol(com_win);		wprintw(com_win, reading_file_msg, file_name);		if (access(file_name, 2))	/* check permission to write */		{			if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))			{				wprintw(com_win, read_only_msg);				ro_flag = TRUE;			}		}		wrefresh(com_win);	}	if (curr_line->line_length > 1)	/* if current line is not blank	*/	{		insert_line(FALSE);		left(FALSE);		append = FALSE;	}	else		append = TRUE;	can_read = FALSE;		/* test if file has any characters  */	while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))	{		can_read = TRUE;  /* if set file has at least 1 character   */		get_line(length, in_string, &append);	}	if ((can_read) && (curr_line->line_length == 1))	{		temp_line = curr_line->prev_line;		temp_line->next_line = curr_line->next_line;		if (temp_line->next_line != NULL)			temp_line->next_line->prev_line = temp_line;		if (curr_line->line != NULL)			free(curr_line->line);		free(curr_line);		curr_line = temp_line;	}	if (input_file)	/* if this is the file to be edited display number of lines	*/	{		wmove(com_win, 0, 0);		wclrtoeol(com_win);		wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);		if (ro_flag)			wprintw(com_win, read_only_msg);		wrefresh(com_win);	}	else if (can_read)	/* not input_file and file is non-zero size */		text_changes = TRUE;	if (recv_file)		/* if reading a file			*/	{		in = EOF;	}}void get_line(length, in_string, append)	/* read string and split into lines */int length;		/* length of string read by read		*/unsigned char *in_string;	/* string read by read				*/int *append;	/* TRUE if must append more text to end of current line	*/{	unsigned char *str1;	unsigned char *str2;	int num;		/* offset from start of string		*/	int char_count;		/* length of new line (or added portion	*/	int temp_counter;	/* temporary counter value		*/	struct text *tline;	/* temporary pointer to new line	*/	int first_time;		/* if TRUE, the first time through the loop */	str2 = in_string;	num = 0;	first_time = TRUE;	while (num < length)	{		if (!first_time)		{			if (num < length)			{				str2++;				num++;			}		}		else			first_time = FALSE;		str1 = str2;		char_count = 1;		/* find end of line	*/		while ((*str2 != '\n') && (num < length))		{			str2++;			num++;			char_count++;		}		if (!(*append))	/* if not append to current line, insert new one */		{			tline = txtalloc();	/* allocate data structure for next line */			tline->line_number = curr_line->line_number + 1;			tline->next_line = curr_line->next_line;			tline->prev_line = curr_line;			curr_line->next_line = tline;			if (tline->next_line != NULL)				tline->next_line->prev_line = tline;			curr_line = tline;			curr_line->line = point = (unsigned char *) malloc(char_count);			curr_line->line_length = char_count;			curr_line->max_length = char_count;		}		else		{			point = resiz_line(char_count, curr_line, curr_line->line_length); 			curr_line->line_length += (char_count - 1);		}		for (temp_counter = 1; temp_counter < char_count; temp_counter++)

⌨️ 快捷键说明

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