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

📄 ed.c

📁 C++游戏开发书籍的实例非常适合初学但又又想往游戏开发方面发展的人学习哦
💻 C
📖 第 1 页 / 共 5 页
字号:
         if (!at_top)
            update_line( win );
         --win->rline;             /* ALWAYS decrement line counter */
         win->ll = win->ll->prev;
         win->bin_offset -= win->ll->len;
         if (!at_top) {
            --win->cline;          /* we aren't at top of screen - so move up */
            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 );
}


/*
 * Name:    set_tabstop
 * Purpose: To set the current interval between tab stops
 * Date:    October 1, 1989
 * Notes:   Tab interval must be reasonable, and this function will
 *           not allow tabs more than MAX_COLS / 2.
 */
int  set_tabstop( WINDOW *window )
{
char num_str[MAX_COLS]; /* tab interval as a character string */
int  tab;               /* new tab interval */
register int rc;
register file_infos *file;

   itoa( mode.ltab_size, num_str, 10 );
   /*
    * tab interval:
    */
   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 {
         /*
          * tab size too long
          */
         error( WARNING, window->bottom_line, ed8 );
         rc = ERROR;
      }
   }

   itoa( mode.ptab_size, num_str, 10 );
   /*
    * tab interval:
    */
   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 {
         /*
          * tab size too long
          */
         error( WARNING, window->bottom_line, ed8 );
         rc = ERROR;
      }
   }
   return( rc );
}


/*
 * Name:    show_line_col
 * Purpose: show current real line and column of current cursor position
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Blank old position and display new position.  current line and
 *          column may take up to 12 columns, which allows the display of
 *          9,999 columns and 9,999,999 lines.
 */
void show_line_col( WINDOW *window )
{
int  i;
register int k;
char line_col[20], num[10];
char *hex_digit = "0123456789abcdef";

   /*
    * blank out current line:column position.
    */
   memset( line_col, ' ', 13 );
   line_col[13] = '\0';

   /*
    * convert column to ascii and store in display buffer.
    */
   itoa( window->rcol+1, num, 10 );
   i = strlen( num ) - 1;
   for (k=12; i>=0; i--, k--)
      line_col[k] = num[i];

   /*
    * put in colon to separate line and column
    */
   line_col[k--] = ':';

   /*
    * convert line to ascii and store in display buffer.
    */
   ltoa( window->rline, num, 10 );
   i = strlen( num ) - 1;
   for (; i>=0; i--, k--)
      line_col[k] = num[i];

   /*
    * find line to start line:column display then output
    */
   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 file was opened in binary mode, show offset from beginning of file.
    */
   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 );
}


/*
 * Name:    show_asterisk
 * Purpose: give user an indication if file is dirty
 * Date:    September 16, 1991
 * Passed:  window:  pointer to current window
 */
void show_asterisk( WINDOW *window )
{
   c_output( window->file_info->modified ? '*' : ' ', window->start_col+4,
             window->top_line-1, g_display.head_color );
}


/*
 * Name:    toggle_overwrite
 * Purpose: toggle overwrite-insert mode
 * Date:    September 16, 1991
 * Passed:  arg_filler:  argument to satify function prototype
 */
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 );
}


/*
 * Name:    toggle_smart_tabs
 * Purpose: toggle smart tab mode
 * Date:    June 5, 1992
 * Passed:  arg_filler:  argument to satify function prototype
 */
int  toggle_smart_tabs( WINDOW *arg_filler )
{
   mode.smart_tab = !mode.smart_tab;
   show_tab_modes( );
   return( OK );
}


/*
 * Name:    toggle_indent
 * Purpose: toggle indent mode
 * Date:    September 16, 1991
 * Passed:  arg_filler:  argument to satify function prototype
 */
int  toggle_indent( WINDOW *arg_filler )
{
   mode.indent = !mode.indent;
   show_indent_mode( );
   return( OK );
}


