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

📄 cmds.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		mt_set_curselmsg(nmsg); 	}	if (!mt_3x_compatibility) {		(void)sprintf(mt_info, "%d deleted message%s", mt_del_count, 			mt_del_count > 1 ? "s" : "");		mt_update_info(mt_info);		mt_set_namestripe_right(mt_info, TRUE);	}}/* * Check to make sure the recipient field is correctly filled out. * Assumes "To:" must appear in pos 0 in reply sw and must be * followed by some alphnumeric characters. */intmt_check_to_who(ptr)struct reply_panel_data	*ptr;{  Textsw_index	first = 0, last_plus_one;  char		wstr[256];  int		i;  strcpy(wstr,"To:");  if ((textsw_find_bytes(ptr->replysw, &first, &last_plus_one,       wstr, strlen(wstr), 0)) == -1)  { /* 'To:' not found, so insert it in pos 0, i.e. line 1, column 1 */    mt_warn(mt_frame, 	    "Warning: recipient field not found.",	    "         Inserting field into text.",0);     (void)window_set(ptr->replysw, TEXTSW_INSERTION_POINT, 0, 0);    (void)sprintf(wstr, "To: %s\n", (mt_use_fields ? "|>recipients<|" : ""));    if (textsw_insert(ptr->replysw, wstr, strlen(wstr)) == 0)    {      mt_warn(mt_frame,"Unable to insert recipient field", 0);    }    else    {       if (mt_use_fields)        { /* select the field for the user */	 first = 0;	 textsw_match_bytes(ptr->replysw,			    &first, &last_plus_one, "|>", 2, "<|", 2,			    TEXTSW_FIELD_BACKWARD);	 (void) textsw_set_selection(ptr->replysw, first, last_plus_one,		 PRIMARY_SELECTION | PRIMARY_PD_SELECTION);	 (void) window_set(ptr->replysw, TEXTSW_INSERTION_POINT,		 last_plus_one, 0);       }       else	 /* set insertion point right after "To: " */	 (void)window_set(ptr->replysw, TEXTSW_INSERTION_POINT, 5, 0);    }    return(0);  /* unsuccessful */  }  if (first != 0)  /* 'To:' must be in pos 0, i.e. line 1, col 0 */  {    mt_warn(mt_frame,	    "The recipient designator 'To:' must be",	    "at the beginning of the text subwindow.",0);    return(0);  /* unsuccessful */  }    /*    * Check for blank recipient field.  The reply sw starts at   * line 0, col 0.  The next operation sets last_plus_one to   * the position of the 1st char on the 2nd visible line.   */  last_plus_one = textsw_index_for_file_line(ptr->replysw, 1);  if (last_plus_one != TEXTSW_CANNOT_SET)  {    (void) window_get(ptr->replysw, TEXTSW_CONTENTS, 4, wstr, last_plus_one);    for (i=0; wstr[i] != '\n' && i < (int)last_plus_one-4; i++)  	if isalnum(wstr[i])  		return(1);  /* successful - chars detected */  }  mt_warn(mt_frame, "You need to specify a recipient to mail to", 0);  return(0);  /* unsuccessful */   }/* ARGSUSED */static voidmt_do_deliver(item, ie)	Panel_item      item;	Event          *ie;{	char            current_filename[1024];	Panel           panel;	struct reply_panel_data *ptr;	Textsw_index             first, last_plus_one;	register char **fp;	int		intact = (event_ctrl_is_down(ie));	panel = panel_get(item, PANEL_PARENT_PANEL);	ptr = (struct reply_panel_data *)panel_get(panel, PANEL_CLIENT_DATA);	/* erase "|>subject<|" and other similiar fields */	for (fp = &fields[0]; *fp != (char *) 0; fp++) 	{		first = 1;		if (textsw_find_bytes(ptr->replysw, &first, &last_plus_one,			*fp, strlen(*fp), 0) != -1)			textsw_erase(ptr->replysw, first, last_plus_one);	}	if (mt_check_to_who(ptr) == 0)  /* check the recipient field */		return;	current_filename[0] = '\0';	(void)textsw_append_file_name(ptr->replysw, current_filename);	/* (Bug# 1012325 fix)  see comments at end of program */        if ((window_get(ptr->replysw, TEXTSW_LENGTH) > 0) || 	    (window_get(ptr->replysw, TEXTSW_MODIFIED))) 	{		/* typical case. edits made, need to write them to a file */		int	save = FALSE;		if (current_filename[0] != '\0' &&			strcmp(current_filename, ptr->replysw_file) != 0) {			/*			 * user either loaded a file in, or else did a store			 * along the way. Ask him if he wants his recent			 * changes written back out to this file 			 */			int	expert = FALSE;			(void) strcpy(line, current_filename);			(void) strcat(line, " ?");			if (mt_value("expert")) {				expert = TRUE;				mt_deassign("expert");			}			save = mt_confirm(ptr->replysw, TRUE, FALSE,				"Yes: save edits in file",				"No: use temporary file",				"Do you want the edits to this window written back to",				line,				0);			if (expert)				mt_assign("expert", "");		}		if (save) {			if (textsw_save(ptr->replysw, 0, 0))				goto failed;		} else {			if (textsw_store_file(ptr->replysw,				ptr->replysw_file, 0, 0)) 				goto failed;			(void) strcpy(current_filename, ptr->replysw_file);		}	}	if (intact) {}	else if (ptr->frame != mt_frame && ptr->behavior == mt_Close)		(void) window_set(ptr->frame, FRAME_CLOSED, TRUE, 0);	else if (ptr->behavior == mt_Disappear)		mt_stop_reply(ptr);	if (vfork() == 0) {		register int i;		for (i = GETDTABLESIZE(); i > 2; i--)			(void)close(i);		(void) close(0);		(void) open(current_filename, 0);		if (!intact)			(void) unlink(ptr->replysw_file);  		execlp("Mail", "Mail", "-t", 0);		/*		 * -t tells Mail to interpret the headers in the message,		 * rather than requiring them to be supplied as arguments to		 * the program. This allows Mail to pick up the "To:" line in		 * the message and figure our who to send to. 		 */		exit(-1);	}	if (!intact) {		textsw_reset(ptr->replysw);		ptr->inuse = FALSE;	}	if (ptr->frame != mt_frame)		(void) window_set(ptr->frame,			FRAME_ICON, &mt_empty_letter_icon,			0);	return;   failed:	mt_warn(mt_frame, "Can't save changes.", 0);	return;}/* * Do the save or copy. */static voidmt_do_save(del, ie, has_selection)	int             del;	Event          *ie;	int		has_selection;{	int             msg;	char           *file;	static char     buf[256];	char           *p;	extern char    *index();	if (mt_nomail) {		mt_warn(mt_frame, "No Mail", 0);		return;	}	if ((msg = mt_get_curselmsg(0)) == 0)		return;	file = (char *)panel_get_value(mt_file_item);	if (file == NULL || *file == '\0') {		mt_warn(mt_frame, "Must specify file name.", 0);		return;	}	mt_yield_all();       /* use mt_yield_all() to save shelf */	/*	 * if (msg == mt_curmsg) - bug: if edit current message, select	 * something else, and click save, edits aren't saved 	 */	mt_save_curmsg();	if (mt_copy_msg(msg, file))		mt_save_filename(file);	/* only save name if copy succeeds */	else {		mt_warn(mt_frame, mt_info, 0);		del = 0;		/* don't delete if copy fails */	}	(void) strcpy(buf, mt_info);	if (del)		mt_do_del(msg, ie, has_selection);	mt_update_info(buf);	if (p = index(&buf[1], ']')) 		*(++p) = '\0';	mt_set_namestripe_right(buf, TRUE);}/* * Handle input events when over the "File" item. * Menu request gives menu of recent file names. */voidmt_file_event(item, ie)	Panel_item      item;	Event          *ie;{	Menu_item       mi;	if (event_action(ie) == MS_RIGHT && event_is_down(ie)) {		if (mt_file_menu == NULL) {			mt_warn(mt_frame, "No saved file names", 0);		} else {			mi = menu_show(mt_file_menu, mt_cmdpanel,				panel_window_event(mt_cmdpanel, ie), 0);			if (mi) {				char	*s;				s = menu_get(mi, MENU_STRING);				(void) panel_set_value(mt_file_item, s);				(void) menu_set(mt_file_menu,					MENU_SELECTED_ITEM, mi,					0);				mt_trace("set folder name to ", s);			}		}	} else		mt_default_panel_event(item, ie,			"input folder name", "", NULL);}/* * Handles "new mail", "commit" and "done" */static voidmt_do_retrieve(item, ie, incorporate, quietly)	Panel_item      item;	Event          *ie;{	static u_long   last;	u_long          when;	when = event_time(ie).tv_sec;	if (last != 0 && when != 0 && when < last) {		/*		 * this event occurred BEFORE the last new mail operation		 * completed, i.e., user bounced on the key. The when != 0		 * check is to check for synthetic events, i.e., calls to		 * mt_do_retrieve from mt_itimer_doit because user opened the		 * tool when it was idle. 		 */		last = when;		return;	}	if (event_ctrl_is_down(ie)) {		mt_done_proc(item, ie);		return;	} 	(void)win_release_event_lock(mt_cmdpanel_fd);	mt_yield_all();	mt_new_folder("%", incorporate, quietly);	last = mt_current_time();}/* * Save a file name in the "File:" item menu. * The last "filemenusize" file names are saved. */voidmt_save_filename(file)	char           *file;{	Menu_item       mi, smi;	int             height;	register int    i, n, cn;	static int      fileuse;	/* filter out any white space before or after filename */	while (isspace(*file) && (*file != '\0'))		*file++;	n = strlen(file) - 1;	while (isspace(*(file + n)) && (*(file + n) != '\0'))	{		*(file + n) = '\0';		n--;	}	if (mt_file_menu == NULL) {		mt_file_menu = menu_create(MENU_NOTIFY_PROC,			menu_return_item, 0);	}	n = fileuse + 1;	smi = NULL;	for (i = 1; mi = menu_get(mt_file_menu, MENU_NTH_ITEM, i); i++) {		if (strcmp(file, (char *)menu_get(mi, MENU_STRING)) == 0) {			(void) menu_set(mi, MENU_VALUE, ++fileuse, 0);			return;		}		if ((cn = (int)menu_get(mi, MENU_VALUE)) < n) {			smi = mi;			n = cn;		}	}	height = i - 1;	if (mt_value("filemenusize") == NULL)		i = DEFMAXFILES;	else		i = atoi(mt_value("filemenusize"));	if (height < i) {		(void) menu_set(mt_file_menu,		    MENU_STRING_ITEM, mt_savestr(file), ++fileuse, 0);	} else {		free((char *)menu_get(smi, MENU_STRING));		(void) menu_set(smi, MENU_STRING, mt_savestr(file), 0);		(void) menu_set(smi, MENU_VALUE, ++fileuse, 0);	}}voidmt_new_folder(file, incorporate, quietly)	char           *file;	int             quietly, incorporate;	/*	 * quietly is used in conjunction with auto-retrieval, which is	 * currently not implemented. It gets new messages, but leave msgsw	 * viewing the message that it is currently displaying 	 */{	int             n, goto_system_mail_box;	char		s[128];	char           *p;	extern char    *index();	/* allow other processes to proceed */	(void)win_release_event_lock(mt_cmdpanel_fd);	mt_yield_all();       /* use mt_yield_all() to save shelf */	if (!mt_nomail)		mt_save_curmsg();	goto_system_mail_box = (strcmp(file, "%") == 0);	quietly = (quietly && !mt_nomail &&		mt_system_mail_box && goto_system_mail_box);	if (incorporate && !mt_nomail &&		mt_system_mail_box && goto_system_mail_box		&& !mt_3x_compatibility) {		/*		 * if in system mail box, and asking to get mail from system		 * mail box, simply incorporate new mail without committing		 * existing changes. 		 */		register	int i;		mt_tool_is_busy(TRUE, "retrieving new mail...");		for (i = mt_maxmsg; i > 0; i--) 			if(!mt_message[i].m_deleted)				break;		if (mt_incorporate_mail()) {		/*		 * mt_incorporate_mail returns FALSE if		 * user is not running latest mail. In this case, drop		 * through and do it old way, i.e., commit and retrieve. 		 */			int	maxmsg = mt_maxmsg;			(void) strcpy(s, mt_info);	/* n new, m unread */			if (mt_is_prefix("No new mail for", mt_info)) {} 			else if ((strcmp(mt_info,				"Mail: skipping garbage before messages\n")					== 0) ||				(!mt_get_headers(maxmsg + 1)) ) 			/*			 * The skipping garbage message occurs if the user			 * runs Mail while inside of mailtool, deletes some			 * messages, and commits, receives some more			 * messages, and then does an incorporate. It is			 * caused by the fact that the place that the Mail			 * that mailtool is attached to thought was the end			 * of the spool file is now in the middle of a			 * message. If the user runs Mail, delets some			 * messages, commits, and then does an incorporate			 * before any new messages have arrived, then Mail			 * will think there is new mail because the spool			 * file has been written, but there won't be any. In			 * this case, mt_get_headers will not find any new			 * messages and will return FALSE. 			 */				mt_warn(mt_headersw, 			"Mail is confused about the state of your spool file.",			"This could occur if you did a commit while running",			"another instance of Mail or mailtool since the last", 			"time you committed in *this* mailtool. Suggest you",			"exit mailtool without committing your changes using",			"the menu behind the 'Done' button. (Note: this will",			"cause any messages that you deleted since the last", 			"time you committed in mailtool to reappear.)",			0);			else {				if (!quietly) 					mt_curmsg = maxmsg + 1;				mt_append_headers(!quietly);				if (!quietly) 					mt_update_msgsw(maxmsg + 1,						TRUE, FALSE, FALSE,						/* mt_load_headers has						 * already positioned						 * the header subwindow						 */						mt_has_selection());			}			mt_scandir = 1;			mt_tool_is_busy(FALSE);			mt_update_info(s);			if (p = index(&s[1], ':'))				mt_set_namestripe_right(++p, TRUE);			else				mt_set_namestripe_right(s, TRUE);			return;		} else 			mt_tool_is_busy(FALSE);	}	s[0] = '\0';	if (mt_3x_compatibility)		(void) strcat(s, "loading messages");	else if (!mt_nomail || strcmp(mt_folder, "[None]") != 0)		(void) strcat(s, "committing changes");	if (mt_3x_compatibility) {} 	else if (goto_system_mail_box) {		if (s[0] != '\0')			(void) strcat(s, " and ");		(void) strcat(s, "retrieving new mail");	} else if (strcmp(file, mt_folder) != 0) {		if (s[0] != '\0')			(void) strcat(s, " and ");		(void) strcat(s, "switching to ");		(void) strcat(s, file);	}	(void) strcat(s, "...");	mt_tool_is_busy(TRUE, s);	if ((n = mt_set_folder(file)) > 0) {		(void) strcpy(s, mt_info);	/* n new, m unread */		mt_system_mail_box = goto_system_mail_box;		mt_delp = NULL;	/* a commit was done so there are no deleted				 * messages to undelete */		mt_del_count = 0;		mt_get_folder();		(void) mt_get_headers(1);	/* sets mt_curmsg, mt_maxmsg */		mt_load_headers();		mt_prevmsg = 0;		mt_update_msgsw(mt_curmsg,				TRUE, FALSE, FALSE,	/* mt_load_headers has							 * already positioned							 * the header subwindow							 */				mt_has_selection());		mt_tool_is_busy(FALSE);		mt_nomail = FALSE;		mt_scandir = 1;		if (mt_panel_style == mt_3DImages)			(void) panel_set(mt_del_item, PANEL_LABEL_IMAGE,				mt_trash_pr, 0);		if (!mt_3x_compatibility)			mt_update_info(s);	/* info item is cleared by						 * mt_update_msgsw */		mt_set_namestripe_left(mt_folder, "", FALSE);		if (p = index(&s[1], ':'))			mt_set_namestripe_right(++p, TRUE);		else			mt_set_namestripe_right(++p, TRUE);	} else if (n == 0) {	/* no new mail */		(void) strcpy(s, mt_info);		mt_system_mail_box = goto_system_mail_box;		mt_delp = NULL;		mt_del_count = 0;		mt_get_folder();		mt_update_info(mt_info);		mt_set_namestripe_left(mt_folder, "[No Mail]", FALSE);		if (p = index(&s[1], ':'))			mt_set_namestripe_right(++p, TRUE);		else			mt_set_namestripe_right(++p, TRUE);		mt_tool_is_busy(FALSE);		mt_set_nomail();		mt_prevmsg = 0;		if (mt_panel_style == mt_3DImages)			(void) panel_set(mt_del_item, PANEL_LABEL_IMAGE,				mt_trash_pr, 0);	} else {		/*		 * either no mail at all, or else a file or folder that		 * doesn't exist 		 */		mt_tool_is_busy(FALSE);		mt_update_info(mt_info);		mt_set_namestripe_left(mt_folder,			(strcmp(file, "%") == 0) ? "" :"[No Mail]",			FALSE);		mt_set_namestripe_right(mt_info, TRUE);		if (mt_is_prefix("No mail for", mt_info)) {}		else			mt_warn(mt_frame, mt_info, 0);			/* incorrect file or folder should be shown to user */	}}static voidmt_set_nomail(){	mt_nomail = TRUE;	textsw_reset(mt_msgsw, 0, 0);	(void) unlink(mt_msgfile);	mt_msg_time = 0;	textsw_reset(mt_headersw, 0, 0);}static intmt_has_selection(){	seln_holder = seln_inquire(SELN_PRIMARY);	return (seln_holder.state != SELN_NONE &&	    seln_holder_same_client(&seln_holder, mt_headersw)) ;}/**************** << C O M M E N T   S E C T I O N  >> ****************  Name    Date    Comment  ----    ----    ------- mjb     5/12/89 Bug# 1012325 fix - checked length of textsw to insure		the replysw will be saved when there is text inside.***********************************************************************/ 

⌨️ 快捷键说明

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