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

📄 perform.c

📁 功能强大的文本编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
   if (perform_test_eol1 (&save_u.buffer [save_u.anz-1], -1))
      fc->line_anz--;  /* anzahl lines runterzaehlen */

/* delete n bytes (shift to left the rest of the memory) */
   memcpy_rev (fc->buffer, (fc->buffer + delta), 
              (fc->byte_anz - fc->byte_index + 1 - delta));
   fc->byte_anz -= delta;
   check_tag_index (fc->byte_index, (long) -delta);

/* old line below is now under cursor */
   new_index = act_index (fc->buff_0, fc->lin_left, fc->byte_anz, fc->column);
   delta = (int)(new_index - fc->byte_index);

   fc->byte_index += delta;
   fc->buffer     += delta;

/* display new memory content */
   update_rest_of_window (fc->lin_left, fc->lrow);

   return;
}  /* perform_delete_whole_line */


int perform_undo (void)
{
int  delta;

/* ist ueberhaupt was im buffer ? */
   if (save_u.anz == 0)        
   {                      /* nein ! */
      return 1;
   }

/* passt save_u.buffer noch mit rein ? */
   if (check_and_increase_buffer (fc, (fc->byte_anz + save_u.anz),
                                  FILE_RESERVE, 0) < 0)
   {                      /* nein ! */
      err_message (BUFFER_OVERFLOW);
      return 0;
   }

/* sonst ... */
/* war voriges kommando ^Z ? */
   if (save_u.command == 'Z')
   {
      if (perform_test_eol1 (&save_u.buffer [save_u.anz-1], -1))
         fc->line_anz++;  /* anzahl lines hochzaehlen */

      delta = (int) (fc->byte_index - fc->lin_left);
   
      fc->byte_index -= delta;
      fc->buffer     -= delta;
   
   /* cursor to begin of line */
      fc->column = 0;
   }

/* erstmal platz machen */
   memcpy_rev ((fc->buffer + save_u.anz), fc->buffer,
               (fc->byte_anz - fc->byte_index + 1));
   fc->byte_anz += save_u.anz;
   check_tag_index (fc->byte_index, (long) save_u.anz);

/* jetzt buffer holen */
   memcpy (fc->buffer, save_u.buffer, save_u.anz);

/* cursor auf alte position setzen */
   fc->byte_index += save_u.index;
   fc->buffer     += save_u.index;
   fc->column = act_column (fc->buff_0, fc->byte_index);

/* display new memory content */
   if (save_u.command == 'Z')
      update_rest_of_window (fc->lin_left, fc->lrow);
   else
      update_this_line (fc->lin_left, fc->lrow);

   return 1;
}  /* perform_undo */

/* -FF-  */

int valid_char (int key)
{
   if (((key >= 0x20) && ( key <= 0x7e)) ||    /* normal printable */
        (key == 0x09) ||                       /* <tab>     */
        (key == 0x0d) ||                       /* <cr>      */
        (key == 0x0a) ||                       /* <lf>      */
        (key == 0x0d0a) ||                     /* <cr><lf>  */
        (key >= 0x80))                         /* deutsches sonderzeichen */
      return 1;
   else
      return 0;
}  /* valid_char */


int perform_string_insert (char *string)
{
int flag, count;

   count = 0;
   while (*string)
   {
      flag = perform_key_insert (*string, 1);

      if (flag == 1)
      {
         string++;                     /* char was inserted */
         count++;
      }
      else
      {
         break;                        /* abort while loop */
      }
   }

   return count;
}  /* perform_string_insert */


void check_for_autonl (void)
{
long index_0, first_ind, last_ind, save_tag_a;
char FA_HU *buff_1;
int delta;

/* automatic insertion of <nl> ? */
   if ((mode_flag == 1) &&                  /* insert mode    ? */
       (set.autonl)     &&                  /* 'S'et 'A'utonl ? */
       (fc->column > (set.margin[2]) + 1))  /* line limit exceeded ? */
   {
   /* save last position */
      save_tag_a       = fc->tag_index[0];
      fc->tag_index[0] = fc->byte_index;

   /* this part of the screen must be refreshed */
      update_rest_of_window (fc->lin_left, fc->lrow);

   /* search backward for first + last white spaces (in one sequence) */
      first_ind = fc->lin_left;
      last_ind  = -1;

      for (index_0 = fc->byte_index-1 , buff_1 = fc->buffer-1 ;
           index_0 >= fc->lin_left ; 
           index_0--                  , buff_1--)
      {
         if (isspace(*buff_1) && (last_ind == -1))
         {
            last_ind = index_0 + 1;
         }

         if ((!isspace(*buff_1)) && (last_ind != -1))
         {
            first_ind = index_0 + 1;
            break;
         }
      }

   /* delete all white spaces, if found any */
      if (last_ind != -1)
      {
         delta = (int) (last_ind - first_ind);
         perform_move (last_ind);
      
      /* delete n bytes (shift to left the rest of the memory) */
         memcpy_rev ((fc->buffer - delta), fc->buffer,
                     (fc->byte_anz - fc->byte_index + 1));
         fc->byte_anz   -= delta;
         fc->buffer     -= delta;
         fc->byte_index -= delta;
         check_tag_index (fc->byte_index, (long) -delta);
      }

   /* insert <nl> */
      perform_key_insert (EOLN, 0);

   /* restore last position */
      perform_move (fc->tag_index[0]);
      fc->tag_index[0] = save_tag_a;
   }

   return;
}  /* check_for_autonl */


