root/src/viewer/internal.h

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

INCLUDED FROM


   1 #ifndef MC__VIEWER_INTERNAL_H
   2 #define MC__VIEWER_INTERNAL_H
   3 
   4 #include <stdlib.h>
   5 #include <stdio.h>
   6 #include <sys/types.h>
   7 
   8 #include "lib/global.h"
   9 
  10 #include "lib/search.h"
  11 #include "lib/widget.h"
  12 #include "lib/vfs/vfs.h"        /* vfs_path_t */
  13 
  14 #include "src/keybind-defaults.h"       /* global_keymap_t */
  15 #include "src/filemanager/dir.h"        /* dir_list */
  16 
  17 #include "mcviewer.h"
  18 
  19 /*** typedefs(not structures) and defined constants **********************************************/
  20 
  21 typedef unsigned char byte;
  22 
  23 /* A width or height on the screen */
  24 typedef unsigned int screen_dimen;
  25 
  26 /*** enums ***************************************************************************************/
  27 
  28 /* data sources of the view */
  29 enum view_ds
  30 {
  31     DS_NONE,                    /* No data available */
  32     DS_STDIO_PIPE,              /* Data comes from a pipe using popen/pclose */
  33     DS_VFS_PIPE,                /* Data comes from a piped-in VFS file */
  34     DS_FILE,                    /* Data comes from a VFS file */
  35     DS_STRING                   /* Data comes from a string in memory */
  36 };
  37 
  38 enum ccache_type
  39 {
  40     CCACHE_OFFSET,
  41     CCACHE_LINECOL
  42 };
  43 
  44 typedef enum
  45 {
  46     NROFF_TYPE_NONE = 0,
  47     NROFF_TYPE_BOLD = 1,
  48     NROFF_TYPE_UNDERLINE = 2
  49 } nroff_type_t;
  50 
  51 /*** structures declarations (and typedefs of structures)*****************************************/
  52 
  53 /* A node for building a change list on change_list */
  54 struct hexedit_change_node
  55 {
  56     struct hexedit_change_node *next;
  57     off_t offset;
  58     byte value;
  59 };
  60 
  61 struct area
  62 {
  63     screen_dimen top, left;
  64     screen_dimen height, width;
  65 };
  66 
  67 /* A cache entry for mapping offsets into line/column pairs and vice versa.
  68  * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
  69  * line and column of that cache entry. cc_nroff_column is the column
  70  * corresponding to cc_offset in nroff mode.
  71  */
  72 typedef struct
  73 {
  74     off_t cc_offset;
  75     off_t cc_line;
  76     off_t cc_column;
  77     off_t cc_nroff_column;
  78 } coord_cache_entry_t;
  79 
  80 typedef struct
  81 {
  82     size_t size;
  83     size_t capacity;
  84     coord_cache_entry_t **cache;
  85 } coord_cache_t;
  86 
  87 /* TODO: find a better name. This is not actually a "state machine",
  88  * but a "state machine's state", but that sounds silly.
  89  * Could be parser_state, formatter_state... */
  90 typedef struct
  91 {
  92     off_t offset;               /* The file offset at which this is the state. */
  93     off_t unwrapped_column;     /* Columns if the paragraph wasn't wrapped, */
  94     /* used for positioning TABs in wrapped lines */
  95     gboolean nroff_underscore_is_underlined;    /* whether _\b_ is underlined rather than bold */
  96     gboolean print_lonely_combining;    /* whether lonely combining marks are printed on a dotted circle */
  97 } mcview_state_machine_t;
  98 
  99 struct mcview_nroff_struct;
 100 
 101 struct WView
 102 {
 103     Widget widget;
 104 
 105     vfs_path_t *filename_vpath; /* Name of the file */
 106     vfs_path_t *workdir_vpath;  /* Name of the working directory */
 107     char *command;              /* Command used to pipe data in */
 108 
 109     enum view_ds datasource;    /* Where the displayed data comes from */
 110 
 111     /* stdio pipe data source */
 112     mc_pipe_t *ds_stdio_pipe;   /* Output of a shell command */
 113     gboolean pipe_first_err_msg;        /* Show only 1st message from stderr */
 114 
 115     /* vfs pipe data source */
 116     int ds_vfs_pipe;            /* Non-seekable vfs file descriptor */
 117 
 118     /* vfs file data source */
 119     int ds_file_fd;             /* File with random access */
 120     off_t ds_file_filesize;     /* Size of the file */
 121     off_t ds_file_offset;       /* Offset of the currently loaded data */
 122     byte *ds_file_data;         /* Currently loaded data */
 123     size_t ds_file_datalen;     /* Number of valid bytes in file_data */
 124     size_t ds_file_datasize;    /* Number of allocated bytes in file_data */
 125 
 126     /* string data source */
 127     byte *ds_string_data;       /* The characters of the string */
 128     size_t ds_string_len;       /* The length of the string */
 129 
 130     /* Growing buffers information */
 131     gboolean growbuf_in_use;    /* Use the growing buffers? */
 132     GPtrArray *growbuf_blockptr;        /* Pointer to the block pointers */
 133     size_t growbuf_lastindex;   /* Number of bytes in the last page of the
 134                                    growing buffer */
 135     gboolean growbuf_finished;  /* TRUE when all data has been read. */
 136 
 137     mcview_mode_flags_t mode_flags;
 138 
 139     /* Hex editor modes */
 140     gboolean hexedit_mode;      /* Hexview or Hexedit */
 141     gboolean hexview_in_text;   /* Is the hexview cursor in the text area? */
 142     int bytes_per_line;         /* Number of bytes per line in hex mode */
 143     off_t hex_cursor;           /* Hexview cursor position in file */
 144     gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
 145     gboolean locked;            /* We hold lock on current file */
 146 
 147 #ifdef HAVE_CHARSET
 148     gboolean utf8;              /* It's multibyte file codeset */
 149 #endif
 150 
 151     coord_cache_t *coord_cache; /* Cache for mapping offsets to cursor positions */
 152 
 153     /* Display information */
 154     screen_dimen dpy_frame_size;        /* Size of the frame surrounding the real viewer */
 155     off_t dpy_start;            /* Offset of the displayed data (start of the paragraph in non-hex mode) */
 156     off_t dpy_end;              /* Offset after the displayed data */
 157     off_t dpy_paragraph_skip_lines;     /* Extra lines to skip in wrap mode */
 158     mcview_state_machine_t dpy_state_top;       /* Parser-formatter state at the topmost visible line in wrap mode */
 159     mcview_state_machine_t dpy_state_bottom;    /* Parser-formatter state after the bottomvisible line in wrap mode */
 160     gboolean dpy_wrap_dirty;    /* dpy_state_top needs to be recomputed */
 161     off_t dpy_text_column;      /* Number of skipped columns in non-wrap
 162                                  * text mode */
 163     screen_dimen cursor_col;    /* Cursor column */
 164     screen_dimen cursor_row;    /* Cursor row */
 165     struct hexedit_change_node *change_list;    /* Linked list of changes */
 166     struct area status_area;    /* Where the status line is displayed */
 167     struct area ruler_area;     /* Where the ruler is displayed */
 168     struct area data_area;      /* Where the data is displayed */
 169 
 170     ssize_t force_max;          /* Force a max offset, or -1 */
 171 
 172     int dirty;                  /* Number of skipped updates */
 173     gboolean dpy_bbar_dirty;    /* Does the button bar need to be updated? */
 174 
 175 
 176     /* handle of search engine */
 177     mc_search_t *search;
 178     gchar *last_search_string;
 179     struct mcview_nroff_struct *search_nroff_seq;
 180     off_t search_start;         /* First character to start searching from */
 181     off_t search_end;           /* Length of found string or 0 if none was found */
 182     int search_numNeedSkipChar;
 183 
 184     /* Markers */
 185     int marker;                 /* mark to use */
 186     off_t marks[10];            /* 10 marks: 0..9 */
 187 
 188     off_t update_steps;         /* The number of bytes between percent increments */
 189     off_t update_activate;      /* Last point where we updated the status */
 190 
 191     /* converter for translation of text */
 192     GIConv converter;
 193 
 194     GArray *saved_bookmarks;
 195 
 196     dir_list *dir;              /* List of current directory files
 197                                  * to handle CK_FileNext and CK_FilePrev commands */
 198     int *dir_idx;               /* Index of current file in dir structure.
 199                                  * Pointer is used here as reference to WPanel::dir::count */
 200     vfs_path_t *ext_script;     /* Temporary script file created by regex_command_for() */
 201 };
 202 
 203 typedef struct mcview_nroff_struct
 204 {
 205     WView *view;
 206     off_t index;
 207     int char_length;
 208     int current_char;
 209     nroff_type_t type;
 210     nroff_type_t prev_type;
 211 } mcview_nroff_t;
 212 
 213 typedef struct mcview_search_options_t
 214 {
 215     mc_search_type_t type;
 216     gboolean case_sens;
 217     gboolean backwards;
 218     gboolean whole_words;
 219     gboolean all_codepages;
 220 } mcview_search_options_t;
 221 
 222 /*** global variables defined in .c file *********************************************************/
 223 
 224 extern mcview_search_options_t mcview_search_options;
 225 
 226 /*** declarations of public functions ************************************************************/
 227 
 228 /* actions_cmd.c:  */
 229 cb_ret_t mcview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
 230 cb_ret_t mcview_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
 231                                  void *data);
 232 
 233 /* ascii.c: */
 234 void mcview_display_text (WView *);
 235 void mcview_state_machine_init (mcview_state_machine_t *, off_t);
 236 void mcview_ascii_move_down (WView *, off_t);
 237 void mcview_ascii_move_up (WView *, off_t);
 238 void mcview_ascii_moveto_bol (WView *);
 239 void mcview_ascii_moveto_eol (WView *);
 240 
 241 /* coord_cache.c: */
 242 coord_cache_t *coord_cache_new (void);
 243 void coord_cache_free (coord_cache_t * cache);
 244 
 245 #ifdef MC_ENABLE_DEBUGGING_CODE
 246 void mcview_ccache_dump (WView * view);
 247 #endif
 248 
 249 void mcview_ccache_lookup (WView * view, coord_cache_entry_t * coord, enum ccache_type lookup_what);
 250 
 251 /* datasource.c: */
 252 void mcview_set_datasource_none (WView *);
 253 off_t mcview_get_filesize (WView *);
 254 void mcview_update_filesize (WView * view);
 255 char *mcview_get_ptr_file (WView *, off_t);
 256 char *mcview_get_ptr_string (WView *, off_t);
 257 gboolean mcview_get_utf (WView * view, off_t byte_index, int *ch, int *ch_len);
 258 gboolean mcview_get_byte_string (WView *, off_t, int *);
 259 gboolean mcview_get_byte_none (WView *, off_t, int *);
 260 void mcview_set_byte (WView *, off_t, byte);
 261 void mcview_file_load_data (WView *, off_t);
 262 void mcview_close_datasource (WView *);
 263 void mcview_set_datasource_file (WView *, int, const struct stat *);
 264 gboolean mcview_load_command_output (WView *, const char *);
 265 void mcview_set_datasource_vfs_pipe (WView *, int);
 266 void mcview_set_datasource_string (WView *, const char *);
 267 
 268 /* dialog.c: */
 269 gboolean mcview_dialog_search (WView * view);
 270 gboolean mcview_dialog_goto (WView * view, off_t * offset);
 271 
 272 /* display.c: */
 273 void mcview_update (WView * view);
 274 void mcview_display (WView * view);
 275 void mcview_compute_areas (WView * view);
 276 void mcview_update_bytes_per_line (WView * view);
 277 void mcview_display_toggle_ruler (WView * view);
 278 void mcview_display_clean (WView * view);
 279 void mcview_display_ruler (WView * view);
 280 
 281 /* growbuf.c: */
 282 void mcview_growbuf_init (WView * view);
 283 void mcview_growbuf_done (WView * view);
 284 void mcview_growbuf_free (WView * view);
 285 off_t mcview_growbuf_filesize (WView * view);
 286 void mcview_growbuf_read_until (WView * view, off_t p);
 287 gboolean mcview_get_byte_growing_buffer (WView * view, off_t p, int *);
 288 char *mcview_get_ptr_growing_buffer (WView * view, off_t p);
 289 
 290 /* hex.c: */
 291 void mcview_display_hex (WView * view);
 292 gboolean mcview_hexedit_save_changes (WView * view);
 293 void mcview_toggle_hexedit_mode (WView * view);
 294 void mcview_hexedit_free_change_list (WView * view);
 295 void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
 296 
 297 /* lib.c: */
 298 void mcview_toggle_magic_mode (WView * view);
 299 void mcview_toggle_wrap_mode (WView * view);
 300 void mcview_toggle_nroff_mode (WView * view);
 301 void mcview_toggle_hex_mode (WView * view);
 302 void mcview_init (WView * view);
 303 void mcview_done (WView * view);
 304 void mcview_select_encoding (WView * view);
 305 void mcview_set_codeset (WView * view);
 306 void mcview_show_error (WView * view, const char *error);
 307 off_t mcview_bol (WView * view, off_t current, off_t limit);
 308 off_t mcview_eol (WView * view, off_t current);
 309 char *mcview_get_title (const WDialog * h, size_t len);
 310 int mcview_calc_percent (WView * view, off_t p);
 311 
 312 /* move.c */
 313 void mcview_move_up (WView *, off_t);
 314 void mcview_move_down (WView *, off_t);
 315 void mcview_move_left (WView *, off_t);
 316 void mcview_move_right (WView *, off_t);
 317 void mcview_moveto_top (WView *);
 318 void mcview_moveto_bottom (WView *);
 319 void mcview_moveto_bol (WView *);
 320 void mcview_moveto_eol (WView *);
 321 void mcview_moveto_offset (WView *, off_t);
 322 void mcview_moveto (WView *, off_t, off_t);
 323 void mcview_coord_to_offset (WView *, off_t *, off_t, off_t);
 324 void mcview_offset_to_coord (WView *, off_t *, off_t *, off_t);
 325 void mcview_place_cursor (WView *);
 326 void mcview_moveto_match (WView *);
 327 
 328 /* nroff.c: */
 329 int mcview__get_nroff_real_len (WView * view, off_t, off_t p);
 330 mcview_nroff_t *mcview_nroff_seq_new_num (WView * view, off_t p);
 331 mcview_nroff_t *mcview_nroff_seq_new (WView * view);
 332 void mcview_nroff_seq_free (mcview_nroff_t **);
 333 nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
 334 int mcview_nroff_seq_next (mcview_nroff_t *);
 335 int mcview_nroff_seq_prev (mcview_nroff_t *);
 336 
 337 /* search.c: */
 338 mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
 339                                               int *current_char);
 340 mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset);
 341 void mcview_do_search (WView * view, off_t want_search_start);
 342 
 343 /*** inline functions ****************************************************************************/
 344 
 345 #include "inlines.h"
 346 
 347 #endif /* MC__VIEWER_INTERNAL_H */

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