root/src/editor/editbuffer.h

/* [previous][next][first][last][top][bottom][index][help]  */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. edit_buffer_get_current_byte
  2. edit_buffer_get_previous_byte
  3. edit_buffer_get_current_bol
  4. edit_buffer_get_current_eol

   1 /** \file
   2  *  \brief Header: text keep buffer for WEdit
   3  */
   4 
   5 #ifndef MC__EDIT_BUFFER_H
   6 #define MC__EDIT_BUFFER_H
   7 
   8 /*** typedefs(not structures) and defined constants **********************************************/
   9 
  10 /*** enums ***************************************************************************************/
  11 
  12 /*** structures declarations (and typedefs of structures)*****************************************/
  13 
  14 typedef struct edit_buffer_struct
  15 {
  16     off_t curs1;     // position of the cursor from the beginning of the file.
  17     off_t curs2;     // position from the end of the file
  18     GPtrArray *b1;   // all data up to curs1
  19     GPtrArray *b2;   // all data from end of file down to curs2
  20     off_t size;      // file size
  21     long lines;      // total lines in the file
  22     long curs_line;  // line number of the cursor.
  23 } edit_buffer_t;
  24 
  25 typedef struct edit_buffer_read_file_status_msg_struct
  26 {
  27     simple_status_msg_t status_msg;  // base class
  28 
  29     gboolean first;
  30     edit_buffer_t *buf;
  31     off_t loaded;
  32 } edit_buffer_read_file_status_msg_t;
  33 
  34 /*** global variables defined in .c file *********************************************************/
  35 
  36 /*** declarations of public functions ************************************************************/
  37 
  38 void edit_buffer_init (edit_buffer_t *buf, off_t size);
  39 void edit_buffer_clean (edit_buffer_t *buf);
  40 
  41 int edit_buffer_get_byte (const edit_buffer_t *buf, off_t byte_index);
  42 #ifdef HAVE_CHARSET
  43 int edit_buffer_get_utf (const edit_buffer_t *buf, off_t byte_index, int *char_length);
  44 int edit_buffer_get_prev_utf (const edit_buffer_t *buf, off_t byte_index, int *char_length);
  45 #endif
  46 long edit_buffer_count_lines (const edit_buffer_t *buf, off_t first, off_t last);
  47 off_t edit_buffer_get_bol (const edit_buffer_t *buf, off_t current);
  48 off_t edit_buffer_get_eol (const edit_buffer_t *buf, off_t current);
  49 GString *edit_buffer_get_word_from_pos (const edit_buffer_t *buf, off_t start_pos, off_t *start,
  50                                         gsize *cut);
  51 gboolean edit_buffer_find_word_start (const edit_buffer_t *buf, off_t *word_start, gsize *word_len);
  52 
  53 void edit_buffer_insert (edit_buffer_t *buf, int c);
  54 void edit_buffer_insert_ahead (edit_buffer_t *buf, int c);
  55 int edit_buffer_delete (edit_buffer_t *buf);
  56 int edit_buffer_backspace (edit_buffer_t *buf);
  57 
  58 off_t edit_buffer_get_forward_offset (const edit_buffer_t *buf, off_t current, long lines,
  59                                       off_t upto);
  60 off_t edit_buffer_get_backward_offset (const edit_buffer_t *buf, off_t current, long lines);
  61 
  62 off_t edit_buffer_read_file (edit_buffer_t *buf, int fd, off_t size,
  63                              edit_buffer_read_file_status_msg_t *sm, gboolean *aborted);
  64 off_t edit_buffer_write_file (edit_buffer_t *buf, int fd);
  65 
  66 int edit_buffer_calc_percent (const edit_buffer_t *buf, off_t offset);
  67 
  68 /*** inline functions ****************************************************************************/
  69 
  70 static inline int
  71 edit_buffer_get_current_byte (const edit_buffer_t *buf)
     /* [previous][next][first][last][top][bottom][index][help]  */
  72 {
  73     return edit_buffer_get_byte (buf, buf->curs1);
  74 }
  75 
  76 /* --------------------------------------------------------------------------------------------- */
  77 
  78 static inline int
  79 edit_buffer_get_previous_byte (const edit_buffer_t *buf)
     /* [previous][next][first][last][top][bottom][index][help]  */
  80 {
  81     return edit_buffer_get_byte (buf, buf->curs1 - 1);
  82 }
  83 
  84 /* --------------------------------------------------------------------------------------------- */
  85 /**
  86  * Get "begin-of-line" offset of current line
  87  *
  88  * @param buf editor buffer
  89  *
  90  * @return index of first char of current line
  91  */
  92 
  93 static inline off_t
  94 edit_buffer_get_current_bol (const edit_buffer_t *buf)
     /* [previous][next][first][last][top][bottom][index][help]  */
  95 {
  96     return edit_buffer_get_bol (buf, buf->curs1);
  97 }
  98 
  99 /* --------------------------------------------------------------------------------------------- */
 100 /**
 101  * Get "end-of-line" offset of current line
 102  *
 103  * @param buf editor buffer
 104  *
 105  * @return index of first char of current line + 1
 106  */
 107 
 108 static inline off_t
 109 edit_buffer_get_current_eol (const edit_buffer_t *buf)
     /* [previous][next][first][last][top][bottom][index][help]  */
 110 {
 111     return edit_buffer_get_eol (buf, buf->curs1);
 112 }
 113 
 114 /* --------------------------------------------------------------------------------------------- */
 115 
 116 #endif

/* [previous][next][first][last][top][bottom][index][help]  */