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

📄 textsw_again.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	count = textsw_scanf(again, "%d", &pieces);	CHECK_ERROR(count != 1 || pieces == (Es_handle)NULL);	CHECK_ERROR(*TXTSW_STRING_BASE(again)++ != '\n');Again_Error:	return(pieces);#undef CHECK_ERROR}static inttextsw_text_for_replay(again, ptr_to_buffer)	register string_t	 *again;	register char		**ptr_to_buffer;{#define CHECK_ERROR(test)	if AN_ERROR(test) goto Again_Error;	int			  count, length = -1;	count = textsw_scanf(again, "%d", &length);	CHECK_ERROR(count != 1 || length < 0);	CHECK_ERROR(textsw_next_is_delimiter(again) == 0);	CHECK_ERROR(*TXTSW_STRING_BASE(again)++ != '\n');	if (length) {	    *ptr_to_buffer = sv_malloc(		(unsigned)(length+1) * (sizeof(**ptr_to_buffer)+1));	    (void) strncpy(*ptr_to_buffer, TXTSW_STRING_BASE(again), length);	    TXTSW_STRING_BASE(again) += length;	} else {	    *ptr_to_buffer = NULL;	}	CHECK_ERROR(*TXTSW_STRING_BASE(again)++ != '\n');	CHECK_ERROR(*TXTSW_STRING_BASE(again)++ != text_delimiter[0]);	CHECK_ERROR(*TXTSW_STRING_BASE(again)++ != '\n');Again_Error:	return(length);#undef CHECK_ERROR}static char *token_index(string, token)	char		*string;	register char	*token;{	register char	*result = string, *r, *t;	if (result == NULL || token == NULL)	    goto NoMatch;	for (; *result; result++) {	    if (*result == *token) {		r = result+1;		for (t = token+1; *t; r++, t++) {		    if (*r != *t) {			if (*r == 0)			    goto NoMatch;			else			    break;		    }		}		if (*t == 0)		    return(result);	    }	}NoMatch:	return(NULL);}/* ARGSUSED */pkg_privatetextsw_free_again(textsw, again)	Textsw_folio		 textsw;	/* Currently unused */	register string_t	*again;{	char			*saved_base = TXTSW_STRING_BASE(again);	Es_handle		 pieces;	if (TXTSW_STRING_IS_NULL(again))	    return;	ASSERT(allock());	while ((TXTSW_STRING_BASE(again) = token_index(		    TXTSW_STRING_BASE(again), text_tokens[PIECES_TOKEN]))		!= NULL) {	    TXTSW_STRING_BASE(again) += strlen(text_tokens[PIECES_TOKEN]);	    if (pieces = textsw_pieces_for_replay(again))		es_destroy(pieces);	}	free(saved_base);	ASSERT(allock());	*again = null_string;}pkg_private inttextsw_get_recorded_x(view)	register Textsw_view	 view;{#define CHECK_ERROR(test)	if AN_ERROR(test) goto Again_Error;	register Textsw_folio	 folio = FOLIO_FOR_VIEW(view);	register string_t	*again;	char			*buffer = NULL,				*saved_base;	char			 token_buf[20];	register char		*token = token_buf;	register int		 count;	Textsw_Caret_Direction	 direction;	int			 loc_x, result = -1;	int			 found_it_already = FALSE;		if (!TXTSW_DO_AGAIN(folio))	    return;	again = &folio->again[0];	if (TXTSW_STRING_IS_NULL(again)) {	    return(result);	}	saved_base = TXTSW_STRING_BASE(again);	ev_set(0, folio->views, EV_CHAIN_DELAY_UPDATE, TRUE, 0);	FOREVER {	    count = textsw_scanf(again, "%19s", token);	    if (count == -1)		break;	    ASSERT(count == 1);	    count = match_in_table(token, cmd_tokens);	    CHECK_ERROR(count < 0);	    if (buffer != NULL) {		free(buffer);		buffer = NULL;	    }	    if ((Token)count == CARET_TOKEN) {	        count = textsw_scanf(again, "%x %d", &direction, &loc_x);	        CHECK_ERROR(count != 2);	        	        if ((direction == TXTSW_NEXT_LINE) ||	            (direction == TXTSW_PREVIOUS_LINE)) {	            if (!found_it_already) {	                result = loc_x;	                found_it_already = TRUE;	            }	        } else {	           if (found_it_already)  {	           /* 	            * Any other direction following TXTSW_NEXT_LINE or 	            * TXTSW_PREVIOUS_LINE will clear the loc_x value 	            */	 	                result = -1;	                found_it_already = FALSE; 	           }	        }	        	    } else if (found_it_already)  {	    /* 	     * Any other event following TXTSW_NEXT_LINE or 	     * TXTSW_PREVIOUS_LINE will clear the loc_x value 	     */	        result = -1;	        found_it_already = FALSE; 	    }	}Again_Error:	if (buffer != NULL)	    free(buffer);	ev_set(0, folio->views, EV_CHAIN_DELAY_UPDATE, FALSE, 0);	ev_update_chain_display(folio->views);	TXTSW_STRING_BASE(again) = saved_base;	ASSERT(allock());#undef CHECK_ERROR	return(result);	}	pkg_privatetextsw_do_again(view, x, y)	register Textsw_view	 view;	int			 x, y;{#define CHECK_ERROR(test)	if AN_ERROR(test) goto Again_Error;	pkg_private Es_index	 ev_get_insert();	pkg_private int		 ev_get_selection();	pkg_private voidtextsw_move_caret ();	register Textsw_folio	 textsw = FOLIO_FOR_VIEW(view);	register string_t	*again;	char			*buffer = NULL,				*saved_base;	char			 token_buf[20];	register char		*token = token_buf;	register int		 buffer_length, count;	Es_index		 first, last_plus_one;	if (!TXTSW_DO_AGAIN(textsw))	    return;	again = &textsw->again[0];	if (TXTSW_STRING_IS_NULL(again)) {	    again = &textsw->again[1];	    if (TXTSW_STRING_IS_NULL(again))		return;	}	saved_base = TXTSW_STRING_BASE(again);	(void) ev_get_selection(textsw->views, &first, &last_plus_one,				EV_SEL_PRIMARY);	ev_set(0, textsw->views, EV_CHAIN_DELAY_UPDATE, TRUE, 0);	FOREVER {	    count = textsw_scanf(again, "%19s", token);	    if (count == -1)		break;	    ASSERT(count == 1);	    count = match_in_table(token, cmd_tokens);	    CHECK_ERROR(count < 0);	    if (buffer != NULL) {		free(buffer);		buffer = NULL;	    }	    switch ((Token)count) {	      case CARET_TOKEN: {	        unsigned	direction;	        int		unused;  /* This is an x location */	        	        count = textsw_scanf(again, "%x %d", &direction, &unused);	        CHECK_ERROR(count != 2);	        (void)textsw_move_caret (view, (Textsw_Caret_Direction)direction);	        break;	      }	      case DELETE_TOKEN:		CHECK_ERROR(*TXTSW_STRING_BASE(again)++ != '\n');		/*		 * Do the delete and update the selection.		 */		(void) textsw_delete_span(view, first, last_plus_one,					  TXTSW_DS_ADJUST|TXTSW_DS_SHELVE);		first = last_plus_one;		break;	      case EDIT_TOKEN: {		unsigned	unit, direction;		/*		 * Determine the type of edit.		 */		count = textsw_scanf(again, "%19s", token);		CHECK_ERROR(count != 1);		count = match_in_table(token, edit_tokens);		switch (count) {		  case CHAR_TOKEN:		    unit = EV_EDIT_CHAR;		    break;		  case WORD_TOKEN:		    unit = EV_EDIT_WORD;		    break;		  case LINE_TOKEN:		    unit = EV_EDIT_LINE;		    break;		  default:			/* includes case -1 */		    LINT_IGNORE(CHECK_ERROR(TRUE));		}		/*		 * Determine the direction of edit.		 */		count = textsw_scanf(again, "%19s", token);		CHECK_ERROR(count != 1);		count = match_in_table(token, direction_tokens);		switch ((Direction)count) {		  case FORWARD_DIR:		    direction = 0;		    break;		  case BACKWARD_DIR:		    direction = EV_EDIT_BACK;		    break;		  default:			/* includes case -1 */		    LINT_IGNORE(CHECK_ERROR(TRUE));		}		CHECK_ERROR(*TXTSW_STRING_BASE(again)++ != '\n');		/*		 * Process the selection.		 */		if (first < last_plus_one) {		    (void) textsw_set_selection(			VIEW_REP_TO_ABS(view),			ES_INFINITY, ES_INFINITY, EV_SEL_PRIMARY);		    first = last_plus_one = ES_INFINITY;		}		/*		 * Finally, do the actual edit.		 */		(void) textsw_do_edit(view, unit, direction);		break;	      }	      	      case EXTRAS_TOKEN: {	        pkg_private char **string_to_argv();	        char	**filter_argv;	        int	cmd_len;	        	        CHECK_ERROR(textsw_next_is_delimiter(again) == 0);		        buffer_length = textsw_text_for_replay(again, &buffer);	        CHECK_ERROR(buffer_length <= 0);	        	        buffer[buffer_length] = NULL; /* In case garbage follow */	        filter_argv = string_to_argv(buffer);	        (void) textsw_call_filter(view, filter_argv);	        	        break;	      }	      	      case FIELD_TOKEN: {	        unsigned     options = EV_SEL_PRIMARY;	        unsigned     field_flag;	        int	     matched;	        char	     start_marker[3];	        	        count = textsw_scanf(again, "%x", &field_flag);	        CHECK_ERROR(count != 1);	        count = textsw_scanf(again, "%3s", start_marker);	        CHECK_ERROR(count != 1);	        	            	        textsw_flush_caches(view, TFC_STD);	        	        if ((field_flag == TEXTSW_FIELD_ENCLOSE) || 	            (field_flag == TEXTSW_DELIMITER_ENCLOSE)) {	           int		first, last_plus_one;	           	           first = last_plus_one = ev_get_insert(textsw->views);	           matched = textsw_match_field_and_normalize(view, &first, &last_plus_one, start_marker, strlen(start_marker), field_flag, TRUE);	        } else {		    matched = textsw_match_selection_and_normalize(view,  start_marker, field_flag);		}		CHECK_ERROR(!matched);		(void) ev_get_selection(textsw->views, &first, &last_plus_one,				EV_SEL_PRIMARY);		        break;	      }	      case FILTER_TOKEN: {		Event	event;		int	dummy;		count = textsw_scanf(again, "%x", &dummy);		CHECK_ERROR(count != 1);		event_set_action(&event, dummy);		count = textsw_scanf(again, "%x", &dummy);		CHECK_ERROR(count != 1);		event.ie_flags = dummy & (~IE_NEGEVENT);		count = textsw_scanf(again, "%x", &dummy);		CHECK_ERROR(count != 1);		event.ie_shiftmask = dummy;		event.ie_locx = x;		event.ie_locy = y;		event.ie_time = textsw->last_point;			/* Something reasonable */		CHECK_ERROR(textsw_next_is_delimiter(again) == 0);		/*		 * Enter the filtering state		 */		 (void) textsw_do_filter(view, &event);		buffer_length = textsw_text_for_replay(again, &buffer);		if (buffer_length > 0) {		    bcopy(buffer, textsw->to_insert, buffer_length);		    textsw->to_insert_next_free =			textsw->to_insert + buffer_length;		}		/*		 * Actually invoke the filter		 */		event.ie_flags |= IE_NEGEVENT;		(void) textsw_do_filter(view, &event);		/*		 * Find out what the selection looks like now		 */		(void) ev_get_selection(textsw->views, &first,					&last_plus_one, EV_SEL_PRIMARY);		break;	      }	      case FIND_TOKEN: {		unsigned	flags = EV_FIND_DEFAULT;		Es_index	insert = ev_get_insert(textsw->views);		/*		 * Determine the direction of the search.		 */		count = textsw_scanf(again, "%19s", token);		CHECK_ERROR(count != 1);		count = match_in_table(token, direction_tokens);		CHECK_ERROR(count < 0);		switch ((Direction)count) {		  case BACKWARD_DIR:		    CHECK_ERROR(textsw_next_is_delimiter(again) == 0);		    flags = EV_FIND_BACKWARD;		    if (first >= last_plus_one) {			first = insert;		    }		    break;		  case FORWARD_DIR:		  case EMPTY_DIR:		    CHECK_ERROR(textsw_next_is_delimiter(again) == 0);		    if (first >= last_plus_one) 			first = insert;		    else 			first = last_plus_one;		    		    break;		  default:		    break;		}		/*		 * Get the pattern for the search, then do it.		 */		buffer_length = textsw_text_for_replay(again, &buffer);		CHECK_ERROR(buffer_length <= 0);		textsw_find_pattern_and_normalize(			view, x, y, &first, &last_plus_one,			buffer, (u_int)buffer_length, flags);		CHECK_ERROR(first == ES_CANNOT_SET);		/*		 * Find out what the selection looks like now		 */		(void) ev_get_selection(textsw->views, &first,					&last_plus_one, EV_SEL_PRIMARY);		break;	      }	      case INSERT_TOKEN: {		(void) textsw_do_pending_delete(view, EV_SEL_PRIMARY,						TFC_INSERT|TFC_SEL);		first = last_plus_one;		/*		 * Determine the type of text to be inserted.		 */		count = textsw_scanf(again, "%19s", token);		CHECK_ERROR(count != 1);		count = match_in_table(token, text_tokens);		switch (count) {		  case DELIMITER_TOKEN:		    buffer_length = textsw_text_for_replay(again, &buffer);		    CHECK_ERROR(buffer_length <= 0);		    (void) textsw_do_input(view, buffer, (long)buffer_length,		    			   TXTSW_UPDATE_SCROLLBAR_IF_NEEDED);		    break;		  case PIECES_TOKEN: {		    Es_handle		pieces;		    Es_index		pos = ev_get_insert(textsw->views);		    pieces = textsw_pieces_for_replay(again);		    (void) textsw_insert_pieces(view, pos, pieces);		    break;		  }		  case TRASH_TOKEN: {		    Es_index		pos = ev_get_insert(textsw->views);		    (void) textsw_insert_pieces(view, pos, textsw->trash);		    break;		  }		  default:		    LINT_IGNORE(CHECK_ERROR(TRUE));	/* includes case -1 */		}		break;	      }	      default:		LINT_IGNORE(CHECK_ERROR(TRUE));	    }	}Again_Error:	if (buffer != NULL)	    free(buffer);	ev_set(0, textsw->views, EV_CHAIN_DELAY_UPDATE, FALSE, 0);	ev_update_chain_display(textsw->views);	TXTSW_STRING_BASE(again) = saved_base;	ASSERT(allock());#undef CHECK_ERROR}

⌨️ 快捷键说明

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