1 #ifndef MC__VIEWER_INTERNAL_H
2 #define MC__VIEWER_INTERNAL_H
8 #include "lib/global.h"
10 #include "lib/search.h"
11 #include "lib/widget.h"
12 #include "lib/vfs/vfs.h" /* vfs_path_t */
14 #include "src/keybind-defaults.h" /* global_keymap_t */
15 #include "src/filemanager/dir.h" /* dir_list */
19 /*** typedefs(not structures) and defined constants **********************************************/
21 typedef unsigned char byte
;
23 /* A width or height on the screen */
24 typedef unsigned int screen_dimen
;
26 extern const off_t OFFSETTYPE_MAX
;
28 /*** enums ***************************************************************************************/
30 /* data sources of the view */
33 DS_NONE
, /* No data available */
34 DS_STDIO_PIPE
, /* Data comes from a pipe using popen/pclose */
35 DS_VFS_PIPE
, /* Data comes from a piped-in VFS file */
36 DS_FILE
, /* Data comes from a VFS file */
37 DS_STRING
/* Data comes from a string in memory */
50 NROFF_TYPE_UNDERLINE
= 2
53 /*** structures declarations (and typedefs of structures)*****************************************/
55 /* A node for building a change list on change_list */
56 struct hexedit_change_node
58 struct hexedit_change_node
*next
;
65 screen_dimen top
, left
;
66 screen_dimen height
, width
;
69 /* A cache entry for mapping offsets into line/column pairs and vice versa.
70 * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
71 * line and column of that cache entry. cc_nroff_column is the column
72 * corresponding to cc_offset in nroff mode.
79 off_t cc_nroff_column
;
80 } coord_cache_entry_t
;
86 coord_cache_entry_t
**cache
;
89 /* TODO: find a better name. This is not actually a "state machine",
90 * but a "state machine's state", but that sounds silly.
91 * Could be parser_state, formatter_state... */
94 off_t offset
; /* The file offset at which this is the state. */
95 off_t unwrapped_column
; /* Columns if the paragraph wasn't wrapped, */
96 /* used for positioning TABs in wrapped lines */
97 gboolean nroff_underscore_is_underlined
; /* whether _\b_ is underlined rather than bold */
98 gboolean print_lonely_combining
; /* whether lonely combining marks are printed on a dotted circle */
99 } mcview_state_machine_t
;
101 struct mcview_nroff_struct
;
107 vfs_path_t
*filename_vpath
; /* Name of the file */
108 vfs_path_t
*workdir_vpath
; /* Name of the working directory */
109 char *command
; /* Command used to pipe data in */
111 enum view_ds datasource
; /* Where the displayed data comes from */
113 /* stdio pipe data source */
114 mc_pipe_t
*ds_stdio_pipe
; /* Output of a shell command */
115 gboolean pipe_first_err_msg
; /* Show only 1st message from stderr */
117 /* vfs pipe data source */
118 int ds_vfs_pipe
; /* Non-seekable vfs file descriptor */
120 /* vfs file data source */
121 int ds_file_fd
; /* File with random access */
122 off_t ds_file_filesize
; /* Size of the file */
123 off_t ds_file_offset
; /* Offset of the currently loaded data */
124 byte
*ds_file_data
; /* Currently loaded data */
125 size_t ds_file_datalen
; /* Number of valid bytes in file_data */
126 size_t ds_file_datasize
; /* Number of allocated bytes in file_data */
128 /* string data source */
129 byte
*ds_string_data
; /* The characters of the string */
130 size_t ds_string_len
; /* The length of the string */
132 /* Growing buffers information */
133 gboolean growbuf_in_use
; /* Use the growing buffers? */
134 GPtrArray
*growbuf_blockptr
; /* Pointer to the block pointers */
135 size_t growbuf_lastindex
; /* Number of bytes in the last page of the
137 gboolean growbuf_finished
; /* TRUE when all data has been read. */
140 gboolean hex_mode
; /* Hexview or Hexedit */
141 gboolean hexedit_mode
; /* Hexedit */
142 gboolean hexview_in_text
; /* Is the hexview cursor in the text area? */
143 gboolean text_nroff_mode
; /* Nroff-style highlighting */
144 gboolean text_wrap_mode
; /* Wrap text lines to fit them on the screen */
145 gboolean magic_mode
; /* Preprocess the file using external programs */
146 gboolean hexedit_lownibble
; /* Are we editing the last significant nibble? */
147 gboolean locked
; /* We hold lock on current file */
150 gboolean utf8
; /* It's multibyte file codeset */
153 coord_cache_t
*coord_cache
; /* Cache for mapping offsets to cursor positions */
155 /* Display information */
156 gboolean active
; /* Active or not in QuickView mode */
157 screen_dimen dpy_frame_size
; /* Size of the frame surrounding the real viewer */
158 off_t dpy_start
; /* Offset of the displayed data (start of the paragraph in non-hex mode) */
159 off_t dpy_end
; /* Offset after the displayed data */
160 off_t dpy_paragraph_skip_lines
; /* Extra lines to skip in wrap mode */
161 mcview_state_machine_t dpy_state_top
; /* Parser-formatter state at the topmost visible line in wrap mode */
162 mcview_state_machine_t dpy_state_bottom
; /* Parser-formatter state after the bottomvisible line in wrap mode */
163 gboolean dpy_wrap_dirty
; /* dpy_state_top needs to be recomputed */
164 off_t dpy_text_column
; /* Number of skipped columns in non-wrap
166 off_t hex_cursor
; /* Hexview cursor position in file */
167 screen_dimen cursor_col
; /* Cursor column */
168 screen_dimen cursor_row
; /* Cursor row */
169 struct hexedit_change_node
*change_list
; /* Linked list of changes */
170 struct area status_area
; /* Where the status line is displayed */
171 struct area ruler_area
; /* Where the ruler is displayed */
172 struct area data_area
; /* Where the data is displayed */
174 ssize_t force_max
; /* Force a max offset, or -1 */
176 int dirty
; /* Number of skipped updates */
177 gboolean dpy_bbar_dirty
; /* Does the button bar need to be updated? */
180 int bytes_per_line
; /* Number of bytes per line in hex mode */
182 /* Search variables */
183 off_t search_start
; /* First character to start searching from */
184 off_t search_end
; /* Length of found string or 0 if none was found */
187 int marker
; /* mark to use */
188 off_t marks
[10]; /* 10 marks: 0..9 */
190 off_t update_steps
; /* The number of bytes between percent
192 off_t update_activate
; /* Last point where we updated the status */
194 /* converter for translation of text */
197 /* handle of search engine */
199 gchar
*last_search_string
;
200 struct mcview_nroff_struct
*search_nroff_seq
;
202 int search_numNeedSkipChar
;
204 GArray
*saved_bookmarks
;
206 dir_list
*dir
; /* List of current directory files
207 * to handle CK_FileNext and CK_FilePrev commands */
208 int *dir_idx
; /* Index of current file in dir structure.
209 * Pointer is used here as reference to WPanel::dir::count */
210 vfs_path_t
*ext_script
; /* Temporary script file created by regex_command_for() */
213 typedef struct mcview_nroff_struct
220 nroff_type_t prev_type
;
223 typedef struct mcview_search_options_t
225 mc_search_type_t type
;
228 gboolean whole_words
;
229 gboolean all_codepages
;
230 } mcview_search_options_t
;
232 /*** global variables defined in .c file *********************************************************/
234 extern mcview_search_options_t mcview_search_options
;
236 /*** declarations of public functions ************************************************************/
239 cb_ret_t
mcview_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
);
240 cb_ret_t
mcview_dialog_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
,
244 void mcview_display_text (WView
*);
245 void mcview_state_machine_init (mcview_state_machine_t
*, off_t
);
246 void mcview_ascii_move_down (WView
*, off_t
);
247 void mcview_ascii_move_up (WView
*, off_t
);
248 void mcview_ascii_moveto_bol (WView
*);
249 void mcview_ascii_moveto_eol (WView
*);
252 coord_cache_t
*coord_cache_new (void);
253 void coord_cache_free (coord_cache_t
* cache
);
255 #ifdef MC_ENABLE_DEBUGGING_CODE
256 void mcview_ccache_dump (WView
* view
);
259 void mcview_ccache_lookup (WView
* view
, coord_cache_entry_t
* coord
, enum ccache_type lookup_what
);
262 void mcview_set_datasource_none (WView
*);
263 off_t
mcview_get_filesize (WView
*);
264 void mcview_update_filesize (WView
* view
);
265 char *mcview_get_ptr_file (WView
*, off_t
);
266 char *mcview_get_ptr_string (WView
*, off_t
);
267 gboolean
mcview_get_utf (WView
* view
, off_t byte_index
, int *ch
, int *ch_len
);
268 gboolean
mcview_get_byte_string (WView
*, off_t
, int *);
269 gboolean
mcview_get_byte_none (WView
*, off_t
, int *);
270 void mcview_set_byte (WView
*, off_t
, byte
);
271 void mcview_file_load_data (WView
*, off_t
);
272 void mcview_close_datasource (WView
*);
273 void mcview_set_datasource_file (WView
*, int, const struct stat
*);
274 gboolean
mcview_load_command_output (WView
*, const char *);
275 void mcview_set_datasource_vfs_pipe (WView
*, int);
276 void mcview_set_datasource_string (WView
*, const char *);
279 gboolean
mcview_dialog_search (WView
* view
);
280 gboolean
mcview_dialog_goto (WView
* view
, off_t
* offset
);
283 void mcview_update (WView
* view
);
284 void mcview_display (WView
* view
);
285 void mcview_compute_areas (WView
* view
);
286 void mcview_update_bytes_per_line (WView
* view
);
287 void mcview_display_toggle_ruler (WView
* view
);
288 void mcview_display_clean (WView
* view
);
289 void mcview_display_ruler (WView
* view
);
292 void mcview_growbuf_init (WView
* view
);
293 void mcview_growbuf_done (WView
* view
);
294 void mcview_growbuf_free (WView
* view
);
295 off_t
mcview_growbuf_filesize (WView
* view
);
296 void mcview_growbuf_read_until (WView
* view
, off_t p
);
297 gboolean
mcview_get_byte_growing_buffer (WView
* view
, off_t p
, int *);
298 char *mcview_get_ptr_growing_buffer (WView
* view
, off_t p
);
301 void mcview_display_hex (WView
* view
);
302 gboolean
mcview_hexedit_save_changes (WView
* view
);
303 void mcview_toggle_hexedit_mode (WView
* view
);
304 void mcview_hexedit_free_change_list (WView
* view
);
305 void mcview_enqueue_change (struct hexedit_change_node
**, struct hexedit_change_node
*);
308 void mcview_toggle_magic_mode (WView
* view
);
309 void mcview_toggle_wrap_mode (WView
* view
);
310 void mcview_toggle_nroff_mode (WView
* view
);
311 void mcview_toggle_hex_mode (WView
* view
);
312 void mcview_init (WView
* view
);
313 void mcview_done (WView
* view
);
314 void mcview_select_encoding (WView
* view
);
315 void mcview_set_codeset (WView
* view
);
316 void mcview_show_error (WView
* view
, const char *error
);
317 off_t
mcview_bol (WView
* view
, off_t current
, off_t limit
);
318 off_t
mcview_eol (WView
* view
, off_t current
, off_t limit
);
319 char *mcview_get_title (const WDialog
* h
, size_t len
);
320 int mcview_calc_percent (WView
* view
, off_t p
);
323 void mcview_move_up (WView
*, off_t
);
324 void mcview_move_down (WView
*, off_t
);
325 void mcview_move_left (WView
*, off_t
);
326 void mcview_move_right (WView
*, off_t
);
327 void mcview_moveto_top (WView
*);
328 void mcview_moveto_bottom (WView
*);
329 void mcview_moveto_bol (WView
*);
330 void mcview_moveto_eol (WView
*);
331 void mcview_moveto_offset (WView
*, off_t
);
332 void mcview_moveto (WView
*, off_t
, off_t
);
333 void mcview_coord_to_offset (WView
*, off_t
*, off_t
, off_t
);
334 void mcview_offset_to_coord (WView
*, off_t
*, off_t
*, off_t
);
335 void mcview_place_cursor (WView
*);
336 void mcview_moveto_match (WView
*);
339 int mcview__get_nroff_real_len (WView
* view
, off_t
, off_t p
);
340 mcview_nroff_t
*mcview_nroff_seq_new_num (WView
* view
, off_t p
);
341 mcview_nroff_t
*mcview_nroff_seq_new (WView
* view
);
342 void mcview_nroff_seq_free (mcview_nroff_t
**);
343 nroff_type_t
mcview_nroff_seq_info (mcview_nroff_t
*);
344 int mcview_nroff_seq_next (mcview_nroff_t
*);
345 int mcview_nroff_seq_prev (mcview_nroff_t
*);
348 mc_search_cbret_t
mcview_search_cmd_callback (const void *user_data
, gsize char_offset
,
350 mc_search_cbret_t
mcview_search_update_cmd_callback (const void *user_data
, gsize char_offset
);
351 void mcview_do_search (WView
* view
, off_t want_search_start
);
353 /*** inline functions ****************************************************************************/
357 #endif /* MC__VIEWER_INTERNAL_H */