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

📄 utils.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
      if (del_trailing  &&  mode.trailing  &&  file->crlf != BINARY) {         len = g_status.line_buff_len - 1;         for (c = g_status.line_buff + len; (int)len >= 0; len--, c--) {            if (*c != ' '  &&  (*c != '\t' || !file->inflate_tabs))               break;         }         g_status.line_buff_len = len + 1;         file->dirty = GLOBAL;         if (window->visible == TRUE)            show_changed_line( window );      }      len    = g_status.line_buff_len;      ll_len = ll->len;      assert( len    < MAX_LINE_LENGTH );      assert( ll_len < MAX_LINE_LENGTH );      net_change = len - ll_len;      if (net_change != 0) {         /*          * let's malloc space for the new line before we free the old line.          */         p = my_malloc( len, &rc );         if (rc == ERROR)            error( WARNING, window->bottom_line, main4 );         else {            /*             * free the space taken up by the old line.             */            my_free( ll->line );            ll->line = p;         }      }      if (rc != ERROR) {         my_memcpy( ll->line, g_status.line_buff, len );         ll->len = len;         if (net_change != 0) {            for (wp=g_status.window_list; wp != NULL; wp=wp->next) {               if (wp->file_info == file && wp != window)                  if (wp->rline > window->rline)                     wp->bin_offset += net_change;            }         }         file->modified = TRUE;         if (window->visible)            show_avail_mem( );      }   }   g_status.copied = FALSE;   g_status.buff_node = NULL;   return( rc );}/* * jmh 980729: This function is currently unused. */#if 0/* * Name:    un_copy_tab_buffer * Purpose: To copy the tab buffer line the main text buffer * Date:    October 31, 1992 * Passed:  line_number:  line number to copy line tab out buffer *          window:       pointer to current window */int  un_copy_tab_buffer( line_list_ptr ll, TDE_WIN *window ){text_ptr p;int  len;               /* length of current line buffer text */int  net_change;int  rc;file_infos *file;TDE_WIN *wp;   rc = OK;   file = window->file_info;   /*    * file has changed.  lets create the back_up if needed    */   if (mode.do_backups == TRUE) {      window->file_info->modified = TRUE;      rc = backup_file( window );   }   len = g_status.tabout_buff_len;   assert( len >= 0 );   assert( len < MAX_LINE_LENGTH );   assert( ll->len >= 0 );   assert( ll->len < MAX_LINE_LENGTH );   /*    * if the FAR heap has run out of space, then only part of the    *  current line can be moved back into the FAR heap. Warn the user    *  that some of the current line has been lost.    */   p = my_malloc( len, &rc );   if (rc == ERROR)      error( WARNING, window->bottom_line, main4 );   else {      net_change = len - ll->len;      my_free( ll->line );      my_memcpy( p, g_status.line_buff, len );      ll->line = p;      ll->len  = len;      if (net_change != 0) {         for (wp=g_status.window_list; wp != NULL; wp=wp->next) {            if (wp->file_info == file && wp != window)               if (wp->rline > window->rline)                  wp->bin_offset += net_change;         }      }      file->modified = TRUE;   }   return( rc );}#endif/* * Name:    set_prompt * Purpose: To display a prompt, highlighted, at the bottom of the screen. * Date:    October 1, 1989 * Passed:  prompt: prompt to be displayed *          line:   line to display prompt * jmh 980726: changed eol_clear to text color rather than message. */void set_prompt( const char *prompt, int line ){register int prompt_col;   /*    * work out where the answer should go    */   prompt_col = strlen( prompt );   /* jmh 981002: truncate the message if it's too long, instead of failing an    *             assertion.    * jmh 030325: since it's now constant, and s_output will truncate anyway,    *              simply change the col.    */   if (prompt_col > g_display.ncols - 1)      prompt_col = g_display.ncols - 1;   /*    * output the prompt    */   s_output( prompt, line, 0, Color( Message ) );   eol_clear( prompt_col, line, Color( Text ) );   /*    * put cursor at end of prompt    */   xygoto( prompt_col, line );   refresh( );}/* * Name:    show_eof * Purpose: display eof message * Date:    September 16, 1991 * Notes:   line:  ususally, line to display is "<=== eof ===>" * * jmh 980702: also display the top of file message * jmh 980703: cover the entire window */void show_eof( TDE_WIN *window ){register int col;text_t temp[MAX_COLS+2];unsigned char attr[MAX_COLS+2];const char *msg;int  wid, len;int  j;int  spaces;int  start_col;   start_col = window->left;   wid = window->end_col + 1 - start_col;   memset( temp, EOF_CHAR, wid );   memset( attr, Color( EOF ), wid );   spaces = (wid > 30) ? 3 : (wid > 20) ? 2 : 1;   msg = eof_text[(window->rline != 0)];   len = strlen( msg );   col = (wid - len) / 2;   memcpy( temp + col, msg, len );   for (j = 0; j < spaces; ++j)      temp[col-1-j] = temp[col+len+j] = ' ';   if (ruler_win.rline != -1) {      if (window->cline == ruler1 || window->cline == ruler2 ||          window->rline == ruler_win.rline)         make_popup_ruler( window, temp, attr, wid, ruler1, ruler2 );   }   display_line( temp, attr, wid, window->cline, start_col );}/* * Name:    show_line_numbers * Class:   helper function * Purpose: display just the line numbers for the popup ruler * Author:  Jason Hood * Date:    July 20, 2005 * Passed:  window:  window being displayed * Notes:   rline is assumed to be at the top line of the window. */static void show_line_numbers( TDE_WIN *window ){long n;int  line;char buf[16];   line = window->top_line;   n = window->rline;   if (n == 0) {      ++n;      ++line;   }   for (; line <= window->bottom_line; ++line) {      sprintf( buf, "%*ld", window->file_info->len_len - 1,                            labs( n - ruler_win.rline ) + 1 );      s_output( buf, line, window->left, Color( Ruler ) );      if (++n > window->file_info->length)         break;   }}/* * Name:    display_current_window * Purpose: display text in current window * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   use a temporary window structure, "w", to do the dirty work. * * jmh 991126: use normal syntax coloring to blank window, if appropriate. * jmh 050720: special processing for the popup ruler. */void display_current_window( TDE_WIN *window ){register int count;     /* number of lines in window */register int number;    /* number of text lines to display */TDE_WIN w;              /* scratch window structure */int  curl;              /* current line on screen, window->cline */int  col;               /* color of blank lines */int  below;             /* is the ruler below the line being measured? */int  hyt;   /*    * jmh 980801: reset the current line count, since it's not required.    */   window->cur_count = 0;   /*    * initialize the scratch variables    */   dup_window_info( &w, window );   count = w.cline - w.top_line;   if (count > 0) {      w.cline -= count;      w.rline -= count;      do         w.ll = w.ll->prev;      while (--count != 0);   }   /*    * start at the top of the window and display a window full of text    */   curl  = (swap_er == -1) ? window->cline : -1;   count = number = hyt = w.bottom_line - w.top_line;   if (w.rline + number > w.file_info->length) {      number = (int)(w.file_info->length - w.rline);      hyt = number + 1;   }   count -= number;   /*    * determine what the popup ruler wants displayed    */   if (ruler_win.rline != -1) {      ruler1 = ruler2 = curl = -1;      if (ruler_win.rline >= w.rline && ruler_win.rline <= w.rline + hyt) {         ruler1 = w.top_line + (int)(ruler_win.rline - w.rline);         if (ruler1 == w.top_line || (ruler1 == w.top_line+1 && hyt != 1)) {            below = TRUE;            ++ruler1;            ruler2 = ruler1 + (ruler1 < w.top_line + hyt);         } else {            below = FALSE;            --ruler1;            ruler2 = ruler1 - (ruler1 > w.top_line);         }         if (w.file_info->dirty & RULER) {            if ((w.file_info->dirty & GLOBAL)  &&  mode.line_numbers)               show_line_numbers( &w );            while ((!below && w.cline != ruler2)  ||                    (below && w.rline != ruler_win.rline)) {               ++w.cline;               ++w.rline;               w.ll = w.ll->next;            }            if (w.file_info->dirty & GLOBAL) {               if (w.file_info->dirty & LOCAL) {                  if (below  &&  (ruler1 == w.top_line + 2  ||                      (ruler_win.rline == 2 && ruler1 == w.top_line + 3))  &&                      w.rline > 0) {                     --w.cline;                     --w.rline;                     w.ll = w.ll->prev;                  }               } else /* (w.file_info->dirty & NOT_LOCAL) */ {                  if (w.cline != w.top_line  &&  w.rline > 0) {                     --w.cline;                     --w.rline;                     w.ll = w.ll->prev;                  }               }               number = 3;            } else               number = 2;            if (number > w.bottom_line - w.cline)               number = w.bottom_line - w.cline;            count = 0;            if (w.rline + number > w.file_info->length) {               number = (int)(w.file_info->length - w.rline);               count = 1;            }         }      }   }   if (w.rline == 0) {      show_eof( &w );      ++w.cline;      ++w.rline;      w.ll = w.ll->next;      --number;   }   for (; number >= 0; number--) {      if (w.cline == curl)         show_curl_line( window );      else         update_line( &w );      ++w.cline;      ++w.rline;      w.ll = w.ll->next;   }   if (count > 0) {      show_eof( &w );      col = (window->syntax) ? syntax_color[0] : Color( Text );      while (--count != 0) {         ++w.cline;         window_eol_clear( &w, col );      }   }   show_asterisk( window );}/* * Name:    redraw_screen * Purpose: display all visible windows, modes, and headers * Date:    June 5, 1991 * Passed:  window:  pointer to current window * * jmh 991126: redraw all windows in one loop. */int  redraw_screen( TDE_WIN *window ){register TDE_WIN *wp;           /* window to redraw */#if defined( __UNIX__ )   cls( );#endif   for (wp = g_status.window_list; wp; wp = wp->next)      redraw_current_window( wp );   window->file_info->dirty = FALSE;   show_modes( );   refresh( );#if defined( __WIN32__ )   show_window_fname( window );         /* console title */#endif   return( OK );}/* * Name:    redraw_current_window * Purpose: redraw all info in window * Date:    July 13, 1991 * Passed:  window:  pointer to current window */void redraw_current_window( TDE_WIN *window ){   if (window->visible) {      show_window_header( window );      show_ruler( window );      show_ruler_pointer( window );      display_current_window( window );      if (window->vertical)         show_vertical_separator( window );      if (g_status.command != SizeWindow)         show_tab_modes( );   }}/* * Name:    show_changed_line * Purpose: Only one line was changed in file, just show it * Date:    June 5, 1991 * Passed:  window:  pointer to current window * * jmh 980728: Even though only one line has been changed, that change may *              affect other lines' colors in the syntax highlighting. * jmh 981125: Corrected bugs with the above. */void show_changed_line( TDE_WIN *window ){TDE_WIN *above;                 /* window above current */TDE_WIN *below;                 /* window below current */TDE_WIN w;                      /* scratch window structure */long changed_line;              /* line number in file that was changed */long top_line, bottom_line;     /* top and bottom line in file on screen */int  line_on_screen;            /* is changed line on screen? */file_infos *file;               /* file pointer */long count;                     /* number of additional lines to display */long rline;                     /* original rline in other window */int  i;   file  = window->file_info;   count = syntax_check_lines( window->ll, file->syntax );   if (window->visible) {      window->cur_count = window->bottom_line - window->cline;      if (window->cur_count > count)

⌨️ 快捷键说明

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