int perform_key_insert (int key, int check)
{
int new_bytes;

/* 1 or 2 bytes ? */
   new_bytes = 1;

   if (EOLN_LEN_2)
   {
      if (key == EOLN)
         new_bytes = 2;
   }

   if ((check) && (!valid_char (key)))
   {
      err_message (INVALID_CHARACTER);
      return 0;
   }

   if (check_and_increase_buffer (fc, (fc->byte_anz + new_bytes),
                                  FILE_RESERVE, 0) < 0)
   {
      err_message (BUFFER_OVERFLOW);
      return 0;
   }
   
/* buffer um 1/2 bytes nach hinten schieben */
   memcpy_rev ((fc->buffer + new_bytes), fc->buffer,
               (fc->byte_anz - fc->byte_index + 1));
   fc->byte_anz += new_bytes;
   check_tag_index (fc->byte_index, (long) new_bytes);


/* aktuelles zeichen loeschen,                    */
/* damit in ..._exchange die zeilen_bilanz stimmt */
   memset (fc->buffer, 0, new_bytes);

/* aktuelles zeichen ueberschreiben */
   return perform_key_exchange (key, check);
}  /* perform_key_insert */


int perform_key_exchange (int key, int check)
{
long last_la, last_left, new_index;
int  last_row, len;
int  new_bytes, old_bytes, shift, end_flag;

/* valid char ? */
   if ((check) && (!valid_char (key)))
   {
      err_message (INVALID_CHARACTER);
      return 0;
   }

/* save last values */
   last_la   = fc->line_anz;
   last_left = fc->lin_left;
   last_row  = fc->lrow;

/* 1 or 2 bytes ? */
   new_bytes = 1;
   old_bytes = 1;

   if (EOLN_LEN_2)
   {
      if (key == EOLN)
         new_bytes = 2;
   
      if (perform_test_eol (fc->buffer, 0))
         old_bytes = 2;
   }

/* at end of line / end of file ? */
   if ((perform_test_eol  (fc->buffer, 0)) ||
       (perform_test_eol1 (fc->buffer, 0)) ||
       (fc->byte_index == fc->byte_anz))
   {
      end_flag = 1;
      shift = new_bytes;
   }
   else
   {
      end_flag = 0;
      if (mode_flag == 2)     /* exchange mode */
         shift = new_bytes - old_bytes;     /* = 1, if <cr><lf> inside line */
      else
         shift = 0;
   }

   if (shift)
   {
      if (check_and_increase_buffer (fc, (fc->byte_anz + shift),
                                     FILE_RESERVE, 0) < 0)
      {
         err_message (BUFFER_OVERFLOW);
         return 0;
      }
      
   /* buffer um 1/2 byte nach hinten schieben */
      memcpy_rev ((fc->buffer + shift), fc->buffer,
                  (fc->byte_anz - fc->byte_index + 1));
      fc->byte_anz += shift;
      check_tag_index (fc->byte_index, (long) shift);
   }

/* aktuelles zeichen loeschen, */
/* als merker in save_x.buffer */
   if (end_flag)
      *fc->buffer = '\0';

/* save old data */
   if (save_x.index < sizeof(save_x.buffer))
   {
      save_x.buffer [save_x.index] = *fc->buffer;
      save_x.index++;
   }

/* overwrite char */
   if (new_bytes == 2)
   {
      *fc->buffer    = EOLN_HIGH;
      fc->buffer [1] = EOLN_LOW;
      fc->line_anz++;                          /* new <cr><lf> */
   }
   else
   {
      *fc->buffer = (char) key;                /* store new char */

      if (key == EOLN_LOW)
         fc->line_anz++;
   }

   perform_key_right (1, 1);
   
   /* indent during insertion ? */
   if ((key == EOLN) && (set.indent))
   {
      len = first_nonblank (fc->buff_0, last_left, fc->byte_anz);
      if (check_and_increase_buffer (fc, (fc->byte_anz + len),
                                     FILE_RESERVE, 0) < 0)
      {
         err_message (BUFFER_OVERFLOW);
         len = (int) (fc->buffer_size - fc->byte_anz) - 1;
      }
      block_insert (fc->buff_0, fc->byte_index,
                    fc->byte_anz, fc->buffer_size,
                    &fc->buff_0 [last_left], (long) len);

      fc->byte_anz += len;
      check_tag_index (fc->byte_index, (long) len);
      new_index = fc->byte_index + len;
      perform_move (new_index);

   /* was old line completely blank ? */
      if (len == line_length (fc->buff_0, last_left, fc->byte_anz, 0))
      {
         new_index = fc->byte_index - len;
         perform_key_up (0);
         perform_delete_start_of_line (0);
         perform_move (new_index);
      }
   }

/* display new memory content */
   if (fc->line_anz != last_la)
      update_rest_of_window (last_left, last_row);
   else
      update_this_line (fc->lin_left, fc->lrow);

   return 1;
}  /* perform_key_exchange */

