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

📄 block.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
      same = TRUE;      if (block_type == BOX) {         if (action == MOVE) {            if (rline == br  &&  (rcol >= bc && rcol <= ec+1))               return( ERROR );         } else if (action == SWAP) {            /*             * jmh 980811: can't swap a block within itself             */            if (rline >= br && rline <= er &&                rcol  >= bc && rcol  <= ec)               return( ERROR );         }      } else if (block_type == LINE) {         if (rline >= br && rline <= er) {             /*              * if COPYing or KOPYing within the block itself, reposition the              * destination to the next line after the block (if it exists)              */            if (action == COPY || action == KOPY)               dest = block_end;             /*              * a block moved to within the block itself has no effect              * jmh 980810: a block can't swap with itself, either              */            else if (action == MOVE || action == SWAP)               return( ERROR );         }      } else if (rline >= br && rline <= er) {         /*          * to find out if cursor is in a STREAM block we have to do          * a few more tests.  if cursor is on the beginning row or          * ending row, then check the beginning and ending column.          */         if ((rline > br && rline < er) ||             (br == er && rcol >= bc && (rcol <= ec || ec == -1)) ||             (br != er && ((rline == br && rcol >= bc) ||                           (rline == er && (rcol <= ec || ec == -1))))) {            /*             * if the cursor is in middle of STREAM, make destination             * the last character following the STREAM block.             */            if (action == COPY || action == KOPY) {               if (ec == -1) {                  dest = block_end->next;                  rcol = 0;                  rline = er + 1;               } else {                  dest = block_end;                  rcol = ec + 1;                  rline = er;               }            } else if (action == MOVE)               return( ERROR );         }      }   }   /*    * 1. can't create lines greater than MAX_LINE_LENGTH    * 2. if we are FILLing a BOX - fill block buff once right here    */   block_len = (ec+1) - bc;   if (block_type == BOX) {      if (!source_only) {         if (rcol + block_len > MAX_LINE_LENGTH) {            /*             * Error: line too long             */            error( INFO, prompt_line, ltol );            return( ERROR );         }      }      if (action == BORDER) {         /*          * The box must be at least big enough for the corners          */         if (g_status.command == BorderBlock) {            if (block_len < 2 || br == er)               rc = ERROR;         } else {            if (style_len[0] + style_len[2] > block_len  ||                style_len[5] + style_len[7] > block_len  ||                (((style_len[0] || style_len[2]) &&                  (style_len[5] || style_len[7])) && br == er))               rc = ERROR;         }         if (rc == ERROR) {            /*             * box not big enough for border             */            error( WARNING, prompt_line, block28a );            return( ERROR );         }      }   } else if (block_type == LINE) {      block_len = 0;   } else if (block_type == STREAM) {      lend = block_end->len;      if ((action == DELETE || action == MOVE) && ec != -1) {         /*          * Is what's left on start of STREAM block line plus what's left at          * end of STREAM block line too long?          */         if (lend > ec)            lend -= ec;         else            lend = 0;         if (bc + lend > MAX_LINE_LENGTH) {            error( INFO, prompt_line, ltol );            return( ERROR );         }      }      if (action != DELETE) {         /*          * We are doing a MOVE, COPY, or KOPY.  Find out if what's on the          * current line plus the start of the STREAM line are too long.          * Then find out if end of the STREAM line plus what's left of          * the current line are too long.          */         lens = block_start->len;         /*          * if we had to move the destination of the STREAM COPY or KOPY          * to the end of the STREAM block, then dest and window->ll->line          * will not be the same.  In this case, set length to length of          * first line in STREAM block.  Then we can add the residue of          * the first line in block plus residue of the last line of block.          */         if (dest->line == window->ll->line)            add = dest->len;         else            add = lens;         /*          * Is current line plus start of STREAM block line too long?          */         if (lens > bc)            lens -= bc;         else            lens = 0;         if (rcol + lens > MAX_LINE_LENGTH) {            error( INFO, prompt_line, ltol );            return( ERROR );         }         /*          * Is residue of current line plus residue of STREAM block line          * too long?          */         if (add > bc)            add -= bc;         else            add = 0;         if (lend > ec  &&  ec != -1)            lend -= ec;         else            lend = 0;         if (add + lend > MAX_LINE_LENGTH) {            error( INFO, prompt_line, ltol );            return( ERROR );         }      }      if (block_start == block_end && ec != -1) {         block_type = BOX;         block_len = (ec+1) - bc;      }   }   if (mode.do_backups == TRUE) {      if (!source_only) {         window->file_info->modified = TRUE;         rc = backup_file( window );      }      if (source_changed) {         source_window->file_info->modified = TRUE;         if (rc != ERROR)            rc = backup_file( source_window );      }      if (rc == ERROR)         return( ERROR );   }   source = block_start;   assert( block_start != NULL );   assert( block_start->len != EOF );   assert( block_end != NULL );   assert( block_end->len != EOF );   if (block_type == BOX)      do_box_block( window, source_window, action,                    source_file, dest_file, source, dest, br, er, rline,                    block_num, block_inc, block_base, fill_char, style,                    style_len, same, block_len, bc, ec, rcol, &rc );   else if (block_type == LINE) {      if (action != JUSTIFY)         do_line_block( window, source_window, action,                        source_file, dest_file, same, block_start, block_end,                        source, dest, br, er, rline, &rc );      else         justify_line_block( source_window, block_start, br, er, &rc );   } else      do_stream_block( window, source_window, action,                       source_file, dest_file, block_start, block_end,                       source, dest, rline, br, er, bc, ec, rcol, &rc );   if (!((action == SWAP && rc == ERROR) || action == SUM)) {      if (!source_only) {         dest_file->modified = TRUE;         dest_file->dirty = GLOBAL;      }      if (source_only || source_changed) {         source_file->modified = TRUE;         source_file->dirty = GLOBAL;      }   }   /*    * Update the syntax highlight flags of affected lines.    * Start with the source lines.    */   syntax = source_file->syntax;   if (source_changed) {      if (block_type == BOX)         syntax_check_block( br, er, block_start, syntax );      else if (block_type == STREAM)         syntax_check_lines( block_start, syntax );      /*       * else block_type == LINE which is done in do_line_block       */   }   /*    * Now check the destination lines.    */   if (!source_only && block_type != LINE)      syntax_check_block( br, er, dest, dest_file->syntax );   /*    * unless we are doing a KOPY, FILL, NUMBER, or OVERLAY we need to unmark    * the block.  if we just did a KOPY, the beginning and ending may have    * changed.  so, we must readjust beginning and ending rows.    * jmh - don't unmark SWAP, as well.    * jmh 980801: turned the unmark conditional around.    * jmh 980814: move the mark along with the block.    *             Go back to unmarking SWAP.    */   number = (er+1) - br;   if ((action == KOPY || action == COPY) && block_type != BOX &&       same && br >= rline  &&  rc != ERROR) {      source_file->block_br += number - (block_type == STREAM);      source_file->block_er += number - (block_type == STREAM && ec != -1);   }   if (action == SWAP) {      swap_er = -1;      if (rc != ERROR)         unmark_block( window );   } else if (action == COPY || action == MOVE || action == DELETE) {      unmark_block( window );      if (action == MOVE) {         dest_file->block_type = -block_type;         if (same && block_type == BOX && rline == br && rcol > bc) {            dest_file->block_bc = rcol - block_len;            dest_file->block_ec = rcol - 1;         } else {            dest_file->block_bc = rcol;            if (block_type != STREAM)               dest_file->block_ec = rcol + ec - bc;         }         --number;         if (same && rline > br && block_type != BOX) {            dest_file->block_br = rline - number;            dest_file->block_er = rline;         } else {            dest_file->block_br = rline;            dest_file->block_er = rline + number;            if (block_type == LINE) {               ++dest_file->block_br;               ++dest_file->block_er;            }         }      }   }   show_avail_mem( );   return( rc );}/* * Name:    do_line_block * Purpose: delete, move, copy, or kopy a LINE block * Date:    April 1, 1993 * 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 *          same:           are source and destination files same? T or F *          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 *          br:             beginning line number in marked block *          er:             ending line number in marked block *          rline:          current line number in destination file *          rc:             return code * * jmh:     September 11, 1997 - added SWAP * jmh 980817: if a break point is defined, SWAP will swap the block with the *              block delineated by the cursor and break point. If there is no *              break point, it swaps the same number of lines, or till eof. * jmh 981125: corrected a MOVE syntax check (set dest_end). * jmh 991026: added OVERLAY operation. * jmh 991027: SWAP asks for the region to be swapped. * jmh 991029: shift the mark to follow the SWAP. * jmh 991108: reduce the mark in an overlapped OVERLAY. */void do_line_block( TDE_WIN *window,  TDE_WIN *source_window,  int action,                    file_infos *source_file,  file_infos *dest_file,  int same,                    line_list_ptr block_start,  line_list_ptr block_end,                    line_list_ptr source,  line_list_ptr dest,                    long br,  long er,  long rline,  int *rc ){line_list_ptr temp_ll;          /* temporary list pointer */line_list_ptr temp2;            /* temporary list pointer */line_list_ptr dest_end;int  lens;                      /* length of source line */long li;                        /* temporary line variables */long diff;long diff_dest = 1;TDE_WIN d_w;                    /* a couple of temporary TDE_WINs */   dest_end = dest;   if (action == COPY || action == KOPY) {      assert( br >= 1 );      assert( br <= source_file->length );      assert( er >= br );      assert( er <= source_file->length );      for (li=br; li <= er  &&  *rc == OK; li++) {         lens = source->len;         assert( lens * sizeof(char) < MAX_LINE_LENGTH );         temp_ll = new_line_text( source->line, lens, source->type|DIRTY, rc );         if (*rc == OK) {            insert_node( dest_file, dest_end, temp_ll );            dest_end = temp_ll;            source = source->next;         } else {            /*             * file too big             */            error( WARNING, window->bottom_line, main4 );            er = li - 1;         }      }   } else if (action == MOVE) {      temp_ll = block_start;      for (li=br; li <= er; li++) {         temp_ll->type |= DIRTY;         temp_ll = temp_ll->next;      }      block_start->prev->next = block_end->next;      block_end->next->prev   = block_start->prev;      /*       * jmh 980806: The block has effectively been deleted; syntax check       *             the lines after it while the block line pointers       *             are still valid.       */      syntax_check_lines( block_end->next, source_file->syntax );      dest->next->prev  = block_end;      block_start->prev = dest;      block_end->next   = dest->next;      dest->next        = block_start;

⌨️ 快捷键说明

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