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

📄 textsw_search.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lint#ifdef sccsstatic  char sccsid[] = "@(#)textsw_search.c 1.1 92/07/30";#endif#endif/* * Copyright (c) 1986 by Sun Microsystems, Inc. *//* * Routines for moving textsw caret. */  #include <suntool/primal.h>#include <suntool/textsw_impl.h>#include <suntool/ev_impl.h>#include <sys/time.h>#include <signal.h>#include <suntool/frame.h>#include <suntool/panel.h>#include <suntool/window.h>#include <suntool/textsw.h>#include <suntool/walkmenu.h>#include <suntool/wmgr.h>#include <sunwindow/pixwin.h>#include <sunwindow/win_struct.h>#include <sunwindow/win_screen.h>#define		MAX_DISPLAY_LENGTH	50#define   	MAX_STR_LENGTH		1024#define		MAX_PANEL_ITEMS		10#define    DONT_RING_BELL		0x00000000#define    RING_IF_NOT_FOUND		0x00000001#define    RING_IF_ONLY_ONE		0x00000002#define HELP_INFO(s) HELP_DATA,s,typedef enum {    FIND_ITEM			= 0,    FIND_STRING_ITEM		= 1,    DONE_ITEM			= 2,    REPLACE_ITEM		= 3,    REPLACE_STRING_ITEM		= 4,    WRAP_ITEM			= 5,    FIND_THEN_REPLACE_ITEM	= 6,    REPLACE_THEN_FIND_ITEM	= 7,    REPLACE_ALL_ITEM		= 8,    BLINK_PARENT_ITEM		= 9} Panel_item_enum;static Panel_item	panel_items[MAX_PANEL_ITEMS];static Menu		direction_menu;int			process_aborted;	/* Stop key is down *//*---------------------------------------------------  search_frame represents the frame that the user can  bring up to do find-and-replace operations on the text.  It is also stored in the folio which owns the view  from which this search_frame was created.---------------------------------------------------*/Frame			search_frame;pkg_private Textsw_viewview_from_panel_item(panel_item)	Panel_item	panel_item;{	Panel		panel = panel_get(panel_item, PANEL_PARENT_PANEL, 0);	Window		search_frame = (Window) window_get (panel, WIN_OWNER, 0);	Textsw_view	view = (Textsw_view) window_get(search_frame, WIN_CLIENT_DATA, 0);	return(view);	}pkg_private inttextsw_get_selection(view, first, last_plus_one, selected_str, max_str_len)	Textsw_view 	view;	int		*first, *last_plus_one;	char		*selected_str;	int		max_str_len;{/* *  Return true iff primary selection is in the textsw of current view. *  If there is a selection in any of the textsw and selected_str is not null, then *  it will copy it to selected_str. */	Textsw_folio		 folio = FOLIO_FOR_VIEW(view);	Textsw_selection_object	 selection;	char			 selection_buf[MAX_STR_LENGTH];	unsigned        	 options = EV_SEL_PRIMARY;		textsw_init_selection_object(	    folio, &selection, selection_buf, sizeof(selection_buf), FALSE);		selection.type = textsw_func_selection_internal(		folio, &selection, EV_SEL_BASE_TYPE(options),		TFS_FILL_ALWAYS);		textsw_clear_secondary_selection(folio, selection.type);		if ((selection.type & TFS_IS_SELF) &&	    (selection.type & EV_SEL_PRIMARY)) {	    /* If this window owns the primary selection, do nothing. */	} else {        	    				    	    	    selection.first = selection.last_plus_one = ES_CANNOT_SET;	    	}			if ((selection.type & EV_SEL_PRIMARY) &&	     (selection.buf_len > 0) && (selected_str != NULL)) {	     	   if (selection.buf_len >= max_str_len)	       selection.buf_len = max_str_len-1;	         	   strncpy(selected_str, selection.buf, selection.buf_len);	   selected_str[selection.buf_len] = NULL;	} 			*first = selection.first;	*last_plus_one = selection.last_plus_one;		return((*first != ES_CANNOT_SET) && (*last_plus_one != ES_CANNOT_SET));}Es_indexdo_search_proc(view, direction, ring_bell_status, wrapping_off)	Textsw_view 		view;	unsigned		direction;	unsigned		ring_bell_status;	int			wrapping_off;	{	Textsw_folio	folio = FOLIO_FOR_VIEW(view);	Es_index	first, last_plus_one;	char		buf[MAX_STR_LENGTH];	int		str_len;	Es_index	start_pos;				if (!textsw_get_selection(view, &first, &last_plus_one, NULL, 0))	    first = last_plus_one = ev_get_insert(folio->views);	    	if (direction == EV_FIND_DEFAULT)  	    first = last_plus_one;	      	strncpy (buf, (char *)panel_get( 	        panel_items[(int)FIND_STRING_ITEM], PANEL_VALUE), MAX_STR_LENGTH);	        	str_len = strlen(buf);	start_pos = (direction & EV_FIND_BACKWARD)			? first : (first - str_len);	textsw_find_pattern(folio, &first, &last_plus_one, buf, str_len, direction); 		if (wrapping_off) {	    if (direction == EV_FIND_DEFAULT)	       first = (start_pos > last_plus_one) ? ES_CANNOT_SET : first;	    else	       first = (start_pos < last_plus_one) ? ES_CANNOT_SET : first;   	}	               if ((first == ES_CANNOT_SET) || (last_plus_one == ES_CANNOT_SET)) {            if (ring_bell_status & RING_IF_NOT_FOUND)               (void) window_bell(WINDOW_FROM_VIEW(view));            return(ES_CANNOT_SET);        } else {            if ((ring_bell_status & RING_IF_ONLY_ONE) && (first == start_pos))                (void) window_bell(WINDOW_FROM_VIEW(view));                            textsw_possibly_normalize_and_set_selection(		VIEW_REP_TO_ABS(view), first, last_plus_one, EV_SEL_PRIMARY);			    (void) textsw_set_insert(folio, last_plus_one);	    textsw_record_find(folio, buf, str_len, (int)direction);            return ((direction == EV_FIND_DEFAULT) ? last_plus_one : first);        }	}	static intdo_replace_proc(view)    	Textsw_view 	view;{	Textsw		textsw = VIEW_REP_TO_ABS(view);	char		buf[MAX_STR_LENGTH];		int		selection_found;	int		first, last_plus_one;				 if (selection_found = textsw_get_selection(view, &first, &last_plus_one, NULL, 0)) {	     strncpy (buf, (char *)panel_get (	             panel_items[(int)REPLACE_STRING_ITEM], PANEL_VALUE), MAX_STR_LENGTH);	     textsw_replace(textsw, first, last_plus_one, buf, strlen(buf));	 }		return(selection_found);}static voidreplace_all_proc(view, do_replace_first, direction)	Textsw_view 	view;	int		do_replace_first;	unsigned	direction;{	register Textsw_folio	folio = FOLIO_FOR_VIEW(view);	int			start_checking = FALSE;   /* See if now is the time to check for wrap point */	Es_index		cur_pos, prev_pos;	register Es_index	cur_mark_pos, 				first, last_plus_one;	Ev_mark_object		mark;	register int		exit_loop = FALSE;	int			first_time = TRUE;	int			wrapping_off = (int)panel_get(panel_items[(int)WRAP_ITEM], PANEL_VALUE);        char str_buf[MAX_STR_LENGTH];		if (do_replace_first)	    (void) do_replace_proc(view);	process_aborted = FALSE;		cur_mark_pos = prev_pos = cur_pos = do_search_proc(view, direction, RING_IF_NOT_FOUND, wrapping_off);		exit_loop = (cur_pos == ES_CANNOT_SET);              /* get the selected string */        strcpy (str_buf, (char *)panel_get               (panel_items[(int)FIND_STRING_ITEM], PANEL_VALUE),                 MAX_STR_LENGTH);   	while (!process_aborted && !exit_loop) {	    if (start_checking) {	        cur_mark_pos = textsw_find_mark_internal(folio, mark);		     		exit_loop =  (direction == EV_FIND_DEFAULT) ?		    	(cur_mark_pos <= cur_pos) : (cur_mark_pos >= cur_pos);	    } else {	        /* Did we wrap around the file already */	        if (!first_time &&                     (prev_pos == cur_pos                      || ((strlen(str_buf) + prev_pos) > cur_pos)))	        /* Only one instance of the pattern in the file. */	            start_checking = TRUE;		 	        else	            start_checking = (direction == EV_FIND_DEFAULT) ? 	                 (prev_pos > cur_pos) : (cur_pos > prev_pos);		/*	         * This is a special case	         * Start search at the first instance of the pattern in the file.	         */	         if (start_checking) {		    cur_mark_pos = textsw_find_mark_internal(folio, mark);		    exit_loop =  (direction == EV_FIND_DEFAULT) ?		        (cur_mark_pos <= cur_pos) : (cur_mark_pos >= cur_pos);	         }     	     }	     	     if (!exit_loop) {		 (void) do_replace_proc(view);		 		 if (first_time) {		     mark = textsw_add_mark_internal(folio, cur_mark_pos, 		           TEXTSW_MARK_MOVE_AT_INSERT);		     first_time = FALSE;		 }		 	         prev_pos = cur_pos;    	         cur_pos = do_search_proc(view, direction, DONT_RING_BELL, wrapping_off);	         exit_loop = (cur_pos == ES_CANNOT_SET);	     }	}		if (process_aborted)	    window_bell(VIEW_REP_TO_ABS(view));}static voiddo_destroy_proc (frame)	Frame		frame;{	Textsw_view	view = (Textsw_view) window_get(frame, WIN_CLIENT_DATA, 0);	Textsw_folio	folio = FOLIO_FOR_VIEW(view);		window_set(frame, FRAME_NO_CONFIRM, TRUE, 0);	window_destroy(frame);		search_frame = folio->search_frame = NULL;}	static voidsearch_event_proc(item, event)    	Panel_item	item;    	Event		*event;{	Panel		panel = panel_get(item, PANEL_PARENT_PANEL, 0);	Textsw_view	view = view_from_panel_item(item);        int             wrapping_off = (int)panel_get(panel_items[(int)WRAP_ITEM], PANEL_VALUE);		if (event_action(event) == MS_RIGHT && event_is_down(event)) {	    int choice	= (int) menu_show(direction_menu, panel, event, 0);	    switch (choice) {	        case 1: 	            (void) do_search_proc(view, EV_FIND_DEFAULT, 	            	       (RING_IF_NOT_FOUND | RING_IF_ONLY_ONE), wrapping_off); 		    break;	        case 2:	            (void) do_search_proc(view, EV_FIND_BACKWARD, 	            	       (RING_IF_NOT_FOUND | RING_IF_ONLY_ONE), wrapping_off);	             break;	         default:	             break; 	    }	    	} else	    panel_default_handle_event(item, event);}static voidslp(x){	struct timeval tv;		tv.tv_sec = x / 64;	tv.tv_usec = (x % 64) * (1000000/64);	select(32, 0, 0, 0, &tv);}pkg_private voidblink_window (win, num_of_blink)	Window			win;{	register struct pixwin *pw;	int			i;	int			w, h;	Frame			base_frame;	Frame			frame;		if (win == NULL)	    return;	    	

⌨️ 快捷键说明

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