/* -FF-  */

int perform_file_compare (void)
{
/* compare 2 files from actual cursor position, stop at 1st difference */

/* 1st case: screen with one single window: compare this  / other file */
/* 2nd case: split screen with two windows: compare upper / lower file */


char FA_HU *buffer_a, FA_HU *buffer_b;
long byte_anz_a, byte_index_a;
long byte_anz_b, byte_index_b;

struct RESULT {
                 int flag;
                 char *message;
              };

static struct RESULT result [] = {0, "file compare: running ...",
                                  0, "file compare: difference found",
                                 -1, "file compare: no difference",
                                 -1, "file compare: end of file"};
                     
enum COMP_STATUS
       {
          STAT_RUNNING,
          STAT_DIFF_FOUND,
          STAT_NO_DIFF,
          STAT_EOF
       } comp_status;


/* display activity */
   line_2_flag = 2;
   comp_status = STAT_RUNNING;
   show_status_line_2 (result[comp_status].message, 0, -2, 0);


/* prepare loop */

#if WINDOW_COMMAND
   if (act_window)
   {
   /* file a */
      buffer_a     = fc->buffer     + 1;
      byte_index_a = fc->byte_index + 1;
      byte_anz_a   = fc->byte_anz;
      window_change ();

   /* file b */
      buffer_b     = fc->buffer     + 1;
      byte_index_b = fc->byte_index + 1;
      byte_anz_b   = fc->byte_anz;
      window_change ();
   }
   else
#endif
   {
   /* file a */
      buffer_a     = fc->buffer     + 1;
      byte_index_a = fc->byte_index + 1;
      byte_anz_a   = fc->byte_anz;
      get_next_file_buffer (1);

   /* file b */
      buffer_b     = fc->buffer     + 1;
      byte_index_b = fc->byte_index + 1;
      byte_anz_b   = fc->byte_anz;
      get_next_file_buffer (-1);
   }

/* check for EOF */
   if ((byte_index_a >= byte_anz_a) ||
       (byte_index_b >= byte_anz_b))
   {
      comp_status = STAT_EOF;
   }
   else
   {
   /* default */
      comp_status = STAT_NO_DIFF;

   /* compare loop */
      for ( ;
           (byte_index_a < byte_anz_a) &&
           (byte_index_b < byte_anz_b) ;
            byte_index_a++, buffer_a++,
            byte_index_b++, buffer_b++)
      {
         if (*buffer_a != *buffer_b)
         {
            comp_status = STAT_DIFF_FOUND;
            break;
         }
      }  /* for byte_index */

   /* loop complete passed without any difference ? */
      if (comp_status == STAT_NO_DIFF)
      {
      /* only 1 EOF ? */
         if ((byte_anz_a - byte_index_a) !=
             (byte_anz_b - byte_index_b))
         {
            comp_status = STAT_DIFF_FOUND;
         }
      }
   }

/* show result */
   if (comp_status != STAT_NO_DIFF)
   {
#if WINDOW_COMMAND
      if (act_window)
      {
      /* file a */
         perform_move (byte_index_a);
         perform_view ();
         window_change ();
   
      /* file b */
         perform_move (byte_index_b);
         perform_view ();
         window_change ();
      }
      else
#endif
      {
      /* file a */
         perform_move (byte_index_a);
         get_next_file_buffer (1);
   
      /* file b */
         perform_move (byte_index_b);
         get_next_file_buffer (-1);
   
         perform_view ();
      }
   }

   line_2_flag = 2;
   show_status_line_2 (result[comp_status].message, 0, -2, 0);

   return result[comp_status].flag;  /* 0 = YES, -1 = NO */
}  /* perform_file_compare */

