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

📄 ee.c

📁 EE Text Editor in standard UNIX
💻 C
📖 第 1 页 / 共 5 页
字号:
	shell_fork = TRUE;	strings_init();	ee_init();	if (argc > 0 )		get_options(argc, argv);	set_up_term();	if (right_margin == 0)		right_margin = COLS - 1;	if (top_of_stack == NULL)	{		if (restrict_mode())		{			wmove(com_win, 0, 0);			werase(com_win);			wprintw(com_win, ree_no_file_msg);			wrefresh(com_win);			edit_abort(0);		}		wprintw(com_win, no_file_string);		wrefresh(com_win);	}	else		check_fp();	clear_com_win = TRUE;	counter = 0;	while(edit) 	{		wrefresh(text_win);		in = wgetch(text_win);		if (in == -1)			exit(0);		/*		 |	The above check used to work to detect if the parent 		 |	process died, but now it seems we need a more 		 |	sophisticated check.		 */		if (counter > 50)		{			parent_pid = getppid();			if (parent_pid == 1)				edit_abort(1);			else				counter = 0;		}		else			counter++;				resize_check();		if (clear_com_win)		{			clear_com_win = FALSE;			wmove(com_win, 0, 0);			werase(com_win);			if (!info_window)			{				wprintw(com_win, "%s", com_win_message);			}			wrefresh(com_win);		}		if (in > 255)			function_key();		else if ((in == '\10') || (in == 127))		{			in = 8;		/* make sure key is set to backspace */			delete(TRUE);		}		else if ((in > 31) || (in == 9))			insert(in);		else if ((in >= 0) && (in <= 31))		{			if (emacs_keys_mode)				emacs_control();			else				control();		}	}	return(0);}unsigned char *resiz_line(factor, rline, rpos)	/* resize the line to length + factor*/int factor;		/* resize factor				*/struct text *rline;	/* position in line				*/int rpos;{	unsigned char *rpoint;	int resiz_var; 	rline->max_length += factor;	rpoint = rline->line = realloc(rline->line, rline->max_length );	for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)		rpoint++;	return(rpoint);}void insert(character)		/* insert character into line		*/int character;			/* new character			*/{	int counter;	int value;	unsigned char *temp;	/* temporary pointer			*/	unsigned char *temp2;	/* temporary pointer			*/	if ((character == '\011') && (expand_tabs))	{		counter = len_char('\011', scr_horz);		for (; counter > 0; counter--)			insert(' ');		if (auto_format)			Auto_Format();		return;	}	text_changes = TRUE;	if ((curr_line->max_length - curr_line->line_length) < 5)		point = resiz_line(10, curr_line, position);	curr_line->line_length++;	temp = point;	counter = position;	while (counter < curr_line->line_length)	/* find end of line */	{		counter++;		temp++;	}	temp++;			/* increase length of line by one	*/	while (point < temp)	{		temp2=temp - 1;		*temp= *temp2;	/* shift characters over by one		*/		temp--;	}	*point = character;	/* insert new character			*/	wclrtoeol(text_win);	if (((character >= 0) && (character < ' ')) || (character >= 127)) /* check for TAB character*/	{		scr_pos = scr_horz += out_char(text_win, character, scr_horz);		point++;		position++;	}	else	{		waddch(text_win, character);		scr_pos = ++scr_horz;		point++;		position ++;	}	if ((observ_margins) && (right_margin < scr_pos))	{		counter = position;		while (scr_pos > right_margin)			prev_word();		if (scr_pos == 0)		{			while (position < counter)				right(TRUE);		}		else		{			counter -= position;			insert_line(TRUE);			for (value = 0; value < counter; value++)				right(TRUE);		}	}	if ((scr_horz - horiz_offset) > last_col)	{		horiz_offset += 8;		midscreen(scr_vert, point);	}	if ((auto_format) && (character == ' ') && (!formatted))		Auto_Format();	else if ((character != ' ') && (character != '\t'))		formatted = FALSE;	draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);}void delete(disp)			/* delete character		*/int disp;{	unsigned char *tp;	unsigned char *temp2;	struct text *temp_buff;	int temp_vert;	int temp_pos;	int del_width = 1;	if (point != curr_line->line)	/* if not at beginning of line	*/	{		text_changes = TRUE;		temp2 = tp = point;		if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))		{			del_width = 2;		}		tp -= del_width;		point -= del_width;		position -= del_width;		temp_pos = position;		curr_line->line_length -= del_width;		if ((*tp < ' ') || (*tp >= 127))	/* check for TAB */			scanline(tp);		else			scr_horz -= del_width;		scr_pos = scr_horz;		if (in == 8)		{			if (del_width == 1)				*d_char = *point; /* save deleted character  */			else			{				d_char[0] = *point;				d_char[1] = *(point + 1);			}			d_char[del_width] = (unsigned char) NULL;		}		while (temp_pos <= curr_line->line_length)		{			temp_pos++;			*tp = *temp2;			tp++;			temp2++;		}		if (scr_horz < horiz_offset)		{			horiz_offset -= 8;			midscreen(scr_vert, point);		}	}	else if (curr_line->prev_line != NULL)	{		text_changes = TRUE;		left(disp);			/* go to previous line	*/		temp_buff = curr_line->next_line;		point = resiz_line(temp_buff->line_length, curr_line, position);		if (temp_buff->next_line != NULL)			temp_buff->next_line->prev_line = curr_line;		curr_line->next_line = temp_buff->next_line;		temp2 = temp_buff->line;		if (in == 8)		{			d_char[0] = '\n';			d_char[1] = (unsigned char) NULL;		}		tp = point;		temp_pos = 1;		while (temp_pos < temp_buff->line_length)		{			curr_line->line_length++;			temp_pos++;			*tp = *temp2;			tp++;			temp2++;		}		*tp = (char) NULL;		free(temp_buff->line);		free(temp_buff);		temp_buff = curr_line;		temp_vert = scr_vert;		scr_pos = scr_horz;		if (scr_vert < last_line)		{			wmove(text_win, scr_vert + 1, 0);			wdeleteln(text_win);		}		while ((temp_buff != NULL) && (temp_vert < last_line))		{			temp_buff = temp_buff->next_line;			temp_vert++;		}		if ((temp_vert == last_line) && (temp_buff != NULL))		{			tp = temp_buff->line;			wmove(text_win, last_line,0);			wclrtobot(text_win);			draw_line(last_line, 0, tp, 1, temp_buff->line_length);			wmove(text_win, scr_vert, (scr_horz - horiz_offset));		}	}	draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);	formatted = FALSE;}void scanline(pos)	/* find the proper horizontal position for the pointer	*/unsigned char *pos;{	int temp;	unsigned char *ptr;	ptr = curr_line->line;	temp = 0;	while (ptr < pos)	{		if (*ptr <= 8)			temp += 2;		else if (*ptr == 9)			temp += tabshift(temp);		else if ((*ptr >= 10) && (*ptr <= 31))			temp += 2;		else if ((*ptr >= 32) && (*ptr < 127))			temp++;		else if (*ptr == 127)			temp += 2;		else if (!eightbit)			temp += 5;		else			temp++;		ptr++;	}	scr_horz = temp;	if ((scr_horz - horiz_offset) > last_col)	{		horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);		midscreen(scr_vert, point);	}	else if (scr_horz < horiz_offset)	{		horiz_offset = max(0, (scr_horz - (scr_horz % 8)));		midscreen(scr_vert, point);	}}int tabshift(temp_int)		/* give the number of spaces to shift	*/int temp_int;{	int leftover;	leftover = ((temp_int + 1) % 8);	if (leftover == 0)		return (1);	else		return (9 - leftover);}int out_char(window, character, column)	/* output non-printing character */WINDOW *window;char character;int column;{	int i1, i2;	unsigned char *string;	char string2[8];	if (character == TAB)	{		i1 = tabshift(column);		for (i2 = 0; 		  (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)		{			waddch(window, ' ');		}		return(i1);	}	else if ((character >= '\0') && (character < ' '))	{		string = table[(int) character];	}	else if ((character < 0) || (character >= 127))	{		if (character == 127)			string = "^?";		else if (!eightbit)		{			sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);			string = string2;		}		else		{			waddch(window, (char)character );			return(1);		}	}	else	{		waddch(window, (char)character);		return(1);	}	for (i2 = 0; (string[i2] != (char) NULL) && (((column+i2+1)-horiz_offset) < last_col); i2++)		waddch(window, string[i2]);	return(strlen(string));}int len_char(character, column)	/* return the length of the character	*/char character;int column;	/* the column must be known to provide spacing for tabs	*/{	int length;	if (character == '\t')		length = tabshift(column);	else if ((character >= 0) && (character < 32))		length = 2;	else if ((character >= 32) && (character <= 126))		length = 1;	else if (character == 127)		length = 2;	else if (((character > 126) || (character < 0)) && (!eightbit))		length = 5;	else		length = 1;	return(length);}void draw_line(vertical, horiz, ptr, t_pos, length)	/* redraw line from current position */int vertical;	/* current vertical position on screen		*/int horiz;	/* current horizontal position on screen	*/unsigned char *ptr;	/* pointer to line				*/int t_pos;	/* current position (offset in bytes) from bol	*/int length;	/* length (in bytes) of line			*/{	int d;		/* partial length of special or tab char to display  */	unsigned char *temp;	/* temporary pointer to position in line	     */	int abs_column;	/* offset in screen units from begin of line	     */	int column;	/* horizontal position on screen		     */	int row;	/* vertical position on screen			     */	int posit;	/* temporary position indicator within line	     */	abs_column = horiz;	column = horiz - horiz_offset;	row = vertical;	temp = ptr;	d = 0;	posit = t_pos;	if (column < 0)	{		wmove(text_win, row, 0);		wclrtoeol(text_win);	}	while (column < 0)	{		d = len_char(*temp, abs_column);		abs_column += d;		column += d;		posit++;		temp++;	}	wmove(text_win, row, column);	wclrtoeol(text_win);	while ((posit < length) && (column <= last_col))	{		if ((*temp < 32) || (*temp >= 127))		{			column += len_char(*temp, abs_column);			abs_column += out_char(text_win, *temp, abs_column);		}		else		{			abs_column++;			column++;			waddch(text_win, *temp);		}		posit++;		temp++;	}	if (column < last_col)		wclrtoeol(text_win);	wmove(text_win, vertical, (horiz - horiz_offset));}void insert_line(disp)			/* insert new line		*/int disp;{	int temp_pos;	int temp_pos2;	unsigned char *temp;	unsigned char *extra;	struct text *temp_nod;	text_changes = TRUE;	wmove(text_win, scr_vert, (scr_horz - horiz_offset));	wclrtoeol(text_win);	temp_nod= txtalloc();	temp_nod->line = extra= malloc(10);	temp_nod->line_length = 1;	temp_nod->max_length = 10;	temp_nod->line_number = curr_line->line_number + 1;	temp_nod->next_line = curr_line->next_line;	if (temp_nod->next_line != NULL)		temp_nod->next_line->prev_line = temp_nod;	temp_nod->prev_line = curr_line;	curr_line->next_line = temp_nod;	temp_pos2 = position;	temp = point;	if (temp_pos2 < curr_line->line_length)	{		temp_pos = 1;		while (temp_pos2 < curr_line->line_length)		{			if ((temp_nod->max_length - temp_nod->line_length)< 5)				extra = resiz_line(10, temp_nod, temp_pos);			temp_nod->line_length++;			temp_pos++;			temp_pos2++;			*extra= *temp;			extra++;			temp++;		}		temp=point;		*temp = (char) NULL;		temp = resiz_line((1 - temp_nod->line_length), curr_line, position);		curr_line->line_length = 1 + temp - curr_line->line;	}	curr_line->line_length = position;	curr_line = temp_nod;	*extra = (char) NULL;	position = 1;	point= curr_line->line;	if (disp)	{		if (scr_vert < last_line)		{			scr_vert++;			wclrtoeol(text_win);			wmove(text_win, scr_vert, 0);			winsertln(text_win);		}		else		{			wmove(text_win, 0,0);			wdeleteln(text_win);			wmove(text_win, last_line,0);			wclrtobot(text_win);		}		scr_pos = scr_horz = 0;		if (horiz_offset)		{			horiz_offset = 0;			midscreen(scr_vert, point);		}		draw_line(scr_vert, scr_horz, point, position,			curr_line->line_length);	}}struct text *txtalloc()		/* allocate space for line structure	*/{	return((struct text *) malloc(sizeof( struct text)));}struct files *name_alloc()	/* allocate space for file name list node */{	return((struct files *) malloc(sizeof( struct files)));}unsigned char *next_word(string)		/* move to next word in string		*/unsigned char *string;{	while ((*string != (char) NULL) && ((*string != 32) && (*string != 9)))		string++;	while ((*string != (char) NULL) && ((*string == 32) || (*string == 9)))		string++;	return(string);}void prev_word()	/* move to start of previous word in text	*/{	if (position != 1)	{		if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))		{	/* if at the start of a word	*/			while ((position != 1) && ((*point != ' ') && (*point != '\t')))				left(TRUE);		}		while ((position != 1) && ((*point == ' ') || (*point == '\t')))			left(TRUE);		while ((position != 1) && ((*point != ' ') && (*point != '\t')))			left(TRUE);		if ((position != 1) && ((*point == ' ') || (*point == '\t')))

⌨️ 快捷键说明

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