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

📄 movement.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
   show_search_message( SEARCHING );   if (fp->length == 1)      current = TRUE;   stop = browser_window->rline;   rc = ERROR;   while (rc == ERROR) {      if (current)         current = FALSE;      else {         /*          * update_line does not recognise hidden windows          */         if (!browser_window->visible)            g_status.screen_display = FALSE;         if (g_status.command == NextBrowse)            prepare_move_down( browser_window );         else            prepare_move_up( browser_window );         if (!browser_window->visible)            g_status.screen_display = TRUE;         if (browser_window->ll->len == EOF) {            fp->dirty = LOCAL;            if (g_status.command == NextBrowse) {               first_line( browser_window );               check_cline( browser_window, browser_window->top_line + 1 );            } else {               move_to_line( browser_window, fp->length, FALSE );               check_cline( browser_window, browser_window->bottom_line - 1 );            }         }         if (browser_window->rline == stop) {            rc = ERROR;            break;         }      }      rc = browser_parse( name, &rline, &rcol );   }   show_search_message( CLR_SEARCH );   if (fp->dirty) {      if (browser_window->visible)         display_current_window( browser_window );      fp->dirty = FALSE;   }   if (rc == OK  &&  *name == '\0') {      /* a results window was generated from a pipe or scratch window;       * if the window before the browser is non-file, assume that one,       * otherwise fail.       */      if (fp->prev == NULL || fp->prev->file_name[0] != '\0')         rc = ERROR;   }   if (rc == OK) {      if (*name == '\0')         win = find_file_window( fp->prev );      else {         get_full_path( name, name );         win = NULL;         for (fp = g_status.file_list; fp != NULL; fp = fp->next) {            if (strcmp( name, fp->file_name ) == 0) {               win = find_file_window( fp );               break;            }         }      }      if (win != NULL) {         change_window( window, win );         if (rline != 0) {            set_marker( win );            if (rline > win->file_info->length)               rline = win->file_info->length + 1;            if (win != window) {               g_status.wrapped = TRUE;               show_search_message( CHANGED );            } else if ((rline < win->rline && g_status.command == NextBrowse) ||                       (rline > win->rline && g_status.command == PrevBrowse)) {               g_status.wrapped = TRUE;               show_search_message( WRAPPED );            }            dup_window_info( &w, win );            move_to_line( &w, rline, TRUE );            if (rcol != -1)               w.rcol = rcol;            move_display( win, &w );            if (win->cline == w.cline  &&  win->file_info->dirty)               center_window( win );         }      } else {         g_status.jump_to = rline;         if (rcol != -1)            g_status.jump_col = rcol + 1;         rc = attempt_edit_display( name, LOCAL );         if (rc == OK) {            g_status.wrapped = TRUE;            show_search_message( CHANGED );         }      }   } else {      /*       * no browse lines found       */      error( INFO, g_display.end_line, utils18b );   }   if (!mode.track_path) {      /*       * Restore the original directory and update all window headers.       */      set_current_directory( cwd );      set_path( NULL );   }   return( rc );}/* * Name:    browser_parse * Purpose: parse the current browser line for filename and line number * Author:  Jason Hood * Date:    November 17, 2003 * Passed:  name:  buffer to store filename *          rline: pointer to store line number *          rcol:  pointer to store column * Returns: OK if found, ERROR if not * Notes:   Search the first four tokens for a filename; if found, test the *           two tokens before or after it for line number and column. *          A token is delimited by " \t:;,", which cannot be in the filename. *          If the line contains only the filename itself, set rline to zero *           (browse files from a list of names, but ignore compiler messages *           without line numbers). *          Set rcol to -1 if no column was found. * * jmh 040714: parse a results window separately (to recognise spaces in names *              and pipes [returns name = ""]). */static int  browser_parse( char *name, long *rline, int *rcol ){char *line;int  len;char *token[4];int  t_len[4];int  tokens;int  results;char num[8];long number;int  rc;int  j, k;   line = (char *)browser_window->ll->line;   len  = browser_window->ll->len;   if (is_line_blank( (text_ptr)line, len, TRUE ))      return( ERROR );   results = (browser_window->file_info->file_name[0] == '\0' &&              browser_window->file_info->file_name[1] == RESULTS);   tokens = 0;   j = 0;   while (tokens < 4) {      while (j < len && bj_isspace( line[j] ))         ++j;      if (j < len) {         token[tokens] = line + j;         t_len[tokens] = 0;         while (j < len  &&  line[j] != ':'  &&  (results  ||                            (line[j] != ' '                         &&  line[j] != '\t'                         &&  line[j] != ';'                         &&  line[j] != ','))) {            ++t_len[tokens];            ++j;         }         ++tokens;         ++j;      } else         break;   }   rc = ERROR;#if !defined( __UNIX__ )   /*    * A colon could be a drive specifier - if we have a one letter token,    * see if it can be combined with the next.  (This needs to be done first    * on the odd chance the same file is on two drives.)    */   for (j = 0; j < tokens - 1; ++j) {      if (t_len[j] == 1 && token[j][1] == ':') {         strncpy( name, token[j], 2 + t_len[j+1] );         name[2 + t_len[j+1]] = '\0';         rc = file_exists( name );         if (rc == OK || rc == READ_ONLY) {            t_len[j] = 2 + t_len[j+1];            --tokens;            for (k = j + 1; k < tokens; ++k) {               token[k] = token[k+1];               t_len[k] = t_len[k+1];            }            rc = OK;            break;         } else            rc = ERROR;      }   }   if (rc == ERROR) {#endif   if (results  &&  t_len[0] == 0) {      *name = '\0';      j = 0;      rc = OK;   } else for (j = 0; j < tokens; ++j) {      strncpy( name, token[j], t_len[j] );      name[t_len[j]] = '\0';      rc = file_exists( name );      if (rc == OK || rc == READ_ONLY) {         rc = OK;         break;      } else         rc = ERROR;   }#if !defined( __UNIX__ )   }#endif   if (rc == OK) {      /*       * If there's only the one token, which takes the whole line, use       * 0 as the line number; otherwise fail.       */      *rline = 0;      *rcol  = -1;      if (tokens == 1) {         if (t_len[0] != len)            rc = ERROR;      } else {         rc = ERROR;         for (k = 0; k < tokens; ++k) {            if (k != j && t_len[k] < 8) {               memcpy( num, token[k], t_len[k] );               num[t_len[k]] = '\0';               number = strtol( num, &line, 10 );               if ((int)(line - num) == t_len[k] && number != 0) {                  rc = OK;                  if (*rline == 0)                     *rline = number;                  else {                     *rcol = (int)number - 1;                     break;                  }               }            }         }      }   }   return( rc );}/* * Name:    center_window * Purpose: To place the current line or cursor in the center of a window. * Date:    June 5, 1991 * Passed:  window:  pointer to current window */int  center_window( TDE_WIN *window ){int  center;int  center_line;int  diff;file_infos *file;register TDE_WIN *win;           /* put window pointer in a register */   win = window;   file = win->file_info;   center = (win->bottom_line + 1 - win->top_line) / 2;   center_line = win->top_line + center;   diff = center_line - win->cline;   if (diff != 0) {      if (g_status.command == CenterWindow) {         if (diff < 0 || win->rline + diff <= file->length + 1) {            if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)               return( ERROR );            undo_move( win, 0 );            update_line( win );            win->cline += diff;            move_to_line( win, win->rline + diff, TRUE );            show_curl_line( win );         }      } else {         if (diff < 0 || center_line <= win->top_line + win->rline) {            win->cline  = center_line;            file->dirty = LOCAL;         }      }   }   if (g_status.command == CenterWindow  ||  g_status.command == CenterLine)      cursor_sync( win );   return( OK );}/* * Name:    topbot_line * Purpose: move the line to the top or bottom of the window * Author:  Jason Hood * Date:    October 25, 1999 * Passed:  window:  pointer to current window */int  topbot_line( TDE_WIN *window ){int  new_line;int  top = window->top_line;   if (g_status.command == TopLine)      new_line = top;   else {      new_line = window->bottom_line;      if (new_line > top + window->rline)         new_line = top + (int)window->rline;   }   if (window->cline != new_line) {      window->cline = new_line;      window->file_info->dirty = LOCAL;   }   cursor_sync( window );   return( OK );}/* * Name:    screen_right * Purpose: To move the cursor one (half) screen to the right * Date:    September 13, 1991 * Passed:  window:  pointer to current window * Notes:   Add 80 columns to the real cursor.  If the cursor is past the *          maximum line length then move it back. * jmh 980910: if not-eol display, add 79 columns. * jmh 991110: made more like _left. * jmh 991124: return ERROR if can't go any further. * jmh 020906: removed the "horizontal_" prefix; *             added the half-screen function. */int  screen_right( TDE_WIN *window ){int  screen_width;int  end;int  rc = OK;   screen_width = window->end_col - window->start_col + 1;   end = MAX_LINE_LENGTH - screen_width;   if (g_status.command == HalfScreenRight)      screen_width /= 2;   else if (mode.show_eol == 2)      --screen_width;   if (window->rcol + screen_width < MAX_LINE_LENGTH) {      undo_move( window, (g_status.command == ScreenRight) ? ScreenLeft                                                           : HalfScreenLeft );      window->rcol += screen_width;      window->bcol += screen_width;      if (window->bcol > end)         window->bcol = end;      window->file_info->dirty = LOCAL | RULER;   } else {      if (window->bcol != end) {         window->bcol = end;         window->file_info->dirty = LOCAL | RULER;      } else         rc = ERROR;   }   if (rc == OK)      check_virtual_col( window, window->rcol, window->ccol );   cursor_sync( window );   return( rc );}/* * Name:    screen_left * Purpose: To move the cursor one (half) screen to the left * Date:    September 13, 1991 * Passed:  window:  pointer to current window * Notes:   Subtract screen width from the real cursor.  If the cursor is less *           than zero then see if bcol is zero.  If bcol is not zero then make *           bcol zero. * jmh 980910: if not-eol display, include one-column "overlap". * jmh 991124: return ERROR if can't go any further. * jmh 020906: removed the "horizontal_" prefix; *             added half-screen function. */int  screen_left( TDE_WIN *window ){int  screen_width;int  rc = OK;   screen_width = window->end_col - window->start_col + 1;   if (g_status.command == HalfScreenLeft)      screen_width /= 2;   else if (mode.show_eol == 2)      --screen_width;   if (window->rcol - screen_width < 0) {      if (window->bcol != 0) {         window->bcol = 0;         window->file_info->dirty = LOCAL | RULER;      } else         rc = ERROR;   } else {      undo_move( window, (g_status.command == ScreenLeft) ? ScreenRight                                                          : HalfScreenRight );      window->rcol -= screen_width;      window->bcol -= screen_width;      if (window->bcol < 0)         window->bcol = 0;      window->file_info->dirty = LOCAL | RULER;   }   if (rc == OK)      check_virtual_col( window, window->rcol, window->ccol );   cursor_sync( window );   return( rc );}/* * Name:    goto_top_file * Purpose: To move the cursor to the top of the file. * Date:    June 5, 1991 * Passed:  window:  pointer to current window */int  goto_top_file( TDE_WIN *window ){register TDE_WIN *win;   /* put window pointer in a register */   win = window;   if (win->rline != win->cline - win->top_line) {      if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)         return( ERROR );      undo_move( win, 0 );      set_marker( win );                /* remember previous position */      move_to_line( win, win->cline - win->top_line, TRUE );      display_current_window( win );   }   cursor_sync( win );   return( OK );}/* * Name:    goto_end_file * Purpose: To move the cursor to the end of the file. * Date:    June 5, 1991 * Passed:  window:  pointer to current window */int  goto_end_file( TDE_WIN *window ){register TDE_WIN *win;  /* put window pointer in a register */long new_line;   win = window;   new_line = win->file_info->length + 1 - (win->bottom_line - win->cline);

⌨️ 快捷键说明

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