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 INVALID_OFFSET
;
27 extern const off_t OFFSETTYPE_MAX
;
29 /*** enums ***************************************************************************************/
31 /* data sources of the view */
34 DS_NONE
, /* No data available */
35 DS_STDIO_PIPE
, /* Data comes from a pipe using popen/pclose */
36 DS_VFS_PIPE
, /* Data comes from a piped-in VFS file */
37 DS_FILE
, /* Data comes from a VFS file */
38 DS_STRING
/* Data comes from a string in memory */
51 NROFF_TYPE_UNDERLINE
= 2
54 /*** structures declarations (and typedefs of structures)*****************************************/
56 /* A node for building a change list on change_list */
57 struct hexedit_change_node
59 struct hexedit_change_node
*next
;
66 screen_dimen top
, left
;
67 screen_dimen height
, width
;
70 /* A cache entry for mapping offsets into line/column pairs and vice versa.
71 * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
72 * line and column of that cache entry. cc_nroff_column is the column
73 * corresponding to cc_offset in nroff mode.
80 off_t cc_nroff_column
;
81 } coord_cache_entry_t
;
87 coord_cache_entry_t
**cache
;
90 /* TODO: find a better name. This is not actually a "state machine",
91 * but a "state machine's state", but that sounds silly.
92 * Could be parser_state, formatter_state... */
95 off_t offset
; /* The file offset at which this is the state. */
96 off_t unwrapped_column
; /* Columns if the paragraph wasn't wrapped, */
97 /* used for positioning TABs in wrapped lines */
98 gboolean nroff_underscore_is_underlined
; /* whether _\b_ is underlined rather than bold */
99 gboolean print_lonely_combining
; /* whether lonely combining marks are printed on a dotted circle */
100 } mcview_state_machine_t
;
102 struct mcview_nroff_struct
;
108 vfs_path_t
*filename_vpath
; /* Name of the file */
109 vfs_path_t
*workdir_vpath
; /* Name of the working directory */
110 char *command
; /* Command used to pipe data in */
112 enum view_ds datasource
; /* Where the displayed data comes from */
114 /* stdio pipe data source */
115 mc_pipe_t
*ds_stdio_pipe
; /* Output of a shell command */
116 gboolean pipe_first_err_msg
; /* Show only 1st message from stderr */
118 /* vfs pipe data source */
119 int ds_vfs_pipe
; /* Non-seekable vfs file descriptor */
121 /* vfs file data source */
122 int ds_file_fd
; /* File with random access */
123 off_t ds_file_filesize
; /* Size of the file */
124 off_t ds_file_offset
; /* Offset of the currently loaded data */
125 byte
*ds_file_data
; /* Currently loaded data */
126 size_t ds_file_datalen
; /* Number of valid bytes in file_data */
127 size_t ds_file_datasize
; /* Number of allocated bytes in file_data */
129 /* string data source */
130 byte
*ds_string_data
; /* The characters of the string */
131 size_t ds_string_len
; /* The length of the string */
133 /* Growing buffers information */
134 gboolean growbuf_in_use
; /* Use the growing buffers? */
135 GPtrArray
*growbuf_blockptr
; /* Pointer to the block pointers */
136 size_t growbuf_lastindex
; /* Number of bytes in the last page of the
138 gboolean growbuf_finished
; /* TRUE when all data has been read. */
141 gboolean hex_mode
; /* Hexview or Hexedit */
142 gboolean hexedit_mode
; /* Hexedit */
143 gboolean hexview_in_text
; /* Is the hexview cursor in the text area? */
144 gboolean text_nroff_mode
; /* Nroff-style highlighting */
145 gboolean text_wrap_mode
; /* Wrap text lines to fit them on the screen */
146 gboolean magic_mode
; /* Preprocess the file using external programs */
147 gboolean hexedit_lownibble
; /* Are we editing the last significant nibble? */
148 gboolean locked
; /* We hold lock on current file */
151 gboolean utf8
; /* It's multibyte file codeset */
154 coord_cache_t
*coord_cache
; /* Cache for mapping offsets to cursor positions */
156 /* Display information */
157 gboolean active
; /* Active or not in QuickView mode */
158 screen_dimen dpy_frame_size
; /* Size of the frame surrounding the real viewer */
159 off_t dpy_start
; /* Offset of the displayed data (start of the paragraph in non-hex mode) */
160 off_t dpy_end
; /* Offset after the displayed data */
161 off_t dpy_paragraph_skip_lines
; /* Extra lines to skip in wrap mode */
162 mcview_state_machine_t dpy_state_top
; /* Parser-formatter state at the topmost visible line in wrap mode */
163 mcview_state_machine_t dpy_state_bottom
; /* Parser-formatter state after the bottomvisible line in wrap mode */
164 gboolean dpy_wrap_dirty
; /* dpy_state_top needs to be recomputed */
165 off_t dpy_text_column
; /* Number of skipped columns in non-wrap
167 off_t hex_cursor
; /* Hexview cursor position in file */
168 screen_dimen cursor_col
; /* Cursor column */
169 screen_dimen cursor_row
; /* Cursor row */
170 struct hexedit_change_node
*change_list
; /* Linked list of changes */
171 struct area status_area
; /* Where the status line is displayed */
172 struct area ruler_area
; /* Where the ruler is displayed */
173 struct area data_area
; /* Where the data is displayed */
175 ssize_t force_max
; /* Force a max offset, or -1 */
177 int dirty
; /* Number of skipped updates */
178 gboolean dpy_bbar_dirty
; /* Does the button bar need to be updated? */
181 int bytes_per_line
; /* Number of bytes per line in hex mode */
183 /* Search variables */
184 off_t search_start
; /* First character to start searching from */
185 off_t search_end
; /* Length of found string or 0 if none was found */
188 int marker
; /* mark to use */
189 off_t marks
[10]; /* 10 marks: 0..9 */
191 off_t update_steps
; /* The number of bytes between percent
193 off_t update_activate
; /* Last point where we updated the status */
195 /* converter for translation of text */
198 /* handle of search engine */
200 gchar
*last_search_string
;
201 struct mcview_nroff_struct
*search_nroff_seq
;
203 int search_numNeedSkipChar
;
205 GArray
*saved_bookmarks
;
207 dir_list
*dir
; /* List of current directory files
208 * to handle CK_FileNext and CK_FilePrev commands */
209 int *dir_idx
; /* Index of current file in dir structure.
210 * Pointer is used here as reference to WPanel::dir::count */
211 vfs_path_t
*ext_script
; /* Temporary script file created by regex_command_for() */
214 typedef struct mcview_nroff_struct
221 nroff_type_t prev_type
;
224 typedef struct mcview_search_options_t
226 mc_search_type_t type
;
229 gboolean whole_words
;
230 gboolean all_codepages
;
231 } mcview_search_options_t
;
233 /*** global variables defined in .c file *********************************************************/
235 extern mcview_search_options_t mcview_search_options
;
237 /*** declarations of public functions ************************************************************/
240 cb_ret_t
mcview_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
);
241 cb_ret_t
mcview_dialog_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
,
245 void mcview_display_text (mcview_t
*);
246 void mcview_state_machine_init (mcview_state_machine_t
*, off_t
);
247 void mcview_ascii_move_down (mcview_t
*, off_t
);
248 void mcview_ascii_move_up (mcview_t
*, off_t
);
249 void mcview_ascii_moveto_bol (mcview_t
*);
250 void mcview_ascii_moveto_eol (mcview_t
*);
253 coord_cache_t
*coord_cache_new (void);
254 void coord_cache_free (coord_cache_t
* cache
);
256 #ifdef MC_ENABLE_DEBUGGING_CODE
257 void mcview_ccache_dump (mcview_t
* view
);
260 void mcview_ccache_lookup (mcview_t
* view
, coord_cache_entry_t
* coord
,
261 enum ccache_type lookup_what
);
264 void mcview_set_datasource_none (mcview_t
*);
265 off_t
mcview_get_filesize (mcview_t
*);
266 void mcview_update_filesize (mcview_t
* view
);
267 char *mcview_get_ptr_file (mcview_t
*, off_t
);
268 char *mcview_get_ptr_string (mcview_t
*, off_t
);
269 int mcview_get_utf (mcview_t
*, off_t
, int *, gboolean
*);
270 gboolean
mcview_get_byte_string (mcview_t
*, off_t
, int *);
271 gboolean
mcview_get_byte_none (mcview_t
*, off_t
, int *);
272 void mcview_set_byte (mcview_t
*, off_t
, byte
);
273 void mcview_file_load_data (mcview_t
*, off_t
);
274 void mcview_close_datasource (mcview_t
*);
275 void mcview_set_datasource_file (mcview_t
*, int, const struct stat
*);
276 gboolean
mcview_load_command_output (mcview_t
*, const char *);
277 void mcview_set_datasource_vfs_pipe (mcview_t
*, int);
278 void mcview_set_datasource_string (mcview_t
*, const char *);
281 gboolean
mcview_dialog_search (mcview_t
* view
);
282 gboolean
mcview_dialog_goto (mcview_t
* view
, off_t
* offset
);
285 void mcview_update (mcview_t
* view
);
286 void mcview_display (mcview_t
* view
);
287 void mcview_compute_areas (mcview_t
* view
);
288 void mcview_update_bytes_per_line (mcview_t
* view
);
289 void mcview_display_toggle_ruler (mcview_t
* view
);
290 void mcview_display_clean (mcview_t
* view
);
291 void mcview_display_ruler (mcview_t
* view
);
294 void mcview_growbuf_init (mcview_t
* view
);
295 void mcview_growbuf_done (mcview_t
* view
);
296 void mcview_growbuf_free (mcview_t
* view
);
297 off_t
mcview_growbuf_filesize (mcview_t
* view
);
298 void mcview_growbuf_read_until (mcview_t
* view
, off_t p
);
299 gboolean
mcview_get_byte_growing_buffer (mcview_t
* view
, off_t p
, int *);
300 char *mcview_get_ptr_growing_buffer (mcview_t
* view
, off_t p
);
303 void mcview_display_hex (mcview_t
* view
);
304 gboolean
mcview_hexedit_save_changes (mcview_t
* view
);
305 void mcview_toggle_hexedit_mode (mcview_t
* view
);
306 void mcview_hexedit_free_change_list (mcview_t
* view
);
307 void mcview_enqueue_change (struct hexedit_change_node
**, struct hexedit_change_node
*);
310 void mcview_toggle_magic_mode (mcview_t
* view
);
311 void mcview_toggle_wrap_mode (mcview_t
* view
);
312 void mcview_toggle_nroff_mode (mcview_t
* view
);
313 void mcview_toggle_hex_mode (mcview_t
* view
);
314 void mcview_init (mcview_t
* view
);
315 void mcview_done (mcview_t
* view
);
316 void mcview_select_encoding (mcview_t
* view
);
317 void mcview_set_codeset (mcview_t
* view
);
318 void mcview_show_error (mcview_t
* view
, const char *error
);
319 off_t
mcview_bol (mcview_t
* view
, off_t current
, off_t limit
);
320 off_t
mcview_eol (mcview_t
* view
, off_t current
, off_t limit
);
321 char *mcview_get_title (const WDialog
* h
, size_t len
);
322 int mcview_calc_percent (mcview_t
* view
, off_t p
);
325 void mcview_move_up (mcview_t
*, off_t
);
326 void mcview_move_down (mcview_t
*, off_t
);
327 void mcview_move_left (mcview_t
*, off_t
);
328 void mcview_move_right (mcview_t
*, off_t
);
329 void mcview_moveto_top (mcview_t
*);
330 void mcview_moveto_bottom (mcview_t
*);
331 void mcview_moveto_bol (mcview_t
*);
332 void mcview_moveto_eol (mcview_t
*);
333 void mcview_moveto_offset (mcview_t
*, off_t
);
334 void mcview_moveto (mcview_t
*, off_t
, off_t
);
335 void mcview_coord_to_offset (mcview_t
*, off_t
*, off_t
, off_t
);
336 void mcview_offset_to_coord (mcview_t
*, off_t
*, off_t
*, off_t
);
337 void mcview_place_cursor (mcview_t
*);
338 void mcview_moveto_match (mcview_t
*);
341 int mcview__get_nroff_real_len (mcview_t
* view
, off_t
, off_t p
);
342 mcview_nroff_t
*mcview_nroff_seq_new_num (mcview_t
* view
, off_t p
);
343 mcview_nroff_t
*mcview_nroff_seq_new (mcview_t
* view
);
344 void mcview_nroff_seq_free (mcview_nroff_t
**);
345 nroff_type_t
mcview_nroff_seq_info (mcview_nroff_t
*);
346 int mcview_nroff_seq_next (mcview_nroff_t
*);
347 int mcview_nroff_seq_prev (mcview_nroff_t
*);
350 mc_search_cbret_t
mcview_search_cmd_callback (const void *user_data
, gsize char_offset
,
352 mc_search_cbret_t
mcview_search_update_cmd_callback (const void *user_data
, gsize char_offset
);
353 void mcview_do_search (mcview_t
* view
, off_t want_search_start
);
355 /*** inline functions ****************************************************************************/
359 #endif /* MC__VIEWER_INTERNAL_H */