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

📄 file.c

📁 aee是一种易使用的文本编辑器。你可以不用说明书来使用它。它提供终端接口和本地的X-windows接口。它的特性包括即弹的菜单
💻 C
📖 第 1 页 / 共 2 页
字号:
/* | |	Handle file operations for aee. |	$Header: /home/hugh/sources/aee/RCS/file.c,v 1.19 1999/01/31 04:28:43 hugh Exp $ | |	Copyright (c) 1986 - 1988, 1991 - 1996 Hugh Mahon. | *//* |	get the full path the the named file */#include "aee.h"struct menu_entries file_error_menu[] = {	{"", NULL, NULL, NULL, NULL, MENU_WARN}, 	{NULL, NULL, NULL, NULL, NULL, -1}, 	{NULL, NULL, NULL, NULL, NULL, -1}, 	{NULL, NULL, NULL, NULL, NULL, -1}	};int aee_write_status;void show_pwd(){	char buffer[1024];	char *buff;	wmove(com_win, 0, 0);	werase(com_win);	buff = getcwd(buffer, 1024);	if (buff != NULL)	{		wprintw(com_win, "%s", buff);	}	else		wprintw(com_win, "%s", pwd_err_msg);}char *get_full_path(path, orig_path)char *path;char *orig_path;{	char *buff = path;	char long_buffer[1024];	if ((path == NULL) || (*path != '/'))	/* a '/' indicates an absolute path */	{		if (orig_path != NULL)		{			strcpy(long_buffer, orig_path);			buff = long_buffer;		}		else			buff = getcwd(long_buffer, 1024);		if (buff != NULL)		{			buff = xalloc(strlen(long_buffer) + 				(path != NULL ? strlen(path) : 0) + 2);			strcpy(buff, long_buffer);			if (path != NULL)			{				strcat(buff, "/");				strcat(buff, path);			}		}		else			change_dir_allowed = FALSE;	}	return(buff);}char *ae_basename(name)char *name;{	char *buff, *base;	buff = base = name;	while (*buff != (char) NULL)	{		if (*buff == '/')			base = ++buff;		else			buff++;	}	return(base);}char *ae_dirname(path)char *path;{	char *tmp = NULL;	char buffer[1024];	if (strchr(path, '/') != NULL)	{		strcpy(buffer, path);		tmp = strrchr(buffer, '/');		*tmp = (char) NULL;		tmp = (char *) malloc(strlen(buffer) + 1);		strcpy(tmp, buffer);	}	return(tmp);}char *buff_name_generator(){	char *buffer = (char *)malloc(4);	char found;	struct bufr *tmp_buff;	int i1, i2;	found = TRUE;	/*	 |	Buffers with the name already existed.	 */	buffer[3] = 0;	buffer[2] = 0;	i2 = -1;	do	{		if (i2 >= 0)			buffer[2] = i2 + 'A';		buffer[1] = 0;		i1 = -1;		do 		{			if (i1 >= 0)				buffer[1] = i1 + 'A';			buffer[0] = 'A'; 			do 			{				found = FALSE;				tmp_buff = first_buff;				while (tmp_buff != NULL)				{					if (!strcmp(buffer, tmp_buff->name))						found = TRUE;					tmp_buff = tmp_buff->next_buff;				}				if (found)					buffer[0]++;			} while ((buffer[0] <= 'Z') && (found)); 			i1++;		} while ((buffer[1] <= 'Z') && (found) );		i2++; 	}while ((buffer[2] <= 'Z') && (found));	return(buffer);}int open_for_edit(string)char *string;{	struct bufr *tmp_buff;	char *short_name;	char buffer[1024];	char found = FALSE;	int length = 0;	int ret_val;	if (restrict_mode())	{		return(FALSE);	}	if ((string != NULL) && (*string != (char)NULL))	{		short_name = ae_basename(string);		do		{			tmp_buff = first_buff;			found = FALSE;			while (tmp_buff != NULL)			{				if (!strcmp(short_name, tmp_buff->name))					found = TRUE;				tmp_buff = tmp_buff->next_buff;			}			if (found)			{				if (length == 0)				{					strcpy(buffer, short_name);					strcat(buffer, "A");					length = strlen(buffer);				}				if (buffer[length-1] <= 'Z')					buffer[length-1]++;				short_name = buffer;			}		}		while ((found) && (buffer[length-1] <= 'Z'));		if ((found) && (buffer[length-1] > 'Z'))		{			/*			 |	Buffers with the name already existed.			 */			 return(FALSE);		}	}	else	{		short_name = buff_name_generator();	}	chng_buf(short_name);	curr_buff->edit_buffer = TRUE;	if (*string != (char)NULL)		tmp_file = strdup(string);	else		tmp_file = "";	recv_file = TRUE;	input_file = TRUE;	ret_val = check_fp();	if (ret_val == FALSE)	{		del_buf();	}	return ( ret_val );}void recover_op(){	struct journal_db *journal_list;	struct journal_db *list_tmp;	struct menu_entries *recover_tmp;	int list_count;	int counter;	int choice;	char *other_choice;	struct bufr local_copy;	char new_buff = FALSE;	/* indicate if a new buffer was created */	/*	 |	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);		return;	}	journal_list = read_journal_db();	for (list_count = 0, list_tmp = journal_list; list_tmp != NULL; 			list_count++, list_tmp = list_tmp->next)		;	unlock_journal_fd();	/*	 | Recover from a failed edit session.  	 | 1. Read the file ~/.aeeinfo, get the list of journal files.	 | 2. Create a menu with names of files according to ~/.aeeinfo.	 | 3. Menu also has entry 'other journal file', which allows the user	 |    to specify another file.	 Not yet implemented:	 | 4. Before creating the menu, the routine checks if the journal file 	 |    is currently open (someone is currently editing that file!).	 | 5. After user selection, present a menu allowing the user to copy 	 |    the journal file, or recover directly from the journal (since 	 |    starting an edit session from the journal could change it, it 	 |    might be nice to just allow the user to 'browse' the file).	 Implemented:	 | 5a. If there is only one file in the list, automatically open it.	 | 6. Call recover_from_journal.	 |	 |	 */	if (list_count == 0)	{		/*		 |	prompt for name of file to recover		 */		other_choice = get_string(recover_name_prompt, TRUE);	}	/*	 | If there is just one file in the list, we could just put the user 	 | into the one file.  I have found that this is not always a good 	 | idea.	else if (list_count == 1)		other_choice = journal_list->journal_name;	 |	 */	else	{		/*		 |	Construct menu.		 */		recover_tmp = malloc((3 + list_count) * 						sizeof(struct menu_entries));		memset(recover_tmp, 0, ((3 + list_count) * sizeof(struct menu_entries)));		for (counter = 1, list_tmp = journal_list;			(counter <= list_count); 				list_tmp = list_tmp->next, counter++)		{			recover_tmp[counter].item_string = (list_tmp->file_name != NULL) ? list_tmp->file_name : no_file_name_string ;			recover_tmp[counter].procedure = NULL;			recover_tmp[counter].ptr_argument = NULL;			recover_tmp[counter].iprocedure = NULL;			recover_tmp[counter].nprocedure = NULL;			recover_tmp[counter].argument = -1;		}		/*		 |	Assign the title of the menu, then add 'other file' to 		 |	menu.		 */		recover_tmp[0].item_string = recover_menu_title;		recover_tmp[list_count+1].item_string = other_recover_file_str;		recover_tmp[list_count+2].item_string = NULL;				/*		 |	Present menu to user.		 */		choice = menu_op(recover_tmp);		free(recover_tmp);		if (choice == 0)			return;		else if (choice == (list_count + 1))		{			other_choice = get_string(recover_name_prompt, TRUE);			in_file_name = NULL;		}		else		{			for (list_count = 1, list_tmp = journal_list; 				list_count < choice; 				list_count++, list_tmp = list_tmp->next)					;			other_choice = list_tmp->journal_name;			in_file_name = list_tmp->file_name;		}	}	/*	 |	take user's choice, fill in data structures, recover, 	 |	and return	 */	/*	 |	Change to a new buffer to make sure we aren't messing 	 |	with the user's edit session.	 */	local_copy.journalling = FALSE;	if ((curr_buff->changed == FALSE) && 	    (curr_buff->first_line->next_line == NULL) &&	    (curr_buff->first_line->line_length == 1) &&	    (*curr_buff->full_name == (char)NULL))	{		local_copy.journalling = curr_buff->journalling;		local_copy.journ_fd = curr_buff->journ_fd;		local_copy.journal_file = curr_buff->journal_file;		local_copy.full_name = curr_buff->full_name;		local_copy.file_name = curr_buff->file_name;		local_copy.name = curr_buff->name;	}	else	{		chng_buf(buff_name_generator());		new_buff = TRUE;	}	curr_buff->journal_file = other_choice;	if (journ_on)	{		curr_buff->journalling = TRUE;	}	if (curr_buff->orig_dir == NULL)	{		curr_buff->orig_dir = get_full_path(NULL, NULL);	}	if (recover_from_journal(curr_buff, curr_buff->journal_file) != 0)	{		if (new_buff)			del_buf();		else		{			curr_buff->journalling = local_copy.journalling;			curr_buff->journ_fd = local_copy.journ_fd ;			curr_buff->journal_file = local_copy.journal_file ;			curr_buff->full_name = local_copy.full_name ;			curr_buff->file_name = local_copy.file_name ;			curr_buff->name = local_copy.name ;		}		wmove(com_win,0,0);		wclrtoeol(com_win);		wprintw(com_win, bad_rcvr_msg);		wrefresh(com_win);	}	else	{		/*		 |	On success, clear flags and continue edit		 |	session.		 */		if ((!new_buff) && (local_copy.journalling))			remove_journal_file(&local_copy);		curr_buff->edit_buffer = TRUE;		curr_buff->curr_line = curr_buff->first_line;		curr_buff->pointer = curr_buff->curr_line->line;		new_screen();		wmove(com_win,0,0);		wclrtoeol(com_win);		wprintw(com_win, rcvr_op_comp_msg);		wrefresh(com_win);#ifdef XAE		if (curr_buff->main_buffer)			set_window_name(curr_buff->file_name);#endif /* XAE */		recv_file = FALSE;		input_file = FALSE;	}}int check_fp()	/* open or close files according to flags recv_file, 		   recover, and input_file	*/{	char *buff;	int line_num;	char buffer[512];	clr_cmd_line = TRUE;	if (recover)	/* get data from journal file	*/	{		recover = FALSE;		buff = in_file_name = tmp_file;		if (journ_on)		{			curr_buff->journalling = TRUE;		}		if (curr_buff->orig_dir == NULL)		{			curr_buff->orig_dir = get_full_path(NULL, NULL);		}		in_file_name = tmp_file = 				get_full_path(in_file_name, 							curr_buff->orig_dir);		short_file_name = ae_basename(in_file_name);		curr_buff->file_name = short_file_name;		curr_buff->full_name = in_file_name;		journal_name(curr_buff, in_file_name);		if (recover_from_journal(curr_buff, 				curr_buff->journal_file) != 0)		{			wmove(com_win,0,0);			wclrtoeol(com_win);			wprintw(com_win, bad_rcvr_msg);			wrefresh(com_win);		}		else		{			/*			 |	On success, clear flags and continue edit			 |	session.			 */			curr_buff->curr_line = curr_buff->first_line;			curr_buff->pointer = curr_buff->curr_line->line;			midscreen(curr_buff->scr_vert, curr_buff->position);			wmove(com_win,0,0);			wclrtoeol(com_win);			wprintw(com_win, rcvr_op_comp_msg);			wrefresh(com_win);#ifdef XAE			if (curr_buff->main_buffer)				set_window_name(curr_buff->file_name);#endif /* XAE */			recv_file = FALSE;			input_file = FALSE;		}	}	if (recv_file)		/* read in a file	*/	{		tmp_vert = curr_buff->scr_vert;		tmp_horz = curr_buff->scr_horz;		tmp_line = curr_buff->curr_line;		if (input_file)		/* get file on command line	*/		{			buff = short_file_name = in_file_name = tmp_file;			if (curr_buff->orig_dir == NULL)				curr_buff->orig_dir = 						get_full_path(NULL, NULL);			if (*buff != (char)NULL)			{				tmp_file = in_file_name = 				get_full_path(in_file_name, curr_buff->orig_dir);				short_file_name = ae_basename(in_file_name);							curr_buff->file_name = short_file_name;				curr_buff->full_name = in_file_name;			}			else			{				recv_file = FALSE;				input_file = FALSE;			}			if (journ_on)			{				curr_buff->journalling = TRUE;				journal_name(curr_buff, in_file_name);				open_journal_for_write(curr_buff);			}#ifdef XAE			if ((curr_buff->main_buffer) && 				(curr_buff->file_name != NULL))				set_window_name(curr_buff->file_name);#endif /* XAE */			if (*buff == (char)NULL)			{				wmove(com_win,0,0);				wclrtoeol(com_win);				wprintw(com_win, no_file_string);				return(TRUE);			}		}		wmove(com_win,0,0);		wclrtoeol(com_win);

⌨️ 快捷键说明

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