/* -FF-  */

/* Modification History */
/* 06.12.92 - file erzeugt */
/* 07.12.92 - perform_help_option () */
/* 20.12.92 - bei set.indent: buffer overflow abfangen ! */
/* 22.12.92 - perform_intro () */
/* 30.12.92 - help_option erweitert */
/* 02.01.93 - int perform_key_insert ()     (vorher void) */
/* 03.01.93 - MACRO_NESTING_TO_DEEP */
/* 06.01.93 - perform_special_keys () */
/* 08.01.93 - perform_find (..., repeat_count, repeat_max, replace_count) */
/* 02.08.93 - EOL --> EOLN */
/* 04.08.93 - Bug Fix for BINARY_MODE 0: exchange at end of line */
/* 05.08.93 - DELTA_LIMIT 200 (vorher 40) */
/* 12.08.93 - perform_test_eol: offset = offset; */
/* 25.08.93 - perform_view (): line_2_flag = 1   (update status line 2 !) */
/* 31.08.93 - delete_whole_line (): decr. line_anz conditionally */
/* 03.09.93 - Bug Fix: indent with old blank old line and <tab>s */
/* 03.09.93 - perform_delete_start_of_line (int save_flag) */
/* 05.09.93 - Find mit Wildcard: '?' */
/* 07.09.93 - perform_find (..., size_t *len1) */
/* 08.09.93 - save_find_indizes () */
/* 10.09.93 - perform_end_of_line (): special case last line in file */
/* 12.09.93 - get_video_active (ignore_batch) */
/* 16.09.93 - TEST_EOL_MACRO */
/* 29.09.93 - update_rest_of_window(), ...entire_window() */
/* 01.10.93 - window_adjust () */
/* 02.10.93 - init_file_control (fc, 0) */
/* 03.10.93 - perform_scroll_screen () */
/* 10.10.93 - bugfix: perform_move zwischen <cr> und <lf> */
/* 11.10.93 - perform_key_left() / right(.., skip_flag) */
/* 19.10.93 - handling of single <lf>s */
/* 05.11.93 - bugfix: single <lf> in one line */
/* 21.05.94 - perform_move(): limit new_index, statt FATAL_ERROR */
/* 03.06.94 - perform_view(): avoid division by zero */
/* 14.06.94 - perform_delete_whole_line: bugfix:                           */
/*            (no of lines in file was counted wrong, if line > 256 chars) */
/* 14.06.94 - err_message (LINE_TOO_LONG) */
/* 04.07.94 - perform_delete_start_of_line(): bugfix: <tab> ^X */
/* 06.07.94 - check_for_autonl() */
/* 09.07.94 - view_unconditionally() */
/* 21.09.94 - perform_file_reset(): refresh_1_window (), if not in hex edit */
/* 23.09.94 - perform_scroll_screen (): save_byte_index, save_buffer */
/*            (bugfix: vorher inkonsistenter Zustand moeglich,       */
/*            wenn cursor position hinter 0x0d, auf 0x0a)            */
/* 25.09.94 - perform_move (): HIGH_SPEED_MOVE */
/* 28.09.94 - bugfix: HIGH_SPEED_MOVE */
/* 16.02.95 - perform_file_compare() */
/* 20.02.95 - perform_file_compare(), bugfix: long ii (statt int) */
/* 22.02.95 - perform_file_compare(), schleifendurchlaeufe um 1 verringert */
/* 24.02.95 - perform_file_compare(), bugfix (EOF) */
/* 26.04.95 - perform_move(): speed up for "diff is large" */
/* 16.06.95 - check_for_autonl(): (fc->column > (set.margin[2]) + 1)      */
/*            'P'aragraph 'F'ill, und 'S'et 'A'utoinsert 'Y'es o.k. */
/* 26.01.96 - perform_find_byte() */
/* 31.01.96 - WITH_HEX_FIND */
/* 05.09.98 - EOLN_LEN_1 and EOLN_LEN_2: #if --> if */
/* 07.09.98 - EOLN_LEN_1: type cast --> (char) */

⌨️ 快捷键说明

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