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

📄 perform.c

📁 功能强大的文本编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
/*      perform.c                                  07.09.98       */
/*
/  --------------------------------------------------------------
/  Copyright (C) 1993: Michael Braun
/                      Kaetinger Muehlenweg 103 A
/                      D-28816 Stuhr
/  --------------------------------------------------------------
/
/    ausgelagerte functionen von mbedit.c
/
*/


/************************/
/*  include files       */
/************************/

#include "config.h"
#include "global.h"
#include "standard.h"
#include "mbedit.h"
#include "history.h"
#include "perform.h"
#include "mbed_sub.h"
#include "commands.h"
#include "blocks.h"
#include "memo_hnd.h"
#include "disp_hnd.h"
#include "mon_outp.h"
#include "err_mess.h"
#include "window.h"
#include "mb_ctype.h"


/************************/
/* some defines         */
/************************/



/************************/
/* local structures     */
/************************/



/************************/
/*  module definitions  */
/************************/

/* -FF-  */

long perform_find (int direction, char *string,
                   int show_remark, size_t *len1)
{
long new_index;

/* anzeige, dass 'aktiv' */
   if (show_remark)
      show_status_line_2 ("searching ...", 0, -2, 0);

/* string suchen */
   new_index = comm_find (fc->buff_0, fc->byte_index,
                          fc->byte_anz, string, direction,
                          set.c_case, set.k_token, set.wildcards, len1);

   return new_index;
}  /* perform_find */

/* -FF-  */

#if (WITH_HEX_FIND)

long perform_find_byte (char byte_1, char byte_2)
{
long new_index;

/* anzeige, dass 'aktiv' */
   show_status_line_2 ("searching ...", 0, -2, 0);

/* string suchen */
   new_index = comm_find_byte (fc->buff_0, fc->byte_index,
                               fc->byte_anz, byte_1, byte_2);

   return new_index;
}  /* perform_find_byte */

#endif

/* -FF-  */

void save_find_indizes (int direction, long new_index, size_t len1)
{

/* save 1st and last char of search string (for invers display) */
   if ((new_index >= 0) && (set.wildcards))
   {
      if (direction)
      {                                      /* forward */
         fc->find[0] = new_index - len1;
         fc->find[1] = new_index;
      }
      else
      {                                      /* backward */
         fc->find[0] = new_index;
         fc->find[1] = new_index + len1;
      }
   }
   else
   {
      fc->find[0] = -1;
      fc->find[1] = -1;
   }

   return;
}  /* save_find_indizes */

/* -FF-  */

long perform_lower_upper (int up_flag)
{
long new_index;

/* string suchen */
   new_index = comm_lower_upper (fc->buff_0, fc->byte_index,
                                 fc->byte_anz, up_flag);

/* gueltiger index ? */
   if (new_index < 0L)
   {
      line_2_flag = 2;
      show_status_line_2 ("*** <F5>,<F6> at end of file ***", 0, -2, 1);
   }

   return new_index;
}  /* perform_lower_upper */

/* -FF-  */

void perform_file_reset (void)
{
   init_file_control (fc, 0);

#if (WITH_HEX_VIEW)
   if (mode_flag <= 2)       /* not in hex editor ? */
#endif
      refresh_1_window ();

   return;
}  /* perform_file_reset */

/* -FF-  */

