2 #ifndef MC_VIEWER_INTERNAL_H
3 #define MC_VIEWER_INTERNAL_H
9 #include "lib/global.h"
11 #include "lib/search.h"
13 #include "src/dialog.h"
14 #include "src/widget.h"
15 #include "src/keybind.h" /* global_keymap_t */
17 /*** typedefs(not structures) and defined constants ********************/
19 typedef unsigned char byte
;
21 /* A width or height on the screen */
22 typedef unsigned int screen_dimen
;
24 #define OFFSETTYPE_PRIX "lX"
25 #define OFFSETTYPE_PRId "lu"
27 extern const off_t INVALID_OFFSET
;
28 extern const off_t OFFSETTYPE_MAX
;
30 /*** enums *************************************************************/
32 /* data sources of the view */
35 DS_NONE
, /* No data available */
36 DS_STDIO_PIPE
, /* Data comes from a pipe using popen/pclose */
37 DS_VFS_PIPE
, /* Data comes from a piped-in VFS file */
38 DS_FILE
, /* Data comes from a VFS file */
39 DS_STRING
/* Data comes from a string in memory */
52 NROFF_TYPE_UNDERLINE
= 2
55 /*** structures declarations (and typedefs of structures)***************/
57 /* A node for building a change list on change_list */
58 struct hexedit_change_node
60 struct hexedit_change_node
*next
;
67 screen_dimen top
, left
;
68 screen_dimen height
, width
;
71 /* A cache entry for mapping offsets into line/column pairs and vice versa.
72 * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
73 * line and column of that cache entry. cc_nroff_column is the column
74 * corresponding to cc_offset in nroff mode.
81 off_t cc_nroff_column
;
82 } coord_cache_entry_t
;
88 coord_cache_entry_t
**cache
;
91 struct mcview_nroff_struct
;
93 typedef struct mcview_struct
97 char *filename
; /* Name of the file */
98 char *command
; /* Command used to pipe data in */
100 enum view_ds datasource
; /* Where the displayed data comes from */
102 /* stdio pipe data source */
103 FILE *ds_stdio_pipe
; /* Output of a shell command */
105 /* vfs pipe data source */
106 int ds_vfs_pipe
; /* Non-seekable vfs file descriptor */
108 /* vfs file data source */
109 int ds_file_fd
; /* File with random access */
110 off_t ds_file_filesize
; /* Size of the file */
111 off_t ds_file_offset
; /* Offset of the currently loaded data */
112 byte
*ds_file_data
; /* Currently loaded data */
113 size_t ds_file_datalen
; /* Number of valid bytes in file_data */
114 size_t ds_file_datasize
; /* Number of allocated bytes in file_data */
116 /* string data source */
117 byte
*ds_string_data
; /* The characters of the string */
118 size_t ds_string_len
; /* The length of the string */
120 /* Growing buffers information */
121 gboolean growbuf_in_use
; /* Use the growing buffers? */
122 GPtrArray
*growbuf_blockptr
; /* Pointer to the block pointers */
123 size_t growbuf_lastindex
; /* Number of bytes in the last page of the
125 gboolean growbuf_finished
; /* TRUE when all data has been read. */
128 gboolean hex_mode
; /* Hexview or Hexedit */
129 gboolean hexedit_mode
; /* Hexedit */
130 gboolean hexview_in_text
; /* Is the hexview cursor in the text area? */
131 gboolean text_nroff_mode
; /* Nroff-style highlighting */
132 gboolean text_wrap_mode
; /* Wrap text lines to fit them on the screen */
133 gboolean magic_mode
; /* Preprocess the file using external programs */
134 gboolean utf8
; /* It's multibyte file codeset */
136 /* Additional editor state */
137 gboolean hexedit_lownibble
; /* Are we editing the last significant nibble? */
138 coord_cache_t
*coord_cache
; /* Cache for mapping offsets to cursor positions */
140 /* Display information */
141 screen_dimen dpy_frame_size
; /* Size of the frame surrounding the real viewer */
142 off_t dpy_start
; /* Offset of the displayed data */
143 off_t dpy_end
; /* Offset after the displayed data */
144 off_t dpy_text_column
; /* Number of skipped columns in non-wrap
146 off_t hex_cursor
; /* Hexview cursor position in file */
147 screen_dimen cursor_col
; /* Cursor column */
148 screen_dimen cursor_row
; /* Cursor row */
149 struct hexedit_change_node
*change_list
; /* Linked list of changes */
150 struct area status_area
; /* Where the status line is displayed */
151 struct area ruler_area
; /* Where the ruler is displayed */
152 struct area data_area
; /* Where the data is displayed */
154 int dirty
; /* Number of skipped updates */
155 gboolean dpy_bbar_dirty
; /* Does the button bar need to be updated? */
158 int bytes_per_line
; /* Number of bytes per line in hex mode */
160 /* Search variables */
161 off_t search_start
; /* First character to start searching from */
162 off_t search_end
; /* Length of found string or 0 if none was found */
164 /* Pointer to the last search command */
165 gboolean want_to_quit
; /* Prepare for cleanup ... */
168 int marker
; /* mark to use */
169 off_t marks
[10]; /* 10 marks: 0..9 */
171 int move_dir
; /* return value from widget:
173 * -1 view previous file
177 off_t update_steps
; /* The number of bytes between percent
179 off_t update_activate
; /* Last point where we updated the status */
181 /* converter for translation of text */
185 const global_keymap_t
*plain_map
;
186 const global_keymap_t
*hex_map
;
188 /* handle of search engine */
190 gchar
*last_search_string
;
191 struct mcview_nroff_struct
*search_nroff_seq
;
193 int search_numNeedSkipChar
;
196 typedef struct mcview_nroff_struct
203 nroff_type_t prev_type
;
206 typedef struct mcview_search_options_t
208 mc_search_type_t type
;
211 gboolean whole_words
;
212 gboolean all_codepages
;
213 } mcview_search_options_t
;
215 /*** global variables defined in .c file *******************************/
217 extern mcview_search_options_t mcview_search_options
;
219 /*** declarations of public functions **********************************/
222 cb_ret_t
mcview_callback (Widget
* w
, widget_msg_t msg
, int parm
);
223 cb_ret_t
mcview_dialog_callback (Dlg_head
* h
, Widget
* sender
,
224 dlg_msg_t msg
, int parm
, void *data
);
227 coord_cache_t
*coord_cache_new (void);
228 void coord_cache_free (coord_cache_t
* cache
);
230 #ifdef MC_ENABLE_DEBUGGING_CODE
231 void mcview_ccache_dump (mcview_t
* view
);
234 void mcview_ccache_lookup (mcview_t
* view
, coord_cache_entry_t
* coord
,
235 enum ccache_type lookup_what
);
238 void mcview_set_datasource_none (mcview_t
*);
239 off_t
mcview_get_filesize (mcview_t
*);
240 void mcview_update_filesize (mcview_t
* view
);
241 char *mcview_get_ptr_file (mcview_t
*, off_t
);
242 char *mcview_get_ptr_string (mcview_t
*, off_t
);
243 int mcview_get_utf (mcview_t
*, off_t
, int *, gboolean
*);
244 gboolean
mcview_get_byte_string (mcview_t
*, off_t
, int *);
245 gboolean
mcview_get_byte_none (mcview_t
*, off_t
, int *);
246 void mcview_set_byte (mcview_t
*, off_t
, byte
);
247 void mcview_file_load_data (mcview_t
*, off_t
);
248 void mcview_close_datasource (mcview_t
*);
249 void mcview_set_datasource_file (mcview_t
*, int, const struct stat
*);
250 gboolean
mcview_load_command_output (mcview_t
*, const char *);
251 void mcview_set_datasource_vfs_pipe (mcview_t
*, int);
252 void mcview_set_datasource_string (mcview_t
*, const char *);
255 gboolean
mcview_dialog_search (mcview_t
* view
);
256 gboolean
mcview_dialog_goto (mcview_t
* view
, off_t
* offset
);
259 void mcview_update (mcview_t
* view
);
260 void mcview_display (mcview_t
* view
);
261 void mcview_compute_areas (mcview_t
* view
);
262 void mcview_update_bytes_per_line (mcview_t
* view
);
263 void mcview_display_toggle_ruler (mcview_t
* view
);
264 void mcview_display_clean (mcview_t
* view
);
265 void mcview_display_ruler (mcview_t
* view
);
266 void mcview_percent (mcview_t
* view
, off_t p
);
269 void mcview_growbuf_init (mcview_t
* view
);
270 void mcview_growbuf_free (mcview_t
* view
);
271 off_t
mcview_growbuf_filesize (mcview_t
* view
);
272 void mcview_growbuf_read_until (mcview_t
* view
, off_t p
);
273 gboolean
mcview_get_byte_growing_buffer (mcview_t
* view
, off_t p
, int *);
274 char *mcview_get_ptr_growing_buffer (mcview_t
* view
, off_t p
);
277 void mcview_display_hex (mcview_t
* view
);
278 gboolean
mcview_hexedit_save_changes (mcview_t
* view
);
279 void mcview_toggle_hexedit_mode (mcview_t
* view
);
280 void mcview_hexedit_free_change_list (mcview_t
* view
);
281 void mcview_enqueue_change (struct hexedit_change_node
**, struct hexedit_change_node
*);
284 void mcview_toggle_magic_mode (mcview_t
* view
);
285 void mcview_toggle_wrap_mode (mcview_t
* view
);
286 void mcview_toggle_nroff_mode (mcview_t
* view
);
287 void mcview_toggle_hex_mode (mcview_t
* view
);
288 gboolean
mcview_ok_to_quit (mcview_t
* view
);
289 void mcview_done (mcview_t
* view
);
290 void mcview_select_encoding (mcview_t
* view
);
291 void mcview_set_codeset (mcview_t
* view
);
292 void mcview_show_error (mcview_t
* view
, const char *error
);
293 off_t
mcview_bol (mcview_t
* view
, off_t current
);
294 off_t
mcview_eol (mcview_t
* view
, off_t current
);
297 void mcview_move_up (mcview_t
*, off_t
);
298 void mcview_move_down (mcview_t
*, off_t
);
299 void mcview_move_left (mcview_t
*, off_t
);
300 void mcview_move_right (mcview_t
*, off_t
);
301 void mcview_scroll_to_cursor (mcview_t
*);
302 void mcview_moveto_top (mcview_t
*);
303 void mcview_moveto_bottom (mcview_t
*);
304 void mcview_moveto_bol (mcview_t
*);
305 void mcview_moveto_eol (mcview_t
*);
306 void mcview_moveto_offset (mcview_t
*, off_t
);
307 void mcview_moveto (mcview_t
*, off_t
, off_t
);
308 void mcview_coord_to_offset (mcview_t
*, off_t
*, off_t
, off_t
);
309 void mcview_offset_to_coord (mcview_t
*, off_t
*, off_t
*, off_t
);
310 void mcview_place_cursor (mcview_t
*);
311 void mcview_moveto_match (mcview_t
*);
314 void mcview_display_nroff (mcview_t
* view
);
315 int mcview__get_nroff_real_len (mcview_t
* view
, off_t
, off_t p
);
317 mcview_nroff_t
*mcview_nroff_seq_new_num (mcview_t
* view
, off_t p
);
318 mcview_nroff_t
*mcview_nroff_seq_new (mcview_t
* view
);
319 void mcview_nroff_seq_free (mcview_nroff_t
**);
320 nroff_type_t
mcview_nroff_seq_info (mcview_nroff_t
*);
321 int mcview_nroff_seq_next (mcview_nroff_t
*);
324 void mcview_display_text (mcview_t
*);
327 int mcview_search_cmd_callback (const void *user_data
, gsize char_offset
);
328 int mcview_search_update_cmd_callback (const void *, gsize
);
329 void mcview_do_search (mcview_t
* view
);
332 /*** inline functions ****************************************************************************/
336 #endif /* MC_VIEWER_INTERNAL_H */