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

📄 ee.c

📁 EE Text Editor in standard UNIX
💻 C
📖 第 1 页 / 共 5 页
字号:
		{			*point = *str1;			point++;			str1++;		}		*point = (char) NULL;		*append = FALSE;		if ((num == length) && (*str2 != '\n'))			*append = TRUE;	}}void draw_screen()		/* redraw the screen from current postion	*/{	struct text *temp_line;	unsigned char *line_out;	int temp_vert;	temp_line = curr_line;	temp_vert = scr_vert;	wclrtobot(text_win);	while ((temp_line != NULL) && (temp_vert <= last_line))	{		line_out = temp_line->line;		draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);		temp_vert++;		temp_line = temp_line->next_line;	}	wmove(text_win, temp_vert, 0);	wmove(text_win, scr_vert, (scr_horz - horiz_offset));}void finish()	/* prepare to exit edit session	*/{	char *file_name = in_file_name;	/*	 |	changes made here should be reflected in the 'save' 	 |	portion of file_op()	 */	if ((file_name == NULL) || (*file_name == (char) NULL))		file_name = get_string(save_file_name_prompt, TRUE);	if ((file_name == NULL) || (*file_name == (char) NULL))	{		wmove(com_win, 0, 0);		wprintw(com_win, file_not_saved_msg);		wclrtoeol(com_win);		wrefresh(com_win);		clear_com_win = TRUE;		return;	}	tmp_file = resolve_name(file_name);	if (tmp_file != file_name)	{		free(file_name);		file_name = tmp_file;	}	if (write_file(file_name))	{		text_changes = FALSE;		quit(0);	}}int quit(noverify)		/* exit editor			*/int noverify;{	char *ans;	touchwin(text_win);	wrefresh(text_win);	if ((text_changes) && (!noverify))	{		ans = get_string(changes_made_prompt, TRUE);		if (toupper(*ans) == toupper(*yes_char))			text_changes = FALSE;		else			return(0);		free(ans);	}	if (top_of_stack == NULL)	{		if (info_window)			wrefresh(info_win);		wrefresh(com_win);		resetty();		endwin();		putchar('\n');		exit(0);	}	else	{		delete_text();		recv_file = TRUE;		input_file = TRUE;		check_fp();	}	return(0);}void edit_abort(arg)int arg;{	wrefresh(com_win);	resetty();	endwin();	putchar('\n');	exit(1);}void delete_text(){	while (curr_line->next_line != NULL)		curr_line = curr_line->next_line;	while (curr_line != first_line)	{		free(curr_line->line);		curr_line = curr_line->prev_line;		free(curr_line->next_line);	}	curr_line->next_line = NULL;	*curr_line->line = (char) NULL;	curr_line->line_length = 1;	curr_line->line_number = 1;	point = curr_line->line;	scr_pos = scr_vert = scr_horz = 0;	position = 1;}int write_file(file_name)char *file_name;{	char cr;	char *tmp_point;	struct text *out_line;	int lines, charac;	int temp_pos;	int write_flag = TRUE;	charac = lines = 0;	if ((in_file_name == NULL) || strcmp(in_file_name, file_name))	{		if ((temp_fp = fopen(file_name, "r")))		{			tmp_point = get_string(file_exists_prompt, TRUE);			if (toupper(*tmp_point) == toupper(*yes_char))				write_flag = TRUE;			else 				write_flag = FALSE;			fclose(temp_fp);			free(tmp_point);		}	}	clear_com_win = TRUE;	if (write_flag)	{		if ((temp_fp = fopen(file_name, "w")) == NULL)		{			clear_com_win = TRUE;			wmove(com_win,0,0);			wclrtoeol(com_win);			wprintw(com_win, create_file_fail_msg, file_name);			wrefresh(com_win);			return(FALSE);		}		else		{			wmove(com_win,0,0);			wclrtoeol(com_win);			wprintw(com_win, writing_file_msg, file_name);			wrefresh(com_win);			cr = '\n';			out_line = first_line;			while (out_line != NULL)			{				temp_pos = 1;				tmp_point= out_line->line;				while (temp_pos < out_line->line_length)				{					putc(*tmp_point, temp_fp);					tmp_point++;					temp_pos++;				}				charac += out_line->line_length;				out_line = out_line->next_line;				putc(cr, temp_fp);				lines++;			}			fclose(temp_fp);			wmove(com_win,0,0);			wclrtoeol(com_win);			wprintw(com_win, file_written_msg, file_name, lines, charac);			wrefresh(com_win);			return(TRUE);		}	}	else		return(FALSE);}int search(display_message)		/* search for string in srch_str	*/int display_message;{	int lines_moved;	int iter;	int found;	if ((srch_str == NULL) || (*srch_str == (char) NULL))		return(FALSE);	if (display_message)	{		wmove(com_win, 0, 0);		wclrtoeol(com_win);		wprintw(com_win, searching_msg);		wrefresh(com_win);		clear_com_win = TRUE;	}	lines_moved = 0;	found = FALSE;	srch_line = curr_line;	srch_1 = point;	if (position < curr_line->line_length)		srch_1++;	iter = position + 1;	while ((!found) && (srch_line != NULL))	{		while ((iter < srch_line->line_length) && (!found))		{			srch_2 = srch_1;			if (case_sen)	/* if case sensitive		*/			{				srch_3 = srch_str;			while ((*srch_2 == *srch_3) && (*srch_3 != (char) NULL))				{					found = TRUE;					srch_2++;					srch_3++;				}	/* end while	*/			}			else		/* if not case sensitive	*/			{				srch_3 = u_srch_str;			while ((toupper(*srch_2) == *srch_3) && (*srch_3 != (char) NULL))				{					found = TRUE;					srch_2++;					srch_3++;				}			}	/* end else	*/			if (!((*srch_3 == (char) NULL) && (found)))			{				found = FALSE;				if (iter < srch_line->line_length)					srch_1++;				iter++;			}		}		if (!found)		{			srch_line = srch_line->next_line;			if (srch_line != NULL)				srch_1 = srch_line->line;			iter = 1;			lines_moved++;		}	}	if (found)	{		if (display_message)		{			wmove(com_win, 0, 0);			wclrtoeol(com_win);			wrefresh(com_win);		}		if (lines_moved == 0)		{			while (position < iter)				right(TRUE);		}		else		{			if (lines_moved < 30)			{				move_rel("d", lines_moved);				while (position < iter)					right(TRUE);			}			else 			{				curr_line = srch_line;				point = srch_1;				position = iter;				scanline(point);				scr_pos = scr_horz;				midscreen((last_line / 2), point);			}		}	}	else	{		if (display_message)		{			wmove(com_win, 0, 0);			wclrtoeol(com_win);			wprintw(com_win, str_not_found_msg, srch_str);			wrefresh(com_win);		}		wmove(text_win, scr_vert,(scr_horz - horiz_offset));	}	return(found);}void search_prompt()		/* prompt and read search string (srch_str)	*/{	if (srch_str != NULL)		free(srch_str);	if ((u_srch_str != NULL) && (*u_srch_str != (char) NULL))		free(u_srch_str);	srch_str = get_string(search_prompt_str, FALSE);	gold = FALSE;	srch_3 = srch_str;	srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);	while (*srch_3 != (char) NULL)	{		*srch_1 = toupper(*srch_3);		srch_1++;		srch_3++;	}	*srch_1 = (char) NULL;	search(TRUE);}void del_char()			/* delete current character	*/{	in = 8;  /* backspace */	if (position < curr_line->line_length)	/* if not end of line	*/	{		if ((ee_chinese) && (*point > 127) && 		    ((curr_line->line_length - position) >= 2))		{			point++;			position++;		}		position++;		point++;		scanline(point);		delete(TRUE);	}	else	{		right(FALSE);		delete(FALSE);	}}void undel_char()			/* undelete last deleted character	*/{	if (d_char[0] == '\n')	/* insert line if last del_char deleted eol */		insert_line(TRUE);	else	{		in = d_char[0];		insert(in);		if (d_char[1] != (unsigned char) NULL)		{			in = d_char[1];			insert(in);		}	}}void del_word()			/* delete word in front of cursor	*/{	int tposit;	int difference;	unsigned char *d_word2;	unsigned char *d_word3;	unsigned char tmp_char[3];	if (d_word != NULL)		free(d_word);	d_word = malloc(curr_line->line_length);	tmp_char[0] = d_char[0];	tmp_char[1] = d_char[1];	tmp_char[2] = d_char[2];	d_word3 = point;	d_word2 = d_word;	tposit = position;	while ((tposit < curr_line->line_length) && 				((*d_word3 != ' ') && (*d_word3 != '\t')))	{		tposit++;		*d_word2 = *d_word3;		d_word2++;		d_word3++;	}	while ((tposit < curr_line->line_length) && 				((*d_word3 == ' ') || (*d_word3 == '\t')))	{		tposit++;		*d_word2 = *d_word3;		d_word2++;		d_word3++;	}	*d_word2 = (char) NULL;	d_wrd_len = difference = d_word2 - d_word;	d_word2 = point;	while (tposit < curr_line->line_length)	{		tposit++;		*d_word2 = *d_word3;		d_word2++;		d_word3++;	}	curr_line->line_length -= difference;	*d_word2 = (char) NULL;	draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);	d_char[0] = tmp_char[0];	d_char[1] = tmp_char[1];	d_char[2] = tmp_char[2];	text_changes = TRUE;	formatted = FALSE;}void undel_word()		/* undelete last deleted word		*/{	int temp;	int tposit;	unsigned char *tmp_old_ptr;	unsigned char *tmp_space;	unsigned char *tmp_ptr;	unsigned char *d_word_ptr;	/*	 |	resize line to handle undeleted word	 */	if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)		point = resiz_line(d_wrd_len, curr_line, position);	tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);	d_word_ptr = d_word;	temp = 1;	/*	 |	copy d_word contents into temp space	 */	while (temp <= d_wrd_len)	{		temp++;		*tmp_ptr = *d_word_ptr;		tmp_ptr++;		d_word_ptr++;	}	tmp_old_ptr = point;	tposit = position;	/*	 |	copy contents of line from curent position to eol into 	 |	temp space	 */	while (tposit < curr_line->line_length)	{		temp++;		tposit++;		*tmp_ptr = *tmp_old_ptr;		tmp_ptr++;		tmp_old_ptr++;	}	curr_line->line_length += d_wrd_len;	tmp_old_ptr = point;	*tmp_ptr = (char) NULL;	tmp_ptr = tmp_space;	tposit = 1;	/*	 |	now copy contents from temp space back to original line	 */	while (tposit < temp)	{		tposit++;		*tmp_old_ptr = *tmp_ptr;		tmp_ptr++;		tmp_old_ptr++;	}	*tmp_old_ptr = (char) NULL;	free(tmp_space);	draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);}void del_line()			/* delete from cursor to end of line	*/{	unsigned char *dl1;	unsigned char *dl2;	int tposit;	if (d_line != NULL)		free(d_line);	d_line = malloc(curr_line->line_length);	dl1 = d_line;	dl2 = point;	tposit = position;	while (tposit < curr_line->line_length)	{		*dl1 = *dl2;		dl1++;		dl2++;		tposit++;	}	dlt_line->line_length = 1 + tposit - position;	*dl1 = (char) NULL;	*point = (char) NULL;	curr_line->line_length = position;	wclrtoeol(text_win);	if (curr_line->next_line != NULL)	{		right(FALSE);		delete(FALSE);	}	text_changes = TRUE;}void undel_line()			/* undelete last deleted line		*/{	unsigned char *ud1;	unsigned char *ud2;	int tposit;	if (dlt_line->line_length == 0)		return;	insert_line(TRUE);	left(TRUE);	point = resiz_line(dlt_line->line_length, curr_line, position);	curr_line->line_length += dlt_line->line_length - 1;	ud1 = point;	ud2 = d_line;	tposit = 1;	while (tposit < dlt_line->line_length)	{		tposit++;		*ud1 = *ud2;		ud1++;		ud2++;	}	*ud1 = (char) NULL;	draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);}void adv_word()			/* advance to next word		*/{while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))		right(TRUE);while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))		right(TRUE);}void move_rel(direction, lines)	/* move relative to current line	*/char *direction;int lines;{	int i;	char *tmp;	

⌨️ 快捷键说明

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