void perform_move (long new_index)
{
long ii, new_line, delta, abs_delta;
int direction, byte_num;

#define HIGH_SPEED_MOVE  1   /* 0 = short code, 1 = fast execution */

#if (HIGH_SPEED_MOVE)
long index_0;
char FA_HU *buff_1;
int  count;
#endif

#define DELTA_LIMIT 200       /* ca. doppelte zeilenlaenge plus reserve */
#define UPDATE_CURSOR 0


/* special case: begin of file */
   if (new_index == 0L)
   {
      perform_file_reset ();
      return;
   }

/* gueltiger index ? sonst begrenzen (frueher: FATAL_ERROR) */
   new_index = min (max (new_index, 0L), fc->byte_anz);

/* is the difference old/new pointer small ? */
   delta = new_index - fc->byte_index;
   abs_delta = labs (delta);

   if (abs_delta < DELTA_LIMIT)
   {                                 /* diff is small */
      if (UPDATE_CURSOR)
         set_cursor_to (fc->lrow, REL_COLUMN);

   /* richtung */
      if (delta >= 0)
         direction = 1;
      else
         direction = -1;

   /* schleife */
      for (ii = 0 ; ii < abs_delta ; ii++)
      {
         if (direction == -1)
            byte_num = perform_key_left  (UPDATE_CURSOR,
                                          ((abs_delta-ii) > 1));
         else
            byte_num = perform_key_right (UPDATE_CURSOR,
                                          ((abs_delta-ii) > 1));

         if (byte_num == 2) ii++;     /* skip 1 byte */
      }
   }                                 /* diff is small */
   else
   {                                 /* diff is large */      
   /* cursor an zeilen anfang */
      perform_begin_of_line (UPDATE_CURSOR);

   /* n-mal rauf / runter */
#if 0
      new_line  = get_total_lines (fc->buff_0, 0L, new_index);
      delta     = new_line - fc->line_index;
#else
      if (delta > 0)
         delta =   get_total_lines (fc->buff_0, fc->byte_index, new_index);
      else
         delta = - get_total_lines (fc->buff_0, new_index, fc->byte_index);
      new_line  = fc->line_index + delta;
#endif
      abs_delta = labs (delta);

   /* richtung */
      if (delta >= 0)
         direction = 1;
      else
         direction = -1;

#if (HIGH_SPEED_MOVE)
   /* fallunterscheidung */
      if (abs_delta <= ROWS)
      {
#endif
      /* schleife */
         for (ii = 0 ; ii < abs_delta ; ii++)
         {
            if (direction == -1)
               perform_key_up (UPDATE_CURSOR);
            else
               perform_key_down (UPDATE_CURSOR);
         }
#if (HIGH_SPEED_MOVE)
      }
      else
      {
      /* NEW ! set direct ! */
         fc->byte_index = new_index;
         fc->buffer     = &fc->buff_0 [new_index];
         fc->line_index = new_line;

      /* calc: lin_left */
      /* search backward for EOL */
         buff_1 = &fc->buff_0 [new_index - 1];
         for (index_0 = (new_index - 1) ; index_0 >= 0 ; index_0--)
         {
            if (perform_test_eol1 (buff_1, -1))
               break;
            buff_1--;
         }
         fc->lin_left = index_0 + 1;


      /* calc. top_left */
         if (direction == -1)
         {
            fc->arow = 0;
            fc->top_left = fc->lin_left;
         }
         else
         {
            fc->arow = MAX_ROW - MIN_ROW;

         /* search backward for n EOLs */
            buff_1 = &fc->buff_0 [fc->lin_left - 1];
            count = MAX_ROW - MIN_ROW + 1;
            for (index_0 = (fc->lin_left - 1) ; index_0 >= 0 ; index_0--)
            {
               if (perform_test_eol1 (buff_1, -1))
               {
                  count--;
                  if (count == 0)
                     break;
               }
               buff_1--;
            }
            fc->top_left = index_0 + 1;
         }
         update_entire_window (fc->top_left);
      }
#endif


   /* zeiger setzen */
      ii = new_index - fc->byte_index;
      fc->byte_index += ii;
      fc->buffer     += ii;

   /* cursor setzen */
      fc->column = act_column (fc->buff_0, new_index);
      if (UPDATE_CURSOR)
         set_cursor_to (fc->lrow, REL_COLUMN);
   }                                 /* diff is large */      

   return;
}  /* perform_move */

/* -FF-  */

void check_dirty_cursor (void)
{
int old_column;

   old_column = fc->column;
   fc->column = act_column (fc->buff_0, fc->byte_index);

   if (EOLN_LEN_2)
   {
      if (perform_test_eol (fc->buffer, -1))
      {
         fc->byte_index--;
         fc->buffer--;
         fc->column--;
      }
   }

   if ((fc->column != old_column) && (get_video_active (0)))
   {                            /* cursor outside line */
      set_cursor_to (fc->lrow, REL_COLUMN);
   }

   return;
}  /* check_dirty_cursor */

/* -FF-  */

void check_tag_index (long old_index, long delta)
{
/* bei verschiebungen des speicherinhalts, tags mit verschieben */
/* (aber nur, wenn sie hinter der akt. position liegen,         */
/*  und nicht vor old_index !)                                  */

int ii;
#if WINDOW_COMMAND
int other_window;
#endif

   for (ii = 0 ; ii < 4 ; ii++)
   {
      if (fc->tag_index [ii] >= old_index)
      {
         fc->tag_index [ii] += delta;
         fc->tag_index [ii] = max (fc->tag_index [ii], old_index);
      }
   }

#if WINDOW_COMMAND
   if (same_buffer)
   {
      other_window = act_window + 1;
      if (other_window > 2)
         other_window = 1;

      if (fc->wind_index[other_window] >= old_index)
      {
         fc->wind_index[other_window] += delta;
         fc->wind_index[other_window] = max (fc->wind_index[other_window],
                                             old_index);
      }
   }
#endif

   return;
}  /* check_tag_index */

