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

📄 findrep.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    */   assert( rcol >= 0 );   assert( rcol < MAX_LINE_LENGTH );   assert( g_status.line_buff_len >= 0 );   assert( g_status.line_buff_len >= rcol );   memcpy( g_status.line_buff + rcol,           (g_status.search & SEARCH_REGX) ? subst_text : g_status.subst,           new_len );   file->modified = TRUE;   un_copy_line( window->ll, window, FALSE, FALSE );   window->ll->type |= DIRTY;   if (direction == FORWARD) {      if (tabs)         window->rcol = detab_adjust_rcol( window->ll->line, rcol + new_len - 1,                                           file->ptab_size );      else         window->rcol += new_len - 1;      if ((g_status.search & SEARCH_REGX)  &&          (found_len == 0 || *regx.pattern == '$' || *regx.pattern == '>'))         ++window->rcol;   }   /*    * jmh (22/11/97) - rcol can become -1, which appears to be safe.    */   assert( window->rcol >= -1 );   show_avail_mem( );}/* * Name:    find_string * Purpose: To set up and perform a find operation. * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   Keep the search string and boyer-moore stuff until changed. */int  find_string( TDE_WIN *window ){int  direction;int  new_string;register TDE_WIN *win;  /* put window pointer in a register */int  rc;char answer[MAX_COLS+2];   switch (g_status.command) {      case FindForward :         direction  = FORWARD;         new_string = TRUE;         break;      case FindBackward :         direction  = BACKWARD;         new_string = TRUE;         break;      case RepeatFindForward :         direction  = FORWARD;         new_string =  bm.search_defined != OK ? TRUE : FALSE;         break;      case RepeatFindBackward :         direction  = BACKWARD;         new_string =  bm.search_defined != OK ? TRUE : FALSE;         break;      default :         direction  = 0;         new_string = 0;         assert( FALSE );         return( ERROR );   }   win = window;   if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)      return( ERROR );   /*    * get search text, using previous as default    */   if (new_string == TRUE) {      strcpy( answer, (char *)bm.pattern );      /*       * string to find:       */      if (get_name( find4, win->bottom_line, answer, &h_find ) <= 0)         return( ERROR );      bm.search_defined = OK;      strcpy( (char *)bm.pattern, answer );      build_boyer_array( );   }   g_status.search = (direction == BACKWARD) ? SEARCH_BACK : 0;   rc = perform_search( win );   return( rc );}/* * Name:    define_search * Purpose: to setup and perform a search * Author:  Jason Hood * Date:    September 23, 1999 * Passed:  window:  pointer to current window * Notes:   prompt for direction and start position.  If the string contains *           regx characters perform a regx search, otherwise a text search. *           Start the string with a quote (") to force text search. *          If searching block, make sure it's in the current file. */int  define_search( TDE_WIN *window ){int  type;register TDE_WIN *win;  /* put window pointer in a register */int  block;int  rc;char *answer;   win = window;   if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)      return( ERROR );   check_block( NULL );   if (g_status.marked && g_status.marked_file == win->file_info)      block = TRUE;   else      block = CB_S_Block = FALSE;   find_dialog[IDC_S_BLOCK].hist = (block) ? NULL : (HISTORY*)ERROR;   rc = do_dialog( find_dialog, find_proc );   if (rc == ERROR)      return( ERROR );   answer = get_dlg_text( EF_S_Pattern );   if (*answer == '\0')      return( ERROR );   if (CB_S_RegX) {      /* pattern is copied and successfully compiled in find_proc */      regx.search_defined = OK;      type = SEARCH_REGX;   } else {      bm.search_defined = OK;      strcpy( (char *)bm.pattern, answer );      build_boyer_array( );      type = 0;   }   if (CB_S_Backward) type |= SEARCH_BACK;   if (CB_S_Begin)    type |= SEARCH_BEGIN;   if (CB_S_Block)    type |= SEARCH_BLOCK;   if (CB_S_All)      type |= SEARCH_ALL;   if (CB_S_Results) {      type |= SEARCH_RESULTS;      results_window = NULL;   }   g_status.search = search_type = type;   rc = perform_search( window );   if (!(search_type & SEARCH_ALL) || !(search_type & SEARCH_RESULTS))      search_type &= ~SEARCH_BEGIN;   g_status.search = 0;   return( rc );}/* * Name:    find_proc * Purpose: dialog callback for DefineSearch * Author:  Jason Hood * Date:    November 30, 2003 * Notes:   if using RegX, check the pattern compiles successfully; *          since Block and All searches are complementary, turning on one *           will turn off the other; *          results for all files will always be from the beginning, so turn *           Beginning on and disable it. */int  find_proc( int id, char* text ){static int  begin = ERROR;      /* remember the old Beginning state */int  other;int  rc = OK;   if (id == IDE_S_PATTERN) {      if (CB_S_RegX && *text != '\0') {         strcpy( (char *)regx.pattern, text );         if (build_nfa( ) == ERROR) {            regx.search_defined = FALSE;            rc = ERROR;         }      }   } else {      if (id == IDC_S_BLOCK || id == IDC_S_ALL) {         other = IDC_S_BLOCK + IDC_S_ALL - id;         if (find_dialog[id].n && find_dialog[other].n)            check_box( other );      }      if (id == IDC_S_RESULTS || id == IDC_S_ALL) {         other = IDC_S_RESULTS + IDC_S_ALL - id;         if (find_dialog[id].n) {            if (find_dialog[other].n) {               begin = CB_S_Begin;               if (!begin)                  check_box( IDC_S_BEGIN );               check_box_enabled( IDC_S_BEGIN, FALSE );            }         } else if (find_dialog[other].n && begin != ERROR) {            check_box_enabled( IDC_S_BEGIN, TRUE );            if (!begin)               check_box( IDC_S_BEGIN );            begin = ERROR;         }      }   }   return( rc );}/* * Name:    repeat_search * Purpose: to repeat the search defined above * Author:  Jason Hood * Date:    September 23, 1999 * Passed:  window:  pointer to current window * Notes:   uses the other search functions to do all the work. *          if repeating results across all files use the dialog to verify. */int  repeat_search( TDE_WIN *window ){line_list_ptr temp;int  rc;   if (/*search_type == ERROR  ||*/ /* (ERROR is -1 so both bits are defined) */       ((search_type & SEARCH_ALL) && (search_type & SEARCH_RESULTS)))      return( define_search( window ) );   if (un_copy_line( window->ll, window, TRUE, TRUE ) == ERROR)      return( ERROR );   /*    * if repeating a search with a results window, add a blank    *  line before the new results and move the cursor there    */   if ((search_type & SEARCH_RESULTS) && results_window != NULL) {      if (results_window == window) {         /*          * results window cannot append to itself          */         error( WARNING, window->bottom_line, find17 );         return( ERROR );      }      rc = OK;      temp = new_line( 0, &rc );      if (rc == OK) {         insert_node( results_file, results_file->line_list_end, temp );         if (results_window->rline == results_file->length)            ++results_window->rline;         else            move_to_line( results_window, results_file->length + 1, TRUE );         check_cline( results_window, (results_window->bottom_line + 1                                       + results_window->top_line) / 2 );      }   }   g_status.search = search_type;   rc = perform_search( window );   g_status.search = 0;   return( rc );}/* * Name:    isearch * Purpose: perform an incremental/interactive search * Author:  Jason Hood * Date:    October 28, 2002 * Passed:  window:  pointer to current window * Notes:   search for text as characters are entered. */int  isearch( TDE_WIN *window ){register TDE_WIN *win;long key;int  func = 0;int  len = 0;MARKER *prev, temp, cur;MARKER pos[MAX_COLS];int  fcol[MAX_COLS];int  vlen[MAX_COLS];HISTORY *h;int  num = 0;int  search, new_string = FALSE, display;int  first = TRUE;int  stop = FALSE;int  rc = OK;DISPLAY_BUFF;int  scase = mode.search_case;int  max_len = 66 - ISEARCH;    /* the position of the "wrapped" message */unsigned char ch;   win = window;   if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)      return( ERROR );   prev = &win->file_info->marker[0];   temp = *prev;   set_marker( win );   cur = *prev;   *prev = temp;   SAVE_LINE( g_display.mode_line );   s_output( mode.search_case == IGNORE ? find18a : find18b,             g_display.mode_line, 0, Color( Help ) );   g_status.search = (g_status.command == ISearchBackward)                     ? (SEARCH_I | SEARCH_BACK) : SEARCH_I;   bm.search_defined = OK;   h = h_find.prev;   new_string = TRUE;   while (!stop) {      search = display = FALSE;      if (new_string) {         num = 0;         if (new_string == TRUE)            strcpy( (char *)bm.pattern, h->str );         build_boyer_array( );         len = bm.pattern_length;         eol_clear( ISEARCH, g_display.mode_line, Color( Help ) );         if (len > max_len) {            ch = bm.pattern[max_len];            bm.pattern[max_len] = '\0';            s_output( (char *)bm.pattern, g_display.mode_line, ISEARCH,                      Color( Help ) );            bm.pattern[max_len] = ch;         } else            s_output( (char *)bm.pattern, g_display.mode_line, ISEARCH,                      Color( Help ) );         refresh( );      }      key = getkey_macro( );      if (g_status.wrapped) {         g_status.wrapped = FALSE;         eol_clear( (len > max_len) ? 67 : ISEARCH + len,                    g_display.mode_line, Color( Help ) );      }      if (key < 256  &&  rc != ERROR) {         if (first) {            len = 0;            eol_clear( ISEARCH, g_display.mode_line, Color( Help ) );         }         if (len < MAX_COLS - 1) {            bm.pattern[len++] = (text_t)key;            bm.pattern[len]   = '\0';            build_boyer_array( );            if (len > max_len)               s_output( (char *)bm.pattern + len - max_len,                         g_display.mode_line, ISEARCH, Color( Help ) );            else               c_output( (int)key, ISEARCH + len - 1, g_display.mode_line,                         Color( Help ) );            refresh( );            search = TRUE + 1;            new_string = FALSE;            g_status.search |= SEARCH_BEGIN;         }      } else {         switch (key) {            case RTURN: case ESC: func = Rturn;           break;            case _CTRL+_G:        func = AbortCommand;    break;            case _CTRL+_S:        func = ISearchForward;  break;            case _CTRL+_R:        func = ISearchBackward; break;            case _CTRL+_W:        func = CopyWord;        break;            case _SHIFT+_CTRL+_W: func = CopyString;      break;            default:              func = getfunc( key );  break;         }         switch (func) {            case AbortCommand:               *prev = cur;               goto_marker( win );               rc = ERROR;               stop = TRUE;               break;            case Rturn:               if (key != ESC  &&  new_string  &&  len)                  search = TRUE;               else {                  *prev = cur;                  rc = OK;                  stop = TRUE;               }               break;            case ToggleSearchCase:               mode.search_case = (mode.search_case == IGNORE) ? MATCH : IGNORE;               build_boyer_array( );               s_output( mode.search_case == IGNORE ? find18a : find18b,                         g_display.mode_line, 0, Color( Help ) );               refresh( );               break;            case ISearchForward:               g_status.search = SEARCH_I;               goto history;            case ISearchBackward:               g_status.search = SEARCH_I | SEARCH_BACK;            history:               if (len) {                  search = TRUE;                  new_string = FALSE;               }               break;            case LineUp:            case LineDown:               h = (func == LineDown) ? h->next : h->prev;               new_string = TRUE;               break;            case WordRight:            case WordEndRight:

⌨️ 快捷键说明

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