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

📄 utils.c

📁 C++游戏开发书籍的实例非常适合初学但又又想往游戏开发方面发展的人学习哦
💻 C
📖 第 1 页 / 共 5 页
字号:
      win->rline += i;
      win->cline = win->cline + i - win->page;
      win->bin_offset += len;
      win->ll = p;
      win->file_info->dirty = LOCAL;
   } else
      rc = ERROR;
   sync( win );
   return( rc );
}


/*
 * Name:    scroll_down
 * Purpose: scroll window down one line
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If there is a line to scroll_down, make the window LOCAL dirty.
 *          We have to redraw the screen anyway, so don't update here.
 */
int  scroll_down( WINDOW *window )
{
int  rc = OK;
register WINDOW *win;   /* put window pointer in a register */

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   if (win->cline == win->top_line + win->ruler) {
      if (win->ll->next != NULL) {
         ++win->rline;
         win->bin_offset += win->ll->len;
         win->ll = win->ll->next;
         win->file_info->dirty = LOCAL;
      } else
         rc = ERROR;
   } else {
      --win->cline;
      win->file_info->dirty = LOCAL;
   }
   sync( win );
   return( rc );
}


/*
 * Name:    scroll_up
 * Purpose: To scroll the window up one line
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If this is the first page, then update screen here.  Else, make
 *           the window LOCAL dirty because we have to redraw screen.
 */
int  scroll_up( WINDOW *window )
{
int  rc = OK;
register WINDOW *win;   /* put window pointer in a register */

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   if (win->rline > 1) {
      if (win->rline == (win->cline - (win->top_line + win->ruler - 1))) {
         if (!mode.sync)
            update_line( win );
         win->ll = win->ll->prev;
         win->bin_offset -= win->ll->len;
         --win->rline;
         --win->cline;
         if (!mode.sync)
            show_curl_line( win );
      } else {
         if (win->cline == win->bottom_line) {
            --win->rline;
            win->ll = win->ll->prev;
            win->bin_offset -= win->ll->len;
            win->file_info->dirty = LOCAL;
         } else {
            ++win->cline;
            win->file_info->dirty = LOCAL;
         }
      }
   } else
     rc = ERROR;
   sync( win );
   return( rc );
}


/*
 * Name:    pan_up
 * Purpose: To leave cursor on same logical line and scroll text up
 * Date:    September 1, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If cursor is on first page then do not scroll.
 */
int  pan_up( WINDOW *window )
{
int  rc = OK;
register WINDOW *win;   /* put window pointer in a register */

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );

   /*
    * see if cursor is on the first page. if it's not then pan_up.
    */
   if (win->rline != (win->cline+1 - (win->top_line + win->ruler))) {
      if (win->rline > 1) {
         --win->rline;
         win->ll = win->ll->prev;
         win->bin_offset -= win->ll->len;
         win->file_info->dirty = LOCAL;
      }
   } else
      rc = ERROR;
   sync( win );
   return( rc );
}


/*
 * Name:    pan_down
 * Purpose: To leave cursor on same logical line and scroll text down
 * Date:    September 1, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If cursor is on last line in file then do not scroll.
 */
int  pan_down( WINDOW *window )
{
int  rc = OK;
register WINDOW *win;   /* put window pointer in a register */

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   if (win->ll->len != EOF) {
      ++win->rline;
      win->bin_offset += win->ll->len;
      win->ll = win->ll->next;
      win->file_info->dirty = LOCAL;
   } else
      rc = ERROR;
   sync( win );
   return( rc );
}


/*
 * Name:    show_window_header
 * Purpose: show file stuff in window header
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Clear line and display header in a lite bar
 */
void show_window_header( WINDOW *window )
{
char status_line[MAX_COLS+2];   /* status line at top of window */
register WINDOW *win;           /* put window pointer in a register */
int  len;

   win = window;
   len = win->vertical ? win->end_col + 1 - win->start_col : win->end_col;

   assert( len >= 0 );
   assert( len <= MAX_COLS );

   memset( status_line, ' ', len );
   status_line[len] = '\0';
   s_output( status_line, win->top_line-1, win->start_col,g_display.head_color);
   show_window_number_letter( win );
   show_window_fname( win );
   show_crlf_mode( win );
   show_size( win );
   show_line_col( win );
}


/*
 * Name:    show_window_number_letter
 * Purpose: show file number and letter of window in lite bar
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 */
void show_window_number_letter( WINDOW *window )
{
int  col;
char temp[10];
register WINDOW *win;   /* put window pointer in a register */

   win = window;
   col = win->start_col;
   s_output( "   ", win->top_line-1, col, g_display.head_color );
   itoa( win->file_info->file_no, temp, 10 );
   s_output( temp, win->top_line-1, strlen( temp ) > 1 ? col : col+1,
             g_display.head_color );
   c_output( win->letter, col+2, win->top_line-1, g_display.head_color );
}


/*
 * Name:    show_window_fname
 * Purpose: show file name in window header.
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Clear name field and display name in a lite bar
 */
