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

📄 textsw_seln_svc.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	    switch (function->function) {	      case SELN_FN_GET:		textsw->func_state |= TXTSW_FUNC_GET;		result |= textsw_end_get(textsw->func_view);		break;	      case SELN_FN_PUT:		textsw->func_state |= TXTSW_FUNC_PUT;		result = textsw_end_put(textsw->func_view);		break;	    }	    break;	  case SELN_SHELVE:	    textsw->func_state |= TXTSW_FUNC_PUT;	    result = textsw_end_put(textsw->func_view);	    break;	  case SELN_FIND:	    textsw->func_state |= TXTSW_FUNC_FIND;	    textsw_end_find(textsw->func_view,			    textsw->func_x, textsw->func_y);	    break;	  case SELN_DELETE:	    textsw->func_state |= TXTSW_FUNC_DELETE;	    result |= textsw_end_delete(textsw->func_view);	    break;	  default:	    goto Done;	}	if (result & TEXTSW_PE_READ_ONLY)	    textsw_read_only_msg((Textsw_folio)textsw->func_view,				 textsw->func_x, textsw->func_y);Done:	textsw_clear_pending_func_state(textsw);	textsw->func_state &= ~TXTSW_FUNC_SVC_ALL;	textsw->func_view = (Textsw_view)0;	textsw->state &= ~TXTSW_PENDING_DELETE;	textsw->track_state &= ~TXTSW_TRACK_ALL;	textsw_end_selection_function(textsw);}#define	TCAR_CONTINUED	0x40000000#define	TCARF_ESH	0#define	TCARF_STRING	1static inttextsw_copy_ascii_reply(first, last_plus_one, response,		        max_length, flags, data)	Es_index		 first, last_plus_one;	register caddr_t	*response;	int			 max_length;	unsigned		 flags;	caddr_t			 data;{	register char		*dest = (char *)response;	int			 count, continued;	if (continued = (max_length < (last_plus_one-first))) {	    switch (flags) {	      case TCARF_ESH:		count = textsw_es_read((Es_handle)LINT_CAST(data), dest,				       first, first+max_length);		break;	      case TCARF_STRING:		count = max_length;		bcopy(((char *)data)+first, dest, count);		break;	      default:		LINT_IGNORE(ASSUME(0));		count = 0;		break;	    }	} else {	    count = last_plus_one - first;	    if (count) {		switch (flags) {		  case TCARF_ESH:		    count = textsw_es_read((Es_handle)LINT_CAST(data), dest,					   first, last_plus_one);		    break;		  case TCARF_STRING:		    bcopy(((char *)data)+first, dest, count);		    break;		  default:		    LINT_IGNORE(ASSUME(0));		    break;		}	    }	    /* Null terminate string (and round count up.  If count is	     *   already rounded, then the null that terminates	     *   the value doubles as the string terminator.)	     */	    while ((count % sizeof(*response)) != 0) {		dest[count++] = '\0';	    }	}	return((continued) ? count+TCAR_CONTINUED : count);}char *textsw_base_name(full_name)	char *full_name;{	extern char	*rindex();	register char	*temp;	if ((temp = rindex(full_name, '/')) == NULL)	    return(full_name);	else	    return(temp+1);}pkg_private Es_indextextsw_check_valid_range(esh, first, ptr_last_plus_one)	register Es_handle	 esh;	register Es_index	 first;	Es_index		*ptr_last_plus_one;	/* Can be NULL */{	register Es_index	 first_valid = first;	int			 count_read;	char			 buf[200];   /* Must be bigger than wrap msg */	if (first != ES_INFINITY &&	    ((int)LINT_CAST(es_get(esh, ES_PS_SCRATCH_MAX_LEN)) !=	      	ES_INFINITY) ) {	    (void) es_set_position(esh, first);	    first_valid = es_read(esh, sizeof(buf)-1, buf, &count_read);	    if (first+count_read == first_valid) {		first_valid = first;	    } else {		/* Hit hole, use es_read result, but check last_plus_one */		if (ptr_last_plus_one &&		    *ptr_last_plus_one < first_valid) {		    *ptr_last_plus_one = first_valid;		}	    }	}	return(first_valid);}pkg_private Seln_resulttextsw_seln_svc_reply(attr, context, max_length)	Seln_attribute		    attr;	register Seln_replier_data *context;	int			    max_length;{	Textsw_view		    first_view = (Textsw_view)					    LINT_CAST(context->client_data);	register Textsw_folio	    textsw = FOLIO_FOR_VIEW(first_view);	register Continuation	    cont_data;	register Seln_result	    result = SELN_SUCCESS;	if (context->context) {	    cont_data = (Continuation)LINT_CAST(context->context);	} else if (attr == SELN_REQ_END_REQUEST) {	    /* Don't set up state after having already flushed it due to	     * previous error.	     */	    cont_data = (Continuation)0;	} else {	    unsigned	holder_flag =			holder_flag_from_seln_rank(context->rank);	    /* First attribute: set up for this set of replies. */	    if (fast_continuation.in_use) {	    	cont_data = NEW(Continuation_object);	    } else {	    	cont_data = &fast_continuation;	    }	    cont_data->in_use = TRUE;	    context->context = (char *)cont_data;	    if ((textsw->holder_state & holder_flag) == 0) {		result = SELN_DIDNT_HAVE;		goto Return;	    } 	    switch (context->rank) {	      case SELN_CARET:		cont_data->type = EV_SEL_CARET;		cont_data->first = cont_data->last_plus_one = ES_INFINITY;		break;	      case SELN_PRIMARY:		cont_data->type = EV_SEL_PRIMARY;		goto Get_Info;	      case SELN_SECONDARY:		cont_data->type = EV_SEL_SECONDARY;Get_Info:		cont_data->span_level = textsw->span_level;		ev_get_selection(textsw->views, &cont_data->first,				 &cont_data->last_plus_one,				(unsigned)cont_data->type);		break;	      case SELN_SHELF:		cont_data->type = EV_SEL_SHELF;		if (textsw->trash) {		    cont_data->first = es_set_position(textsw->trash, 0);		    cont_data->last_plus_one = es_get_length(textsw->trash);		} else {		    cont_data->first = cont_data->last_plus_one = ES_INFINITY;		}		break;	      default:		result = SELN_FAILED;		goto Return;	    }	    cont_data->current = ES_INFINITY;	    /* Check for, and handle, wrap-around edit log */	    cont_data->first = textsw_check_valid_range(		(cont_data->type == EV_SEL_SHELF)		  ? textsw->trash : textsw->views->esh,		cont_data->first,		&cont_data->last_plus_one);	}	switch(attr) {	  case SELN_REQ_BYTESIZE:	    *context->response_pointer++ =		(caddr_t)(cont_data->last_plus_one - cont_data->first);	    goto Return;	  case SELN_REQ_CONTENTS_ASCII: {	    int		continued, count;	    Es_index	current_first;	    Es_handle	esh_to_use;	    esh_to_use = (cont_data->type == EV_SEL_SHELF)			    ? textsw->trash : textsw->views->esh;	    current_first = (cont_data->current == ES_INFINITY)			    ? cont_data->first : cont_data->current;	    count = textsw_copy_ascii_reply(		current_first, cont_data->last_plus_one,		context->response_pointer, max_length, TCARF_ESH,		(caddr_t)esh_to_use);	    if (continued = (count >= TCAR_CONTINUED))		count -= TCAR_CONTINUED;	    context->response_pointer +=		(count / sizeof(*context->response_pointer));	    if (continued) {		cont_data->current = current_first + count;		result = SELN_CONTINUED;	    } else {	        *context->response_pointer++ = 0;    /* Null terminate value */		cont_data->current = ES_INFINITY;	    }	    goto Return;	  }	  case SELN_REQ_COMMIT_PENDING_DELETE: {	    (void) textsw_do_pending_delete(first_view, EV_SEL_SECONDARY, 0);	    goto Return;	  }	  case SELN_REQ_DELETE: {	    (void) textsw_delete_span(		    first_view, cont_data->first, cont_data->last_plus_one,		    TXTSW_DS_ADJUST|TXTSW_DS_SHELVE);	    goto Return;	  }	  case SELN_REQ_FAKE_LEVEL: {	    Seln_level	target_level = (Seln_level)*context->request_pointer;	    switch (target_level) {	      case TEXTSW_UNIT_IS_LINE:		cont_data->span_level = EI_SPAN_LINE;		ev_span(textsw->views, cont_data->first, &cont_data->first,			&cont_data->last_plus_one, EI_SPAN_LINE);		*context->response_pointer++ = (caddr_t)target_level;		break;	      default:		LINT_IGNORE(ASSUME(0));	/* Let implementor look at this. */		*context->response_pointer++ = (caddr_t)(0xFFFFFFFF);		break;	    }	    goto Return;	  }	  case SELN_REQ_FILE_NAME: {	    char	*name;	    int	continued, count;	    int	str_first, str_last_plus_one;	    if (textsw_file_name(textsw, &name) != 0) {		*context->response_pointer++ = 0;  /* Null terminate value */		goto Return;	    }	    /* For dbxtool: return full name, rather than base name ...	    name = textsw_base_name(name);	     */	    str_first = (cont_data->current == ES_INFINITY)			? 0 : cont_data->current;	    str_last_plus_one = strlen(name);	    count = textsw_copy_ascii_reply(		str_first, str_last_plus_one,		context->response_pointer,		max_length, TCARF_STRING, name);	    if (continued = (count >= TCAR_CONTINUED))		count -= TCAR_CONTINUED;	    context->response_pointer +=		(count / sizeof(*context->response_pointer));	    *context->response_pointer++ = 0;  /* Null terminate value */	    if (continued) {		cont_data->current = str_first+count;		result = SELN_CONTINUED;	    } else {		cont_data->current = ES_INFINITY;	    }	    goto Return;	  }	  case SELN_REQ_FIRST:	    *context->response_pointer++ = (caddr_t)cont_data->first;	    goto Return;	  case SELN_REQ_FIRST_UNIT:	    switch (cont_data->span_level) {	      case EI_SPAN_LINE: {		int	line_number;		if (cont_data->first == 0)		    line_number = 0;		else		    line_number = ev_newlines_in_esh(textsw->views->esh,						     0, cont_data->first);		*context->response_pointer++ = (caddr_t)line_number;		break;	      }	      case EI_SPAN_CHAR:		/* Fall through */	      default:	/* BUG ALERT: if in doubt, use char units. */		*context->response_pointer++ = (caddr_t)cont_data->first;	    }	    goto Return;	  case SELN_REQ_LAST:	    *context->response_pointer++ =		(caddr_t)(cont_data->last_plus_one-1);	    goto Return;	  case SELN_REQ_LAST_UNIT:	    /* BUG ALERT: look at current level and adjust for it. */	    *context->response_pointer++ = (caddr_t)-1;	    goto Return;	  case SELN_REQ_YIELD: {	    result = textsw_seln_yield(textsw->first_view, context->rank);	    *context->response_pointer++ = (caddr_t)result;	    goto Return;	  }	  case SELN_REQ_END_REQUEST:	    result = SELN_FAILED;	/* Ignored by caller! */	    goto Return;	  default:	    result = SELN_UNRECOGNIZED;	    goto Return;	}Return:	switch (result) {	  case SELN_SUCCESS:	  case SELN_CONTINUED:	  case SELN_UNRECOGNIZED:	    break;	  default:	    /* We are not going to get another chance, so clean up. */	    if (cont_data == &fast_continuation) {		cont_data->in_use = FALSE;	    } else {		free((caddr_t)cont_data);	    }	    context->context = NULL;	/* Be paranoid! */	}	return(result);}static Seln_resulttextsw_seln_yield(first_view, rank)	Textsw_view		first_view;	register Seln_rank	rank;{	register Textsw_folio	textsw = FOLIO_FOR_VIEW(first_view);	unsigned		holder_flag = holder_flag_from_seln_rank(rank);	if (holder_flag) {	    switch (rank) {	      case SELN_PRIMARY:		textsw_set_selection(VIEW_REP_TO_ABS(textsw->first_view),				     ES_INFINITY, ES_INFINITY, EV_SEL_PRIMARY);		break;	      case SELN_SECONDARY:		textsw_set_selection(VIEW_REP_TO_ABS(textsw->first_view),				     ES_INFINITY, ES_INFINITY,				     EV_SEL_SECONDARY);		textsw->track_state &= ~TXTSW_TRACK_SECONDARY;		break;	      case SELN_SHELF:		if (textsw->trash) {		    es_destroy(textsw->trash);		    textsw->trash = ES_NULL;		}		break;	    }	    textsw->holder_state &= ~holder_flag;	    return(SELN_SUCCESS);	} else {	    return(SELN_DIDNT_HAVE);	}}

⌨️ 快捷键说明

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