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

📄 ed.c

📁 包括文件操作、图形系统、并口串口编程、鼠标编程、小型cad系统、编译器、病毒防火墙、海底大战等多个实例。
💻 C
📖 第 1 页 / 共 4 页
字号:
int  undo( WINDOW *window )
{
register WINDOW *win;   
line_list_ptr node;

   win = window;
   if (win->file_info->undo_count > 0) {
      entab_linebuff( );
      if (un_copy_line( win->ll, win, TRUE ) == ERROR)
         return( ERROR );

      node = win->file_info->undo_top;
      win->file_info->undo_top = node->next;
      win->file_info->undo_top->prev = NULL;
      --win->file_info->undo_count;

      node->next = node->prev = NULL;

      ++win->file_info->length;

      if (win->ll->prev != NULL)
         win->ll->prev->next = node;
      node->prev = win->ll->prev;

      win->ll->prev = node;
      node->next = win->ll;
      win->ll = node;
      win->ll->dirty = TRUE;

      if (win->ll->prev == NULL)
         win->file_info->line_list = win->ll;

      adjust_windows_cursor( win, 1 );

     
      win->file_info->dirty = GLOBAL;
      show_size( win );
      show_avail_mem( );
   }
   return( OK );
}



int  beg_next_line( WINDOW *window )
{
int  rc;

   window->rcol = 0;
   rc = prepare_move_down( window );
   check_virtual_col( window, window->rcol, window->ccol );
   sync( window );
   make_ruler( window );
   show_ruler( window );
   return( rc );
}



int  next_line( WINDOW *window )
{
register int rcol;
register WINDOW *win;   
int  rc;

   win = window;
   rc = prepare_move_down( win );
   rcol = first_non_blank( win->ll->line, win->ll->len );
   check_virtual_col( win, rcol, win->ccol );
   sync( win );
   make_ruler( win );
   show_ruler( win );
   return( rc );
}



int  home( WINDOW *window )
{
register int rcol;
register WINDOW *win;   
text_ptr p;

   win = window;
   if (g_status.copied && win->file_info == g_status.current_window->file_info){
      rcol = first_non_blank( (text_ptr)g_status.line_buff,
                                        g_status.line_buff_len );
      if (is_line_blank( (text_ptr)g_status.line_buff, g_status.line_buff_len))
         rcol = 0;
   } else {
      p = win->ll->line;
      if (p == NULL)
         rcol = 0;
      else {
         rcol = first_non_blank( p, win->ll->len );
         if (is_line_blank( p, win->ll->len ))
            rcol = 0;
      }
   }
   if (win->rcol == rcol)
      rcol = 0;
   check_virtual_col( win, rcol, win->ccol );
   sync( win );
   make_ruler( win );
   show_ruler( win );
   return( OK );
}



int  goto_eol( WINDOW *window )
{
register int rcol;
register WINDOW *win;   

   win = window;
   rcol = find_end( win->ll->line, win->ll->len );
   if (g_status.copied) {
      if (win->file_info == g_status.current_window->file_info)
         rcol = find_end( (text_ptr)g_status.line_buff, g_status.line_buff_len);
   }
   win->ccol = win->start_col + rcol - win->bcol;
   check_virtual_col( win, rcol, win->ccol );
   sync( win );
   make_ruler( win );
   show_ruler( win );
   return( OK );
}



int  goto_top( WINDOW *window )
{
register WINDOW *win;   

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   update_line( win );
   for (; win->cline > win->top_line+win->ruler; win->cline--,win->rline--) {
      if (win->rline <= 1L)
         break;
      else {
         win->ll = win->ll->prev;
         win->bin_offset -= win->ll->len;
      }
   }
   show_curl_line( win );
   sync( win );
   return( OK );
}



int  goto_bottom( WINDOW *window )
{
register WINDOW *win;   
int  at_top;

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   if (win->ll->len == EOF) {
      if (win->rline > 1) {
         at_top = FALSE;
         if (win->cline == win->top_line + win->ruler) {
            win->file_info->dirty = LOCAL;
            at_top = TRUE;
         }
         if (!at_top)
            update_line( win );
         --win->rline;             
         win->ll = win->ll->prev;
         win->bin_offset -= win->ll->len;
         if (!at_top) {
            --win->cline;          
            show_curl_line( win );
         }
      }
   } else {
      update_line( win );
      for (; win->cline < win->bottom_line; win->cline++,win->rline++) {
         if (win->ll == NULL || win->ll->next == NULL || win->ll->next->len == EOF)
            break;
         else {
            win->bin_offset += win->ll->len;
            win->ll = win->ll->next;
         }
      }
      show_curl_line( win );
   }
   sync( win );
   return( OK );
}



int  set_tabstop( WINDOW *window )
{
char num_str[MAX_COLS]; 
int  tab;               
register int rc;
register file_infos *file;

   itoa( mode.ltab_size, num_str, 10 );
   
   rc = get_name( ed7a, window->bottom_line, num_str, g_display.message_color );
   if (rc == OK   &&  *num_str != '\0') {
      tab = atoi( num_str );
      if (tab < MAX_COLS/2) {
         mode.ltab_size = tab;
         if (mode.inflate_tabs) {
            for (file=g_status.file_list; file != NULL; file=file->next)
               file->dirty = GLOBAL;
         }
      } else {
       
         error( WARNING, window->bottom_line, ed8 );
         rc = ERROR;
      }
   }

   itoa( mode.ptab_size, num_str, 10 );
  
   rc = get_name( ed7b, window->bottom_line, num_str, g_display.message_color );
   if (rc == OK  &&  *num_str != '\0') {
      tab = atoi( num_str );
      if (tab < MAX_COLS/2) {
         mode.ptab_size = tab;
         show_tab_modes( );
         if (mode.inflate_tabs) {
            for (file=g_status.file_list; file != NULL; file=file->next)
               file->dirty = GLOBAL;
         }
      } else {
       
         error( WARNING, window->bottom_line, ed8 );
         rc = ERROR;
      }
   }
   return( rc );
}