/* -FF-  */

int perform_insert_eol (void)
{

   return perform_key_insert (EOLN, 0);

}  /* perform_insert_eol */


#if (!TEST_EOL_MACRO)

int perform_test_eol (char *buffer, int offset)
{

   if (EOLN_LEN_1)
   {
      return (*buffer == (char)EOLN);
   }
   else
   {
      return ((buffer [  offset] == (EOLN_HIGH)) &&
              (buffer [1+offset] == (EOLN_LOW)));
   }


}  /* perform_test_eol */

#endif

/* -FF-  */

int  perform_key_left (byte update_cursor, int skip_flag)
{
char old_char;
int llen, byte_num;

   byte_num = 1;

   if (fc->byte_index > 0)
   {
      old_char = *fc->buffer;

      fc->byte_index--;
      fc->buffer--;

      if (fc->column <= 0)
      {                     /* line up */
         fc->line_index--;

         if (EOLN_LEN_2)
         {
            if ((skip_flag) && (fc->buffer[-1] == EOLN_HIGH))
            {
               fc->byte_index--;
               fc->buffer--;
               byte_num = 2;
            }
         }

         llen = act_column (fc->buff_0, fc->byte_index);
         fc->column = llen;

         llen = line_length  (fc->buff_0, fc->byte_index, fc->byte_anz, 1);
         fc->lin_left -= llen;
 
         if (fc->lrow > MIN_ROW)
         {
            fc->arow--;
            if ((update_cursor) && (get_video_active (0)))
               set_cursor_to (fc->lrow, REL_COLUMN);
         }
         else  /* scroll down */
         {
            fc->top_left -= llen;
            update_entire_window (fc->top_left);
         }
      }
      else
      {
         if ((*fc->buffer == 0x09) || (old_char == 0x09))   /* <tab> ? */
         {
            fc->column = act_column (fc->buff_0, fc->byte_index);
            if ((update_cursor) && (get_video_active (0)))
               set_cursor_to (fc->lrow, REL_COLUMN);
         }
         else
         {
            fc->column--;
            if ((REL_COLUMN > 0) && (REL_COLUMN < (COLUMNS-1)))
            {
               if ((update_cursor) && (get_video_active (0)))
                  cursor_left();
            }
         }
      }
      return byte_num;
   }
   else
   {
      return 0;
   }
}  /* perform_key_left */

/* -FF-  */

int  perform_key_right (byte update_cursor, int skip_flag)
{
char *old_char;
int  llen, byte_num, ii;

   byte_num = 1;

   for (ii = 0 ; ii < byte_num ; ii++)
   {
      if (fc->byte_index < fc->byte_anz)
      {
         old_char = fc->buffer;
   
         fc->byte_index++;
         fc->buffer++;
   
         if (*old_char == (EOLN_LOW))      /* end of line ? @@ */
         {                     /* line down */
            fc->line_index++;
   
            llen = line_length (fc->buff_0, (fc->byte_index - 1 /* - (EOLN_LEN_2) */),
                                fc->byte_anz, 1);
            fc->lin_left += llen; 
   
            fc->column = 0;
            if (fc->lrow < MAX_ROW)
            {
               fc->arow++;
               if ((update_cursor) && (get_video_active (0)))
                  set_cursor_to (fc->lrow, REL_COLUMN);
            }
            else  /* scroll up */
            {
               llen = line_length (fc->buff_0, fc->top_left, fc->byte_anz, 1);
               fc->top_left += llen; 
               update_entire_window (fc->top_left);
            }
         }
         else
         {
            if (EOLN_LEN_2)
            {
               if ((skip_flag) &&
                   (perform_test_eol (fc->buffer, -1)))
               {
                  byte_num = 2;
                  continue;
               }
               else
               {
                  if (ii > 0)
                  {
                     fc->byte_index--;
                     fc->buffer--;
                  }
               }
            }
   
            if (*old_char == 0x09)   /* <tab> ? */
            {
               fc->column = act_column (fc->buff_0, fc->byte_index);
               if ((update_cursor) && (get_video_active (0)))
                  set_cursor_to (fc->lrow, REL_COLUMN);
            }
            else
            {
               fc->column++;
               if ((REL_COLUMN >= 0) && (REL_COLUMN < (COLUMNS-1)))
               {
                  if ((update_cursor) && (get_video_active (0)))
                     cursor_right();
               }
            }
         }
      }
      else
      {
         return ii;
      }
   }  /* for ii */

⌨️ 快捷键说明

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