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

📄 textsw_seln_svc.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
static Seln_resultonly_one_buffer(request)	Seln_request	*request;{	Tsfh_handle	 context = (Tsfh_handle)LINT_CAST(					request->requester.context);	if (request->status == SELN_CONTINUED) {	    context->fill_result = TFS_ERROR;	    return(SELN_FAILED);	} else {	    context->fill_result =		textsw_fill_selection_from_reply(context, request);	    return(SELN_SUCCESS);	}}pkg_private inttextsw_selection_from_holder(textsw, selection, holder, type, flags)	register Textsw_folio			 textsw;	register Textsw_selection_handle	 selection;	Seln_holder				*holder;	unsigned				 type, flags;{	extern int		 ev_get_selection();	unsigned		 mode;	register caddr_t	*req_attr;	int			 result = type, to_read;	caddr_t			 req_for_ascii[3];	Seln_result		 query_result;	Tsfh_object		 context;	if (holder) {	    if (holder->state == SELN_NONE)		goto Seln_Error;	    if (SAME_HOLDER(textsw, (caddr_t)LINT_CAST(holder))) {		textsw->holder_state |= holder_flag_from_seln_rank(holder->rank);		result = type = ev_sel_type_from_seln_rank(holder->rank);		if ((type == EV_SEL_PRIMARY) || (type == EV_SEL_SECONDARY))		    goto Get_Local;	    }	    /*	     * Make the request to the selection holder	     */	    if (selection->per_buffer) {		context.view = textsw->first_view;		context.selection = selection;		context.continued_attr = SELN_REQ_END_REQUEST;		context.flags = flags;	    } else {		LINT_IGNORE(ASSERT(0));		goto Seln_Error;	    }	    req_attr = req_for_ascii;	    if (flags & TFS_FILL_IF_OTHER) {		*req_attr++ = (caddr_t)SELN_REQ_CONTENTS_ASCII;		*req_attr++ = (caddr_t)0;  /* Null value */	    }	    *req_attr++ = (caddr_t)0;  /* Null terminate request list */	    query_result =		seln_query(holder, selection->per_buffer,			   (caddr_t)LINT_CAST(&context),			   SELN_REQ_BYTESIZE, ES_INFINITY,			   SELN_REQ_FIRST, ES_INFINITY,			   SELN_REQ_LAST, ES_INFINITY,			   ATTR_LIST, req_for_ascii,			   0);	    if (query_result != SELN_SUCCESS)		goto Seln_Error;	    return(TFS_IS_ERROR(context.fill_result)			? context.fill_result 			: (context.fill_result | result | TFS_IS_OTHER) );	} else {Get_Local:	    mode = ev_get_selection(textsw->views, &selection->first,				    &selection->last_plus_one, type);	    result |= mode;	    if (selection->first >= selection->last_plus_one) {		return(TFS_ERROR);	    }	    if (flags & TFS_FILL_IF_SELF) {		to_read = selection->last_plus_one - selection->first;		selection->buf_max_len =		    textsw_prepare_buf_for_es_read(&to_read, &selection->buf,			selection->buf_max_len, !selection->buf_is_dynamic);		selection->last_plus_one = selection->first + to_read;		selection->buf_len =		    textsw_es_read(			(type & EV_SEL_SHELF)			    ? textsw->trash : textsw->views->esh,			selection->buf,			selection->first, selection->last_plus_one);	    }	    return(result|TFS_IS_SELF);	}Seln_Error:	return(TFS_SELN_SVC_ERROR);}pkg_private inttextsw_func_selection_internal(textsw, selection, type, flags)	register Textsw_folio			textsw;	register Textsw_selection_handle	selection;	unsigned				type, flags;{	Seln_holder		 holder;	int			 result;	if ( ((EV_SEL_BASE_TYPE(type) == EV_SEL_PRIMARY) ||	      (EV_SEL_BASE_TYPE(type) == EV_SEL_SECONDARY)) &&	     (textsw->holder_state & holder_flag_from_textsw_info(type)) ) {	    result = textsw_selection_from_holder(			    textsw, selection, (Seln_holder *)0, type, flags);	} else if (textsw_should_ask_seln_svc(textsw, TRUE)) {	    if (textsw->selection_holder) {		holder = *textsw->selection_holder;	    } else {		holder = seln_inquire(seln_rank_from_textsw_info(type));	    }	    result = textsw_selection_from_holder(			    textsw, selection, &holder, type, flags);	} else {	    result = TFS_SELN_SVC_ERROR;	}	return(result);}pkg_private inttextsw_func_selection(textsw, selection, flags)	register Textsw_folio			textsw;	register Textsw_selection_handle	selection;	unsigned				flags;{	int					result;	if (textsw->selection_holder) {	    result = textsw_selection_from_holder(			    textsw, selection, textsw->selection_holder,			    0, flags);	} else {	    result = textsw_func_selection_internal(			    textsw, selection, EV_SEL_SECONDARY, flags);	    if (TFS_IS_ERROR(result)) {		result = textsw_func_selection_internal(			    textsw, selection, EV_SEL_PRIMARY, flags);	    }	}	selection->type = result;	return(result);}/* ARGSUSED */pkg_private voidtextsw_init_selection_object(    textsw, selection, buf, buf_max_len, buf_is_dynamic)	Textsw_folio			 textsw;    /* Currently unused */	register Textsw_selection_handle selection;	char				*buf;	int				 buf_max_len;	int				 buf_is_dynamic;{	selection->type = 0;	selection->first = selection->last_plus_one = ES_INFINITY;	selection->per_buffer = only_one_buffer;	if (buf) {	    selection->buf = buf;	    selection->buf_max_len = buf_max_len-1;	    selection->buf_is_dynamic = buf_is_dynamic;	} else {	    selection->buf = sv_malloc(SELN_BUFSIZE+1);	    selection->buf_max_len = SELN_BUFSIZE;	    selection->buf_is_dynamic = TRUE;	}	selection->buf_len = 0;}pkg_private inttextsw_is_seln_nonzero(textsw, type)	register Textsw_folio			textsw;	unsigned				type;{	Textsw_selection_object	 selection;	int			 result;	textsw_init_selection_object(textsw, &selection, "", 1, FALSE);	result =	    textsw_func_selection_internal(textsw, &selection, type, 0);	if (TFS_IS_ERROR(result) ||	    (selection.first >= selection.last_plus_one)) {	    return(0);	} else {	    return((result & TFS_IS_SELF) ? 2 : 1);	}}static Seln_resulttextsw_stuff_all_buffers(request)	register Seln_request	*request;{	register Tsfh_handle	 context = (Tsfh_handle)LINT_CAST(						request->requester.context);	int			 status;	if (context->continued_attr == SELN_REQ_END_REQUEST) {	    context->fill_result =		textsw_fill_selection_from_reply(context, request);	    if (TFS_IS_ERROR(context->fill_result)) {		return(SELN_FAILED);	    } else {		status = textsw_input_partial(context->view,					      context->selection->buf,					      context->selection->buf_len);		return(status ? SELN_FAILED : SELN_SUCCESS);	    }	} else if (request->status == SELN_CONTINUED) {	    status = textsw_input_partial(context->view,					  request->data,					  (long int)request->buf_size);	    return(status ? SELN_FAILED : SELN_SUCCESS);	} else if (request->status == SELN_SUCCESS) {	    status = textsw_input_partial(context->view,					  request->data,					  strlen((char *)(request->data)));	    return(status ? SELN_FAILED : SELN_SUCCESS);	} else {	    context->fill_result = TFS_SELN_SVC_ERROR;	    return(SELN_FAILED);	}}pkg_private inttextsw_stuff_selection(view, type)	Textsw_view		view;	unsigned		type;{	register Textsw_folio	folio = FOLIO_FOR_VIEW(view);	Textsw_selection_object	selection;	int			result;	int			delta, record;	Es_index		old_insert_pos, old_length;	textsw_init_selection_object(folio, &selection, NULL, 0, 0);	selection.per_buffer = textsw_stuff_all_buffers;	textsw_input_before(view, &old_insert_pos, &old_length);	result = textsw_func_selection_internal(			folio, &selection, type, TFS_FILL_IF_OTHER);	if ((TFS_IS_ERROR(result) != 0) ||	    (selection.first >= selection.last_plus_one))	    goto Done;	if (result & TFS_IS_SELF) {	    /* Selection is local, so copy pieces, not contents. */	    extern Es_handle	textsw_esh_for_span();	    Es_handle		pieces;	    pieces = textsw_esh_for_span(view, selection.first,					selection.last_plus_one, ES_NULL);	    (void) textsw_insert_pieces(view, old_insert_pos, pieces);	} else {	    record = (TXTSW_DO_AGAIN(folio) &&		      ((folio->func_state & TXTSW_FUNC_AGAIN) == 0) );	    delta = textsw_input_after(view, old_insert_pos, old_length,				       record);	    if AN_ERROR(delta == ES_CANNOT_SET) {}	}Done:	free(selection.buf);	return(result);}/*	========================================================== * *	Routines to support the use of the selection service. * *	========================================================== */pkg_private inttextsw_seln_svc_had_secondary(textsw)	register Textsw_folio	textsw;{	return( (textsw->selection_func.function != SELN_FN_ERROR) &&		(textsw->selection_func.secondary.access.pid != 0) &&		(textsw->selection_func.secondary.state != SELN_NONE) );}pkg_private Seln_responsetextsw_setup_function(folio, function)	register Textsw_folio		 folio;	register Seln_function_buffer	*function;{	register Seln_response		 response;	response = seln_figure_response(function, &folio->selection_holder);#ifdef DEBUG_SVCfprintf(stderr, "Response = %d\n", response);#endif	switch (response) {	  case SELN_IGNORE:	    /* Make sure we don't cause a yield to secondary. */	    function->function = SELN_FN_ERROR;	    return(response);	  case SELN_DELETE:	  case SELN_SHELVE:	    /* holder describes shelf, not sel., so ignore it */	    folio->selection_holder = (Seln_holder *)0;	    /* Fall through */	  case SELN_FIND:	  case SELN_REQUEST:	    break;	  default:	    LINT_IGNORE(ASSUME(0));	    /* Make sure we don't cause a yield to secondary. */	    function->function = SELN_FN_ERROR;	    return(SELN_IGNORE);	}	/*	 * The holder information must be treated with special care, as the	 *   following can otherwise happen:	 *	1) Primary holder (or listener) gets function request	 *	2) Primary gets secondary, then requests secondary to yield	 *	3) Secondary yields, and its state is now correct	 *	4) (Ex)secondary gets same function request, and based on the	 *	   (now out of date) information, notes that it is the	 *	   current secondary holder (and its state is now incorrect).	 *   Although the above is a secondary selection state problem, it	 *   also applies to the other holders, as each holder gets a copy of	 *   the function request (multiple copies if a single client is	 *   multiple holders).	 *	 * The golden rule is that only the "driver" can trust the holder	 *   information!	 */	if (SAME_HOLDER(folio, (caddr_t)LINT_CAST(&function->caret)))	    folio->holder_state |= TXTSW_HOLDER_OF_CARET;	else	    folio->holder_state &= ~TXTSW_HOLDER_OF_CARET;	if (SAME_HOLDER(folio, (caddr_t)LINT_CAST(&function->primary)))	    folio->holder_state |= TXTSW_HOLDER_OF_PSEL;	else	    folio->holder_state &= ~TXTSW_HOLDER_OF_PSEL;	if (SAME_HOLDER(folio, (caddr_t)LINT_CAST(&function->secondary)))	    folio->holder_state |= TXTSW_HOLDER_OF_SSEL;	else	    folio->holder_state &= ~TXTSW_HOLDER_OF_SSEL;	if (SAME_HOLDER(folio, (caddr_t)LINT_CAST(&function->shelf)))	    folio->holder_state |= TXTSW_HOLDER_OF_SHELF;	else	    folio->holder_state &= ~TXTSW_HOLDER_OF_SHELF;	textsw_take_down_caret(folio);	return(response);}pkg_private voidtextsw_end_selection_function(folio)	register Textsw_folio	folio;{	folio->selection_holder = (Seln_holder *)0;	if (folio->selection_func.function != SELN_FN_ERROR) {	    if (textsw_seln_svc_had_secondary(folio) &&		((folio->holder_state & TXTSW_HOLDER_OF_SSEL) == 0)) {		(void) seln_ask(&folio->selection_func.secondary,				SELN_REQ_YIELD, 0,				0);	    }	    folio->selection_func.function = SELN_FN_ERROR;	}}pkg_private voidtextsw_seln_svc_function(first_view, function)	Textsw_view			 first_view;	register Seln_function_buffer	*function;{	Seln_response			 response;	register Textsw_folio		 textsw = FOLIO_FOR_VIEW(first_view);	register int			 result = 0;	response = textsw_setup_function(textsw, function);	if (!textsw->func_view) {	    textsw->func_view = first_view;	    textsw->func_x = textsw->func_y = 0;	}	textsw->selection_func = *function;	textsw->func_state &= ~TXTSW_FUNC_SVC_SAW_ALL;	textsw->func_state |= (TXTSW_FUNC_EXECUTE | TXTSW_FUNC_SVC_REQUEST);	switch (response) {	  case SELN_REQUEST:

⌨️ 快捷键说明

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