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

📄 block.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
      dest_end          = block_end;   } else if (action == DELETE) {      block_end->next->prev   = block_start->prev;      block_start->prev->next = block_end->next;      /*       * jmh 980806: as with MOVE       */      syntax_check_lines( block_end->next, source_file->syntax );      block_end->next = NULL;      my_free_group( TRUE );      while (block_start != NULL) {         temp_ll = block_start;         block_start = block_start->next;         my_free( temp_ll->line );         my_free( temp_ll );      }      my_free_group( FALSE );   } else if (action == SWAP) {      *rc = find_swap_lines( window, &dest, &dest_end, br, er, same );      if (*rc == ERROR)         return;      temp_ll = dest;      for (li = swap_br; li <= swap_er; ++li) {         temp_ll->type |= DIRTY;         temp_ll = temp_ll->next;      }      temp_ll = block_start;      for (li = br; li <= er; ++li) {         temp_ll->type |= DIRTY;         temp_ll = temp_ll->next;      }      temp_ll           = block_start->prev;      temp2             = dest->prev;      temp_ll->next     = dest;      temp2->next       = block_start;      block_start->prev = temp2;      dest->prev        = temp_ll;      temp_ll           = block_end->next;      temp2             = dest_end->next;      temp_ll->prev     = dest_end;      temp2->prev       = block_end;      block_end->next   = temp2;      dest_end->next    = temp_ll;   } else if (action == OVERLAY) {      if (same && rline == br)         return;      li = rline + er - br - dest_file->length;      if (li > 0) {         temp_ll = dest_file->line_list_end->prev;         for (; li > 0  &&  *rc == OK; li--)            *rc = pad_dest_line( window, dest_file, temp_ll );         if (*rc == ERROR)            return;      }      dup_window_info( &d_w, window );      d_w.rline   = rline;      d_w.ll      = dest;      d_w.visible = FALSE;      if (!same || rline < br || rline > er) {         for (li = br; li <= er; ++li) {            copy_line( source, source_window, TRUE );            un_copy_line( d_w.ll, &d_w, TRUE, TRUE );            d_w.ll->type |= DIRTY;            source = source->next;            d_w.ll = d_w.ll->next;            ++d_w.rline;         }         --d_w.rline;         if (same && d_w.rline >= br && d_w.rline < er)            source_file->block_br = d_w.rline + 1;      } else {         for (li = er - br; li > 0; li--) {            source = source->next;            d_w.ll = d_w.ll->next;            ++d_w.rline;         }         for (li = er; li >= br; --li) {            copy_line( source, source_window, TRUE );            un_copy_line( d_w.ll, &d_w, TRUE, TRUE );            d_w.ll->type |= DIRTY;            source = source->prev;            d_w.ll = d_w.ll->prev;            --d_w.rline;         }         source_file->block_er = rline - 1;      }      syntax_check_block( br, er, dest, dest_file->syntax );   }   diff =  er + 1L - br;   if (action == COPY || action == KOPY || action == MOVE) {      if (action == MOVE)         dest_file->length += diff;      adjust_windows_cursor( window, diff );   }   if (action == DELETE || action == MOVE) {      source_file->length -= diff;      adjust_windows_cursor( source_window, -diff );   }   if (action == SWAP) {      diff_dest = swap_er + 1L - swap_br;      source_file->length += diff_dest - diff;      dest_file->length   += diff - diff_dest;      adjust_windows_cursor( source_window, diff_dest - diff );      adjust_windows_cursor( window,        diff - diff_dest );      if (!same) {         source_file->block_er = br + diff_dest - 1;         dest_file->block_type = -LINE;         if (source_window->rline > er)            source_window->rline += diff_dest - diff;         else if (source_window->rline > br + diff_dest - 1)            source_window->rline = br + diff_dest - 1;      } else if (swap_br > er)         swap_br += diff_dest - diff;      dest_file->block_br = swap_br;      dest_file->block_er = swap_br + diff - 1;   }   /*    * do the syntax highlighting check    */   if (action == DELETE && source_window->rline >= br) {      source_window->rline -= diff;      if (source_window->rline < br)         source_window->rline = br;   }   if (action != DELETE && action != OVERLAY) {      syntax_check_lines( (action == SWAP) ? dest : dest->next,                          dest_file->syntax );      syntax_check_lines( dest_end->next, dest_file->syntax );      if (action == SWAP) {         syntax_check_lines( block_start, source_file->syntax );         syntax_check_lines( block_end->next, source_file->syntax );      }   }   /*    * restore all cursors in all windows    */   restore_cursors( dest_file );   if (dest_file != source_file)      restore_cursors( source_file );   show_avail_mem( );}/* * Name:    do_stream_block * Purpose: delete, move, copy, or kopy a STREAM block * Date:    June 5, 1991 * Passed:  window:         pointer to destination window (current window) *          source_window:  pointer to source window *          action:         block action  --  KOPY, MOVE, etc... *          source_file:    pointer to source file structure *          dest_file:      pointer to destination file *          block_start:    pointer to first node in block *          block_end:      pointer to last node in block *          source:         pointer to source node *          dest:           pointer to destination node *          rline:          current line number in destination file *          br:             beginning line number in marked block *          er:             ending line number in marked block *          bc:             beginning column of block *          ec:             ending column of block *          rcol:           current column of cursor *          rc:             return code * * jmh 020815: David Hughes pointed out a bug with the first and last lines *              of a COPY/KOPY possibly being modified. Use load_box_buff() *              instead of prepare_block() to overcome it; *             made appropriate lines dirty; *             fixed a bug padding the destination line beyond eol. * jmh 050714: if ec == -1 the last line itself is marked. */void do_stream_block( TDE_WIN *window,  TDE_WIN *source_window,  int action,                      file_infos *source_file,  file_infos *dest_file,                      line_list_ptr block_start,  line_list_ptr block_end,                      line_list_ptr source,  line_list_ptr dest, long rline,                      long br, long er, int bc, int ec, int rcol, int *rc ){line_list_ptr temp_ll;          /* temporary list pointer */int  lens;                      /* length of source line */int  lend;                      /* length of destination line */long li;                        /* temporary line variables */long diff;TDE_WIN s_w, d_w;               /* a couple of temporary TDE_WINs */   dup_window_info( &s_w, source_window );   dup_window_info( &d_w, window );   s_w.rline   = br;   s_w.ll      = block_start;   s_w.visible = FALSE;   d_w.rline   = rline;   d_w.ll      = dest;   d_w.visible = FALSE;   if (!(action==COPY || action==KOPY)) {      /*       * pad the start of the STREAM block if needed.       */      lens = block_start->len;      if (lens < bc || source_file->inflate_tabs)         *rc = prepare_block( &s_w, block_start, bc );      /*       * pad the end of the STREAM block if needed.       */      if (ec != -1) {         lens = block_end->len;         if (*rc == OK  &&  (lens < ec+1  ||  source_file->inflate_tabs))            *rc = prepare_block( &s_w, block_end, ec+1 );      }   }   /*    * pad the destination line if necessary    */   copy_line( dest, &d_w, TRUE );   *rc = un_copy_line( dest, &d_w, FALSE, FALSE );   lend = dest->len;   if (*rc == OK && (action==MOVE || action==COPY || action==KOPY)) {      if (lend < rcol+1 || dest_file->inflate_tabs)         *rc = prepare_block( &d_w, dest, rcol+1 );   }   if ((action == COPY || action == KOPY) && *rc == OK) {      /*       * concatenate the end of the STREAM block with the end of the       *   destination line.       */      lens = dest->len - rcol;      assert( lens >= 0 );      assert( lens <= MAX_LINE_LENGTH );      assert( ec + 1 >= 0 );      assert( ec + 1 <= MAX_LINE_LENGTH );      assert( rcol >= 0 );      if (ec != -1)         load_box_buff( g_status.line_buff, block_end, 0, ec, ' ',                        source_file->inflate_tabs, source_file->ptab_size );      my_memcpy( g_status.line_buff+ec+1, dest->line+rcol, lens );      lens += ec + 1;      g_status.line_buff_len = lens;      temp_ll = new_line( DIRTY, rc );      if (*rc == OK) {         g_status.copied = TRUE;         *rc = un_copy_line( temp_ll, &d_w, TRUE, FALSE );         if (*rc == OK) {            dest->next->prev = temp_ll;            temp_ll->next = dest->next;            dest->next = temp_ll;            temp_ll->prev = dest;         } else            my_free( temp_ll );      }      /*       * file too big       */      if (*rc != OK)         error( WARNING, window->bottom_line, main4 );      if (*rc == OK) {         g_status.copied = FALSE;         copy_line( dest, &d_w, FALSE );         lens = find_end( block_start->line, block_start->len,                          source_file->inflate_tabs, source_file->ptab_size );         assert( lens >= 0 );         assert( lens <= MAX_LINE_LENGTH );         assert( bc >= 0 );         assert( bc <= MAX_LINE_LENGTH );         assert( rcol >= 0 );         load_box_buff( g_status.line_buff+rcol, block_start, bc, lens-1, ' ',                        source_file->inflate_tabs, source_file->ptab_size );         g_status.line_buff_len = rcol + lens - bc;         *rc = un_copy_line( dest, &d_w, TRUE, FALSE );         dest->type |= DIRTY;      }      source = block_start->next;      if (dest == block_start)         source = source->next;      for (li = br + (ec != -1); li < er  &&  *rc == OK; li++) {         lens = source->len;         assert( lens >= 0 );         assert( lens <= MAX_LINE_LENGTH );         temp_ll = new_line_text( source->line, lens, DIRTY, rc );         if (*rc == OK) {            insert_node( window->file_info, dest, temp_ll );            dest   = temp_ll;            source = source->next;         } else {            /*             * file too big             */            error( WARNING, window->bottom_line, main4 );            *rc = WARNING;         }      }   } else if (action == MOVE) {      /*       * is the dest on the same line as the block_start?       */      if (dest == block_start) {         /*          * move the text between rcol and bc in block_start->line          *   to block_end->line + ec.          */         lens = bc - rcol;         if (ec == -1) {            temp_ll = new_line_text( block_start->line+rcol, lens, DIRTY, rc );            if (*rc == OK)               insert_node( window->file_info, block_end, temp_ll );            else {               /*                * file too big                */               error( WARNING, window->bottom_line, main4 );               *rc = WARNING;            }         } else {            lend = block_end->len - (ec + 1);            g_status.copied = FALSE;            copy_line( block_end, &s_w, FALSE );            assert( lens >= 0 );            assert( lens <= MAX_LINE_LENGTH );            assert( lend >= 0 );            assert( lend <= MAX_LINE_LENGTH );            assert( ec + lens + 1 <= MAX_LINE_LENGTH );            assert( rcol >= 0 );            my_memmove( g_status.line_buff + ec + lens + 1,                        g_status.line_buff + ec + 1,  lend );            my_memcpy( g_status.line_buff+ec+1, block_start->line+rcol, lens );            g_status.line_buff_len = block_end->len + lens;            *rc = un_copy_line( block_end, &d_w, TRUE, FALSE );         }         /*          * now, remove the text between rcol and bc on block_start->line          */         if (*rc == OK) {            lend = block_start->len - bc;            copy_line( block_start, &s_w, FALSE );            assert( lend >= 0 );            assert( lend < MAX_LINE_LENGTH );            my_memmove( g_status.line_buff + rcol,                        g_status.line_buff + bc, lend );            assert( block_start->len - (bc - rcol) >= 0 );            assert( block_start->len - (bc - rcol) <= MAX_LINE_LENGTH );            g_status.line_buff_len = block_start->len - (bc - rcol);            *rc = un_copy_line( block_start, &d_w, TRUE, FALSE );            block_start->type |= DIRTY;            block_end->type   |= DIRTY;         }      /*       * is the dest on the same line as the block_end?       */      } else if (dest == block_end) {         /*          * move the text between rcol and ec on block_end->line to          *   block_start->line + bc.   

⌨️ 快捷键说明

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