void show_line_col( WINDOW *window )
{
int  i;
register int k;
char line_col[20], num[10];
char *hex_digit = "0123456789abcdef";

  
   memset( line_col, ' ', 13 );
   line_col[13] = '\0';

  
   itoa( window->rcol+1, num, 10 );
   i = strlen( num ) - 1;
   for (k=12; i>=0; i--, k--)
      line_col[k] = num[i];

  
   line_col[k--] = ':';

   ltoa( window->rline, num, 10 );
   i = strlen( num ) - 1;
   for (; i>=0; i--, k--)
      line_col[k] = num[i];

  
   s_output( line_col, window->top_line-1, window->end_col-12,
             g_display.head_color );

   strcpy( line_col, " =   " );
   i = window->rcol;
   if (g_status.copied) {
      if (mode.inflate_tabs)
         i = entab_adjust_rcol( (text_ptr)g_status.line_buff,
                                 g_status.line_buff_len, i );
      if (i < g_status.line_buff_len) {
         k = (int)g_status.line_buff[i];
         line_col[2] = *(hex_digit + (k >> 4));
         line_col[3] = *(hex_digit + (k & 0x000f));
         line_col[4] = 'x';
         i = TRUE;
      } else
         i = FALSE;
   } else {
      if (mode.inflate_tabs  &&  window->ll->len != EOF)
         i = entab_adjust_rcol( window->ll->line, window->ll->len, i );
      if (i < window->ll->len) {
         k = (int)window->ll->line[i];
         line_col[2] = *(hex_digit + (k >> 4));
         line_col[3] = *(hex_digit + (k & 0x000f));
         line_col[4] = 'x';
         i = TRUE;
      } else
         i = FALSE;
   }
   s_output( line_col, g_display.mode_line, 58, g_display.mode_color );
   if (i == TRUE)
      c_output( k, 58, g_display.mode_line, g_display.mode_color );


   
   if (window->file_info->crlf == BINARY && !window->vertical) {
      k =  window->ll->line == NULL  ?  0  :  window->rcol;
      memset( line_col, ' ', 7 );
      line_col[7] = '\0';
      s_output( line_col, window->top_line-1, 61, g_display.head_color );
      ltoa( window->bin_offset + k, line_col, 10 );
      s_output( line_col, window->top_line-1, 61, g_display.head_color );
   }
   show_asterisk( window );
}



void show_asterisk( WINDOW *window )
{
   c_output( window->file_info->modified ? '*' : ' ', window->start_col+4,
             window->top_line-1, g_display.head_color );
}



int  toggle_overwrite( WINDOW *arg_filler )
{
   mode.insert = !mode.insert;
   show_insert_mode( );
   set_cursor_size( mode.insert ? g_display.insert_cursor :
                    g_display.overw_cursor );
   return( OK );
}



int  toggle_smart_tabs( WINDOW *arg_filler )
{
   mode.smart_tab = !mode.smart_tab;
   show_tab_modes( );
   return( OK );
}



int  toggle_indent( WINDOW *arg_filler )
{
   mode.indent = !mode.indent;
   show_indent_mode( );
   return( OK );
}



int  set_left_margin( WINDOW *window )
{
register int rc;
char temp[MAX_COLS];

   itoa( mode.left_margin + 1, temp, 10 );
   
   rc = get_name( ed9, window->bottom_line, temp, g_display.message_color );
   if (rc == OK  &&  *temp != '\0') {
      rc = atoi( temp ) - 1;
      if (rc < 0 || rc >= mode.right_margin) {
        
         error( WARNING, window->bottom_line, ed10 );
         rc = ERROR;
      } else {
         mode.left_margin = rc;
         show_all_rulers( );
      }
   }
   return( rc );
}



int  set_right_margin( WINDOW *window )
{
char line_buff[(MAX_COLS+1)*2]; 
register int rc;
int  prompt_line;
char temp[MAX_COLS];

   prompt_line = window->bottom_line;
   save_screen_line( 0, prompt_line, line_buff );
   set_prompt( ed11a, prompt_line );
   rc = get_yn( );
   restore_screen_line( 0, prompt_line, line_buff );
   if (rc != ERROR) {
      mode.right_justify =  rc == A_YES ? TRUE : FALSE;

      itoa( mode.right_margin + 1, temp, 10 );
      
      rc = get_name( ed11, prompt_line, temp, g_display.message_color );
      if (rc == OK  &&  *temp != '\0') {
         rc = atoi( temp ) - 1;
         if (rc <= mode.left_margin || rc > MAX_LINE_LENGTH) {
           
            error( WARNING, prompt_line, ed12 );
            rc = ERROR;
         } else {
            mode.right_margin = rc;
            show_all_rulers( );
         }
      }
   }
   return( rc );
}



int  set_paragraph_margin( WINDOW *window )
{
register int rc;
char temp[80];

   itoa( mode.parg_margin + 1, temp, 10 );
   
   rc = get_name( ed13, window->bottom_line, temp, g_display.message_color );
   if (rc == OK  &&  *temp != '\0') {
      rc = atoi( temp ) - 1;
      if (rc < 0 || rc >= mode.right_margin) {
         /*
          * paragraph margin out of range
          */
         error( WARNING, window->bottom_line, ed14 );
         rc = ERROR;
      } else {
         mode.parg_margin = rc;
         show_all_rulers( );
      }
   }
   return( rc );
}



⌨️ 快捷键说明

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