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

📄 aee.c

📁 aee是一种易使用的文本编辑器。你可以不用说明书来使用它。它提供终端接口和本地的X-windows接口。它的特性包括即弹的菜单
💻 C
📖 第 1 页 / 共 5 页
字号:
char *edit_cmd_str, *edit_err_msg, *restricted_msg, *rae_no_file_msg;char *more_above_str, *more_below_str, *recover_name_prompt;char *no_file_name_string, *recover_menu_title, *other_recover_file_str;char *info_win_height_prompt, *info_win_height_err, *info_win_height_cmd_str;char *info_win_height_msg_str;char *conf_not_saved_msg;	/* message if unable to save configuration */char *conf_dump_err_msg;char *conf_dump_success_msg;char *info_help_msg;char *unix_text_msg, *dos_text_msg;char *text_cmd, *binary_cmd;char *text_msg, *binary_msg, *dos_msg, *unix_msg;int main(argc, argv)		/* beginning of main program		*/int argc;char *argv[];{#ifdef DEBUG	error_fp = fopen("/tmp/ae.mem_debug", "w");#endif /* DEBUG */#ifdef DIAG_DBG		if (!strcmp(argv[argc-1], "-DEBUG"))		{/* |	The following code will start an xterm which will in turn execute  |	a debugger and "adopt" the process, so it can be debugged. */			int child_id;			char command_line[256];			child_id = getpid();			if (!fork())			{				sprintf(command_line, 	      			"xterm -geom =80x40 -fg wheat -bg DarkSlateGrey -n %s -e gdb %s %d", 					"hello",  argv[0], child_id);				execl("/bin/sh", "sh", "-c", command_line, NULL);				fprintf(stderr, "could not exec new window\n");				exit(1);			}/* |	When in debugger, set child_id to zero (p child_id=0) to continue  |	executing the software.			while (child_id != 0)				; */			argc--;		}#endif	eightbit = FALSE;#ifndef DIAG_DBG	mask = 077777777 & (~020000) & (~02);	for (value = 1; value < 24; value++)	{		if ((value != SIGCHLD) && (value != SIGALRM) && (value != SIGSEGV)#ifdef XAE		   && (value != SIGTSTP)#endif /* XAE */		)			signal(value, SIG_IGN);		else			signal(value, SIG_DFL);	}#endif	/* ifndef DIAG	*/	signal(SIGINT, abort_edit);#ifdef XAE	win_width = 0;	win_height = 0;#endif	start_at_line = NULL;	d_word = NULL;	d_wrd_len = 0;	d_line = xalloc(1);	*d_line = (char) NULL;	tabs = (struct tab_stops *) xalloc(sizeof( struct tab_stops));	tabs->next_stop = NULL;	tabs->column = 0;	dlt_line = txtalloc();	dlt_line->line = d_line;	dlt_line->line_length = 1;	paste_buff = NULL;	status_line = FALSE;	srch_str = u_srch_str = NULL;	u_old_string = new_string = old_string = NULL;	/*	 |	initialize literal strings	 */	strings_init();	first_buff = curr_buff = buf_alloc();	first_buff->name = main_buffer_name;	first_buff->first_line = txtalloc();	curr_buff->curr_line = curr_buff->first_line;	first_buff->next_buff = NULL;	first_buff->footer = NULL;	first_buff->main_buffer = TRUE;	first_buff->edit_buffer = TRUE;	curr_buff->curr_line->line = curr_buff->pointer = xalloc(10);	curr_buff->curr_line->line_length = 1;	curr_buff->curr_line->max_length = 10;	curr_buff->curr_line->prev_line = NULL;	curr_buff->curr_line->next_line = NULL;	curr_buff->curr_line->line_number = 1;	curr_buff->curr_line->vert_len = 1;	curr_buff->num_of_lines = 1;	curr_buff->absolute_lin = 1;	num_of_bufs = 1;	curr_buff->position = 1;	curr_buff->abs_pos = curr_buff->scr_pos = 0;	curr_buff->scr_vert = 0;	curr_buff->scr_horz = 0;	bit_bucket = open("/dev/null", O_WRONLY);	forward = windows = edit = TRUE;	observ_margins = literal = FALSE;	expand = indent = overstrike = FALSE;	clr_cmd_line = change = mark_text = gold = case_sen = FALSE;	in_pipe = out_pipe = FALSE;	shell_fork = TRUE;	left_margin = 0;	right_margin = 0;	gold_count = 0;	info_type = CONTROL_KEYS;	top_of_stack = NULL;	echo_flag = TRUE;	journ_on = TRUE;	input_file = FALSE;	recv_file = FALSE;	recover = FALSE;	undel_init();	init_keys();	ae_init();	get_options(argc, argv);	set_up_term();		/* initialize terminal		*/	get_key_assgn();	com_win = newwin(1, COLS, LINES-1, 0);	com_win_initialized = TRUE;	curr_buff->last_col = COLS - 1;	curr_buff->last_line = LINES - 2;	first_buff->lines = LINES - 1;	curr_buff->window_top = 0;	if (info_window)	{		info_win = newwin(info_win_height, COLS, 0, 0);		paint_info_win();		curr_buff->window_top = info_win_height;		first_buff->win = newwin(LINES-info_win_height-1, COLS, info_win_height, 0);		first_buff->lines = LINES - info_win_height - 1;		curr_buff->last_line = first_buff->lines - 1;	}	else		first_buff->win = newwin(LINES-1, COLS, 0, 0);	keypad(curr_buff->win, TRUE);	nodelay(curr_buff->win, FALSE);	idlok(curr_buff->win, TRUE);	/*	 |	If restricted mode, there must have been a file specified on 	 |	the invoking command line.	 */	if ((restrict_mode()) && (top_of_stack == NULL))	{		wmove(com_win, 0, 0);		werase(com_win);		wrefresh(com_win);		menu_op(rae_err_menu);		abort_edit(0);	}	if (top_of_stack != NULL)		tmp_file = top_of_stack->name;	else		tmp_file = "";	input_file = TRUE;	recv_file = TRUE;	if (top_of_stack != NULL)		top_of_stack = top_of_stack->next_name;	value = check_fp();	input_file = FALSE;	recv_file = FALSE;	if (right_margin == 0)		right_margin = COLS - 1;	wmove(curr_buff->win, curr_buff->last_line, 0);	wstandout(curr_buff->win);	wprintw(curr_buff->win, "aee, %s", copyright_notice);	wstandend(curr_buff->win);	wmove(curr_buff->win, curr_buff->scr_vert, curr_buff->scr_horz);	wrefresh(curr_buff->win);	midscreen(curr_buff->scr_vert, curr_buff->position);	while (edit) 	{		get_input(curr_buff->win);		if (clr_cmd_line)		{			clr_cmd_line = FALSE;			werase(com_win);			wrefresh(com_win);		}		keyboard();		status_display();		wmove(curr_buff->win, curr_buff->scr_vert, curr_buff->scr_horz);		wrefresh(curr_buff->win);	}	exit(0);}void get_input(win_ptr)WINDOW *win_ptr;{	int value;	resize_check();#ifdef XAE	event_manage();#endif /* XAE */	in = wgetch(win_ptr);	value = alarm(0);	signal(SIGALRM, dummy);	if (in == EOF)		/* somehow lost contact with input	*/		abort_edit(0);}void status_display()	/* display status line			*/{	if ((status_line) && (!clr_cmd_line))	{		werase(com_win);		wmove(com_win, 0, 0);		if (curr_buff->edit_buffer)		{			if (curr_buff->file_name != NULL)				wprintw(com_win, "%s  ", curr_buff->file_name);			else				wprintw(com_win, "[%s]  ", no_file_string);		}		else		{			if (first_buff->file_name != NULL)				wprintw(com_win, "%s  ",first_buff->file_name);			else				wprintw(com_win, "[%s]  ", no_file_string);		}		wmove(com_win, 0, 16);		wclrtoeol(com_win);		wmove(com_win, 0, 18);		wprintw(com_win, SL_line_str, curr_buff->curr_line->line_number);		wmove(com_win, 0, 30);		wprintw(com_win, SL_col_str, curr_buff->scr_pos);		wmove(com_win, 0, 40);		if (literal)			wprintw(com_win, SL_lit_str);		else			wprintw(com_win, SL_nolit_str);		if (forward)			wprintw(com_win, SL_fwd_str);		else			wprintw(com_win, SL_rev_str);		if (overstrike)			wprintw(com_win, SL_over_str);		else			wprintw(com_win, SL_insrt_str);		if (indent)			wprintw(com_win, SL_indent_str);		else			wprintw(com_win, SL_noindnt_str);		if (observ_margins)			wprintw(com_win, SL_marg_str);		else			wprintw(com_win, SL_nomarg_str);		if (mark_text)		{			wstandout(com_win);			wprintw(com_win, SL_mark_str);			wstandend(com_win);		}		else if (text_only)		{			wprintw(com_win, "%s", 			  curr_buff->dos_file ? dos_text_msg : unix_text_msg);		}		wrefresh(com_win);	}}char *#ifndef DEBUGxalloc(size)	/* allocate memory, report if errors	*/int size;	/* size of memory to allocate		*/#elsedxalloc(size, line_num)int size;int line_num;#endif /* DEBUG */{	int counter;	char *memory;#ifdef DEBUG	fprintf(error_fp, "m s=%d, l#=%d\n", size, line_num);	fflush(error_fp);#endif /*	DEBUG */	if (size == 0)		size++;	if ((memory = malloc(size)) == NULL)	{		counter = 0;		werase(com_win);		wmove(com_win, 0,0);		wstandout(com_win);		wprintw(com_win, "memory allocation errors, please wait");		wstandend(com_win);		wrefresh(com_win);		clr_cmd_line = TRUE;		while (((memory = malloc(size)) == NULL) && (counter < 10000))			counter++;		if (memory == NULL)			abort_edit(0);		werase(com_win);	}	return(memory);}char *#ifndef DEBUGresiz_line(factor, rline, rpos)	/* resize the line to length + factor*/int factor;		/* resize factor				*/struct text *rline;	/* pointer to line structure			*/int rpos;		/* position in line				*/#elsedresiz_line(factor, rline, rpos, line_num) int factor;		/* resize factor				*/struct text *rline;	/* pointer to line structure			*/int rpos;		/* position in line				*/int line_num;#endif{	char *rpoint;	int resiz_var; #ifdef DEBUG	fprintf(error_fp, "r s=%d, l#=%d\n", factor, line_num);	fflush(error_fp);#endif /*	DEBUG */	rline->max_length += factor;	while ((rpoint = realloc(rline->line, rline->max_length )) == NULL)		;	rline->line = rpoint;	for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)		rpoint++;	return(rpoint);}void dummy(foo)int foo;{/*this is a dummy function to eliminate any unresolved signals		*/}void insert(character)		/* insert character into line		*/int character;			/* new character			*/{	int counter;	char *temp;		/* temporary pointer			*/	char *temp2;		/* temporary pointer			*/	int temp_overstrike;	if ((observ_margins) && (curr_buff->scr_pos < left_margin))	{		temp_overstrike = overstrike;		overstrike = FALSE;		counter = left_margin;		left_margin = 0;		while (curr_buff->scr_pos < counter)			insert(' ');		left_margin = counter;		overstrike = temp_overstrike;	}	change = TRUE;	curr_buff->curr_line->changed = TRUE;	curr_buff->changed = TRUE;	if ((!overstrike) || (curr_buff->position == curr_buff->curr_line->line_length))	{		if ((curr_buff->curr_line->max_length - curr_buff->curr_line->line_length) < 5)			curr_buff->pointer = resiz_line(10, curr_buff->curr_line, curr_buff->position);		curr_buff->curr_line->line_length++;		temp = curr_buff->pointer;		counter = curr_buff->position;		while (counter < curr_buff->curr_line->line_length)	/* find end of line */		{			counter++;			temp++;		}		temp++;			/* increase length of line by one	*/		while (curr_buff->pointer < temp)		{			temp2=temp - 1;			*temp= *temp2;	/* shift characters over by one		*/			temp--;		}	}	*curr_buff->pointer = character;	/* insert new character			*/	if (curr_buff->position != (curr_buff->curr_line->line_length - 1))		counter = (scanline(curr_buff->curr_line, curr_buff->curr_line->line_length) / COLS) + 1;	else		counter = ((curr_buff->scr_pos + len_char(*curr_buff->pointer, curr_buff->scr_pos)) / COLS) + 1;	if (counter > curr_buff->curr_line->vert_len)	{		curr_buff->curr_line->vert_len = counter;		if (curr_buff->scr_vert < curr_buff->last_line)		{			wmove(curr_buff->win, (curr_buff->scr_vert+1), 0);			winsertln(curr_buff->win);		}	}	wmove(curr_buff->win, curr_buff->scr_vert, curr_buff->scr_horz);	wclrtoeol(curr_buff->win);	if ((mark_text) && (((pst_pos == cpste_line->line_length) && (cpste_line->next_line == NULL)) || (overstrike)))		right(TRUE);	else	{		counter = curr_buff->scr_horz + len_char(character, curr_buff->scr_pos);		if (counter > curr_buff->last_col)		{			counter = curr_buff->scr_vert + 1;			if (counter > curr_buff->last_line)			{				wmove(curr_buff->win, 0, 0);				wdeleteln(curr_buff->win);				wmove(curr_buff->win, curr_buff->scr_vert-1, curr_buff->scr_horz);			}		}		if ((character < 32) || (character > 126))			curr_buff->scr_horz += out_char(curr_buff->win, character, curr_buff->scr_pos, curr_buff->scr_vert, 0);		else		{			waddch(curr_buff->win, character);			curr_buff->scr_horz++;		}		curr_buff->abs_pos = curr_buff->scr_pos += len_char(*curr_buff->pointer, curr_buff->scr_pos);		curr_buff->pointer++;		curr_buff->position++;		if (curr_buff->scr_horz > curr_buff->last_col)		{			curr_buff->scr_horz = curr_buff->scr_pos % COLS;			if (curr_buff->scr_vert < curr_buff->last_line)				curr_buff->scr_vert++;		}	}	draw_line(curr_buff->scr_vert, curr_buff->scr_pos, curr_buff->pointer, curr_buff->position, curr_buff->curr_line);	if ((observ_margins) && (right_margin < curr_buff->scr_pos))	{		counter = curr_buff->position;		while (curr_buff->scr_pos > right_margin)			prev_word();		if (curr_buff->scr_pos == 0)		{			while (curr_buff->position < counter)				right(TRUE);		}		else		{			counter -= curr_buff->position;			insert_line(TRUE);			for (value = 0; value < counter; value++)				right(TRUE);		}	}	if ((auto_format) && ((character == '\t') || ((character == ' ') && (!formatted))))

⌨️ 快捷键说明

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