void show_window_fname( WINDOW *window )
{
char status_line[MAX_COLS+2];   /* status line at top of window */
register int  fattr;
char *p;
register WINDOW *win;          /* put window pointer in a register */
int  col;
int  len;

   win = window;
   col = win->start_col;
   len = win->vertical ? 11 : FNAME_LENGTH;

   assert( len >= 0 );
   assert( len <= MAX_COLS );

   memset( status_line, ' ', len );
   status_line[len] = '\0';
   s_output( status_line, win->top_line-1, col+5, g_display.head_color );

   assert( strlen( win->file_info->file_name ) < MAX_COLS );

   strcpy( status_line, win->file_info->file_name );
   p = status_line;
   if (win->vertical) {
      len = strlen( status_line );
      for (p=status_line+len;*(p-1) != ':' && *(p-1) != '\\' && p>status_line;)
         --p;
   } else {
      status_line[FNAME_LENGTH] = '\0';
      p = status_line;
   }
   s_output( p, win->top_line-1, col+5, g_display.head_color );
   if (!win->vertical) {
      fattr = win->file_info->file_attrib;
      p = status_line;
      *p++ = (char)(fattr & ARCHIVE   ? 'A' : '-');
      *p++ = (char)(fattr & SYSTEM    ? 'S' : '-');
      *p++ = (char)(fattr & HIDDEN    ? 'H' : '-');
      *p++ = (char)(fattr & READ_ONLY ? 'R' : '-');
      *p   = '\0';
      s_output( status_line, win->top_line-1, col+51, g_display.head_color );
   }
}


/*
 * Name:    show_crlf_mode
 * Purpose: display state of crlf flag
 * Date:    June 5, 1991
 */
void show_crlf_mode( WINDOW *window )
{
char status_line[MAX_COLS+2];   /* status line at top of window */

   if (!window->vertical) {
      switch (window->file_info->crlf) {
         case LF :
            strcpy( status_line, "lf  " );
            break;
         case CRLF :
            strcpy( status_line, "crlf" );
            break;
         case BINARY :
            strcpy( status_line, "BIN " );
            break;
         default :
            assert( FALSE );
      }
      s_output( status_line, window->top_line-1, window->start_col+56,
                g_display.head_color );
   }
}


/*
 * Name:    show_size
 * Purpose: show number of lines in file
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 */
void show_size( WINDOW *window )
{
char csize[20];

   if (!window->vertical  &&  window->file_info->crlf != BINARY) {
      s_output( "       ", window->top_line-1, 61, g_display.head_color );
      ltoa( window->file_info->length, csize, 10 );
      s_output( csize, window->top_line-1, 61, g_display.head_color );
   }
}


/*
 * Name:    quit
 * Purpose: To close the current window without saving the current file.
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If the file has been modified but not saved, then the user is
 *           given a second chance before the changes are discarded.
 *          Note that this is only necessary if this is the last window
 *           that refers to the file.  If another window still refers to
 *           the file, then the check can be left until later.
 */
int  quit( WINDOW *window )
{
int  prompt_line;
char line_buff[(MAX_COLS+2)*2]; /* buffer for char and attribute  */
register file_infos *file;
WINDOW *wp;
int  count = 0;
int  rc = OK;

   entab_linebuff( );
   if (un_copy_line( window->ll, window, TRUE ) == ERROR)
      return( ERROR );
   prompt_line = window->bottom_line;
   file = window->file_info;
   for (wp=g_status.window_list; wp != NULL; wp=wp->next) {
      if (wp->file_info == file && wp->visible)
         ++count;
   }
   if (file->modified && count == 1) {
      save_screen_line( 0, prompt_line, line_buff );
      /*
       * abandon changes (y/n)
       */
      set_prompt( utils12, prompt_line );
      if (get_yn( ) != A_YES)
         rc = ERROR;
      restore_screen_line( 0, prompt_line, line_buff );
   }

   /*
    * remove window, allocate screen lines to other windows etc
    */
   if (rc == OK)
      finish( window );
   return( OK );
}


/*
 * Name:    move_up
 * Purpose: To move the cursor up one line
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If the cursor is at the top of the window, then the file must
 *           be scrolled down.
 */
int  move_up( WINDOW *window )
{
int  rc = OK;
register WINDOW *win;   /* put window pointer in a register */
int  at_top = FALSE;    /* is cline at top of screen? */

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );

   /*
    * if no previous line, give up
    */
   if (win->rline > 1) {
      if (win->cline == win->top_line + win->ruler) {
         win->file_info->dirty = LOCAL;
         at_top = TRUE;
      }
      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
      rc = ERROR;
   sync( win );
   return( rc );
}


/*
 * Name:    move_down
 * Purpose: To move the cursor down one line
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If the cursor is at the bottom of the window, then the file must
 *           be scrolled up.   If the cursor is at the bottom of the file,
 *           then scroll line up until it is at top of screen.
 */
int  move_down( WINDOW *window )
{
int  rc;

   rc = prepare_move_down( window );
   sync( window );
   return( rc );
}


/*
 * Name:    prepare_move_down
 * Purpose: Do the stuff needed to move the cursor down one line.
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Put all the stuff needed to move the cursor down one line in
 *           one function, so several functions can use the guts of the
 *           algorithm.
 */
int  prepare_move_down( WINDOW *window )
{
int  rc = OK;
register WINDOW *win;   /* put window pointer in a register */
int  at_bottom = FALSE; /* is cline at bottom of screen */

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   if (win->cline == win->bottom_line) {
      win->file_info->dirty = LOCAL;
      at_bottom = TRUE;
   }
   if (!at_bottom)
      update_line( win );
   if (win->ll->len != EOF) {
      win->bin_offset += win->ll->len;
      ++win->rline;             /* ALWAYS increment line counter */
      win->ll = win->ll->next;
      if (!at_bottom) {
         ++win->cline;          /* if not at bottom of screen move down */
         show_curl_line( win );
      }
   } else if (win->cline > win->top_line + win->ruler) {
      --win->cline;
      win->file_info->dirty = LOCAL;
      rc = ERROR;
   } else
      rc = ERROR;
   return( rc );
}


/*
 * Name:    move_left
 * Purpose: To move the cursor left one character
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If the cursor is already at the left of the screen, then

⌨️ 快捷键说明

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