/*
 * Name:    set_left_margin
 * Purpose: set left margin for word wrap
 * Date:    November 27, 1991
 * Passed:  window
 */
int  set_left_margin( WINDOW *window )
{
register int rc;
char temp[MAX_COLS];

   itoa( mode.left_margin + 1, temp, 10 );
   /*
    * enter left margin
    */
   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) {
         /*
          * left margin out of range
          */
         error( WARNING, window->bottom_line, ed10 );
         rc = ERROR;
      } else {
         mode.left_margin = rc;
         show_all_rulers( );
      }
   }
   return( rc );
}


/*
 * Name:    set_right_margin
 * Purpose: set right margin for word wrap
 * Date:    November 27, 1991
 * Passed:  window
 */
int  set_right_margin( WINDOW *window )
{
char line_buff[(MAX_COLS+1)*2]; /* buffer for char and attribute  */
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 );
      /*
       * enter right margin
       */
      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) {
            /*
             * right margin out of range
             */
            error( WARNING, prompt_line, ed12 );
            rc = ERROR;
         } else {
            mode.right_margin = rc;
            show_all_rulers( );
         }
      }
   }
   return( rc );
}


/*
 * Name:    set_paragraph_margin
 * Purpose: set column to begin paragraph
 * Date:    November 27, 1991
 * Passed:  window
 * Notes:   paragraph may be indented, flush, or offset.
 */
int  set_paragraph_margin( WINDOW *window )
{
register int rc;
char temp[80];

   itoa( mode.parg_margin + 1, temp, 10 );
   /*
    * enter paragraph margin
    */
   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 );
}


/*
 * Name:    toggle_crlf
 * Purpose: toggle crlf mode
 * Date:    November 27, 1991
 * Passed:  arg_filler:  argument to satify function prototype
 */
int  toggle_crlf( WINDOW *window )
{
register WINDOW *w;

   ++window->file_info->crlf;
   if (window->file_info->crlf > BINARY)
      window->file_info->crlf = CRLF;
   w = g_status.window_list;
   while (w != NULL) {
      if (w->file_info == window->file_info  &&  w->visible)
         show_crlf_mode( w );
      w = w->next;
   }
   return( OK );
}


/*
 * Name:    toggle_ww
 * Purpose: toggle word wrap mode
 * Date:    November 27, 1991
 * Passed:  arg_filler:  argument to satify function prototype
 */
int  toggle_ww( WINDOW *arg_filler )
{
   ++mode.word_wrap;
   if (mode.word_wrap > DYNAMIC_WRAP)
      mode.word_wrap = NO_WRAP;
   show_wordwrap_mode( );
   return( OK );
}


/*
 * Name:    toggle_trailing
 * Purpose: toggle eleminating trainling space at eol
 * Date:    November 25, 1991
 * Passed:  arg_filler:  argument to satify function prototype
 */
int  toggle_trailing( WINDOW *arg_filler )
{
   mode.trailing = !mode.trailing;
   show_trailing( );
   return( OK );
}


/*
 * Name:    toggle_z
 * Purpose: toggle writing control z at eof
 * Date:    November 25, 1991
 * Passed:  arg_filler:  argument to satify function prototype
 */
int  toggle_z( WINDOW *arg_filler )
{
   mode.control_z = !mode.control_z;
   show_control_z( );
   return( OK );
}


/*
 * Name:    toggle_eol
 * Purpose: toggle writing eol character at eol
 * Date:    November 25, 1991
 * Passed:  arg_filler:  argument to satify function prototype
 */
int  toggle_eol( WINDOW *arg_filler )
{
register file_infos *file;

   mode.show_eol = !mode.show_eol;
   for (file=g_status.file_list; file != NULL; file=file->next)
      file->dirty = GLOBAL;
   return( OK );
}


/*
 * Name:    toggle_search_case

⌨️ 快捷键说明

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