x86_64: Cleanup of code for master
[midnight-commander.git] / src / viewer / internal.h
blob4d75366518084c660a3456198493998d97272654
2 #ifndef MC_VIEWER_INTERNAL_H
3 #define MC_VIEWER_INTERNAL_H
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <sys/types.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 */
33 enum view_ds {
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 */
41 enum ccache_type {
42 CCACHE_OFFSET,
43 CCACHE_LINECOL
46 typedef enum {
47 NROFF_TYPE_NONE = 0,
48 NROFF_TYPE_BOLD = 1,
49 NROFF_TYPE_UNDERLINE = 2
50 } nroff_type_t;
52 /*** structures declarations (and typedefs of structures)***************/
54 /* A node for building a change list on change_list */
55 struct hexedit_change_node {
56 struct hexedit_change_node *next;
57 off_t offset;
58 byte value;
61 struct area {
62 screen_dimen top, left;
63 screen_dimen height, width;
66 /* A cache entry for mapping offsets into line/column pairs and vice versa.
67 * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
68 * line and column of that cache entry. cc_nroff_column is the column
69 * corresponding to cc_offset in nroff mode.
71 typedef struct {
72 off_t cc_offset;
73 off_t cc_line;
74 off_t cc_column;
75 off_t cc_nroff_column;
76 } coord_cache_entry_t;
78 typedef struct {
79 size_t size;
80 size_t capacity;
81 coord_cache_entry_t **cache;
82 } coord_cache_t;
84 struct mcview_nroff_struct;
86 typedef struct mcview_struct {
87 Widget widget;
89 char *filename; /* Name of the file */
90 char *command; /* Command used to pipe data in */
92 enum view_ds datasource; /* Where the displayed data comes from */
94 /* stdio pipe data source */
95 FILE *ds_stdio_pipe; /* Output of a shell command */
97 /* vfs pipe data source */
98 int ds_vfs_pipe; /* Non-seekable vfs file descriptor */
100 /* vfs file data source */
101 int ds_file_fd; /* File with random access */
102 off_t ds_file_filesize; /* Size of the file */
103 off_t ds_file_offset; /* Offset of the currently loaded data */
104 byte *ds_file_data; /* Currently loaded data */
105 size_t ds_file_datalen; /* Number of valid bytes in file_data */
106 size_t ds_file_datasize; /* Number of allocated bytes in file_data */
108 /* string data source */
109 byte *ds_string_data; /* The characters of the string */
110 size_t ds_string_len; /* The length of the string */
112 /* Growing buffers information */
113 gboolean growbuf_in_use; /* Use the growing buffers? */
114 GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */
115 size_t growbuf_lastindex; /* Number of bytes in the last page of the
116 growing buffer */
117 gboolean growbuf_finished; /* TRUE when all data has been read. */
119 /* Editor modes */
120 gboolean hex_mode; /* Hexview or Hexedit */
121 gboolean hexedit_mode; /* Hexedit */
122 gboolean hexview_in_text; /* Is the hexview cursor in the text area? */
123 gboolean text_nroff_mode; /* Nroff-style highlighting */
124 gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */
125 gboolean magic_mode; /* Preprocess the file using external programs */
126 gboolean utf8; /* It's multibyte file codeset */
128 /* Additional editor state */
129 gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
130 coord_cache_t *coord_cache; /* Cache for mapping offsets to cursor positions */
132 /* Display information */
133 screen_dimen dpy_frame_size; /* Size of the frame surrounding the real viewer */
134 off_t dpy_start; /* Offset of the displayed data */
135 off_t dpy_end; /* Offset after the displayed data */
136 off_t dpy_text_column; /* Number of skipped columns in non-wrap
137 * text mode */
138 off_t hex_cursor; /* Hexview cursor position in file */
139 screen_dimen cursor_col; /* Cursor column */
140 screen_dimen cursor_row; /* Cursor row */
141 struct hexedit_change_node *change_list; /* Linked list of changes */
142 struct area status_area; /* Where the status line is displayed */
143 struct area ruler_area; /* Where the ruler is displayed */
144 struct area data_area; /* Where the data is displayed */
146 int dirty; /* Number of skipped updates */
147 gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */
149 /* Mode variables */
150 int bytes_per_line; /* Number of bytes per line in hex mode */
152 /* Search variables */
153 off_t search_start; /* First character to start searching from */
154 off_t search_end; /* Length of found string or 0 if none was found */
156 /* Pointer to the last search command */
157 gboolean want_to_quit; /* Prepare for cleanup ... */
159 /* Markers */
160 int marker; /* mark to use */
161 off_t marks[10]; /* 10 marks: 0..9 */
163 int move_dir; /* return value from widget:
164 * 0 do nothing
165 * -1 view previous file
166 * 1 view next file
169 off_t update_steps; /* The number of bytes between percent
170 * increments */
171 off_t update_activate; /* Last point where we updated the status */
173 /* converter for translation of text */
174 GIConv converter;
176 /* keymaps */
177 const global_keymap_t *plain_map;
178 const global_keymap_t *hex_map;
180 /* handle of search engine */
181 mc_search_t *search;
182 gchar *last_search_string;
183 struct mcview_nroff_struct *search_nroff_seq;
185 int search_numNeedSkipChar;
186 } mcview_t;
188 typedef struct mcview_nroff_struct {
189 mcview_t *view;
190 off_t index;
191 int char_width;
192 int current_char;
193 nroff_type_t type;
194 nroff_type_t prev_type;
195 } mcview_nroff_t;
197 typedef struct mcview_search_options_t {
198 mc_search_type_t type;
199 gboolean case_sens;
200 gboolean backwards;
201 gboolean whole_words;
202 gboolean all_codepages;
203 } mcview_search_options_t;
205 /*** global variables defined in .c file *******************************/
207 extern mcview_search_options_t mcview_search_options;
209 /*** declarations of public functions **********************************/
211 /* actions_cmd.c: */
212 cb_ret_t mcview_callback (Widget *w, widget_msg_t msg, int parm);
213 cb_ret_t mcview_dialog_callback (Dlg_head *h, Widget *sender,
214 dlg_msg_t msg, int parm, void *data);
216 /* coord_cache.c: */
217 coord_cache_t *coord_cache_new (void);
218 void coord_cache_free (coord_cache_t *cache);
220 #ifdef MC_ENABLE_DEBUGGING_CODE
221 void mcview_ccache_dump (mcview_t *view);
222 #endif
224 void mcview_ccache_lookup (mcview_t *view, coord_cache_entry_t *coord,
225 enum ccache_type lookup_what);
227 /* datasource.c: */
228 void mcview_set_datasource_none (mcview_t *);
229 off_t mcview_get_filesize (mcview_t *);
230 void mcview_update_filesize (mcview_t * view);
231 char *mcview_get_ptr_file (mcview_t *, off_t);
232 char *mcview_get_ptr_string (mcview_t *, off_t);
233 int mcview_get_utf (mcview_t *, off_t, int *, gboolean *);
234 gboolean mcview_get_byte_string (mcview_t *, off_t, int *);
235 gboolean mcview_get_byte_none (mcview_t *, off_t, int *);
236 void mcview_set_byte (mcview_t *, off_t, byte);
237 void mcview_file_load_data (mcview_t *, off_t);
238 void mcview_close_datasource (mcview_t *);
239 void mcview_set_datasource_file (mcview_t *, int, const struct stat *);
240 gboolean mcview_load_command_output (mcview_t *, const char *);
241 void mcview_set_datasource_vfs_pipe (mcview_t *, int);
242 void mcview_set_datasource_string (mcview_t *, const char *);
244 /* dialog.c: */
245 gboolean mcview_dialog_search (mcview_t *view);
246 gboolean mcview_dialog_goto (mcview_t *view, off_t *offset);
248 /* display.c: */
249 void mcview_update (mcview_t *view);
250 void mcview_display (mcview_t *view);
251 void mcview_compute_areas (mcview_t *view);
252 void mcview_update_bytes_per_line (mcview_t *view);
253 void mcview_display_toggle_ruler (mcview_t *view);
254 void mcview_display_clean (mcview_t *view);
255 void mcview_display_ruler (mcview_t *view);
256 void mcview_percent (mcview_t *view, off_t p);
258 /* growbuf.c: */
259 void mcview_growbuf_init (mcview_t *view);
260 void mcview_growbuf_free (mcview_t *view);
261 off_t mcview_growbuf_filesize (mcview_t *view);
262 void mcview_growbuf_read_until (mcview_t *view, off_t p);
263 gboolean mcview_get_byte_growing_buffer (mcview_t *view, off_t p, int *);
264 char *mcview_get_ptr_growing_buffer (mcview_t *view, off_t p);
266 /* hex.c: */
267 void mcview_display_hex (mcview_t *view);
268 gboolean mcview_hexedit_save_changes (mcview_t *view);
269 void mcview_toggle_hexedit_mode (mcview_t *view);
270 void mcview_hexedit_free_change_list (mcview_t *view);
271 void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
273 /* lib.c: */
274 void mcview_toggle_magic_mode (mcview_t *view);
275 void mcview_toggle_wrap_mode (mcview_t *view);
276 void mcview_toggle_nroff_mode (mcview_t *view);
277 void mcview_toggle_hex_mode (mcview_t *view);
278 gboolean mcview_ok_to_quit (mcview_t *view);
279 void mcview_done (mcview_t *view);
280 void mcview_select_encoding (mcview_t *view);
281 void mcview_set_codeset (mcview_t *view);
282 void mcview_show_error (mcview_t *view, const char *error);
283 off_t mcview_bol (mcview_t *view, off_t current);
284 off_t mcview_eol (mcview_t *view, off_t current);
286 /* move.c */
287 void mcview_move_up (mcview_t *, off_t);
288 void mcview_move_down (mcview_t *, off_t);
289 void mcview_move_left (mcview_t *, off_t);
290 void mcview_move_right (mcview_t *, off_t);
291 void mcview_scroll_to_cursor (mcview_t *);
292 void mcview_moveto_top (mcview_t *);
293 void mcview_moveto_bottom (mcview_t *);
294 void mcview_moveto_bol (mcview_t *);
295 void mcview_moveto_eol (mcview_t *);
296 void mcview_moveto_offset (mcview_t *, off_t);
297 void mcview_moveto (mcview_t *, off_t, off_t);
298 void mcview_coord_to_offset (mcview_t *, off_t *, off_t, off_t);
299 void mcview_offset_to_coord (mcview_t *, off_t *, off_t *, off_t);
300 void mcview_place_cursor (mcview_t *);
301 void mcview_moveto_match (mcview_t *);
303 /* nroff.c: */
304 void mcview_display_nroff (mcview_t *view);
305 int mcview__get_nroff_real_len (mcview_t *view, off_t, off_t p);
307 mcview_nroff_t *mcview_nroff_seq_new_num (mcview_t *view, off_t p);
308 mcview_nroff_t *mcview_nroff_seq_new (mcview_t * view);
309 void mcview_nroff_seq_free (mcview_nroff_t **);
310 nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
311 int mcview_nroff_seq_next (mcview_nroff_t *);
313 /* plain.c: */
314 void mcview_display_text (mcview_t *);
316 /* search.c: */
317 int mcview_search_cmd_callback (const void *user_data, gsize char_offset);
318 int mcview_search_update_cmd_callback (const void *, gsize);
319 void mcview_do_search (mcview_t *view);
322 /*** inline functions ****************************************************************************/
324 #include "inlines.h"
326 #endif /* MC_VIEWER_INTERNAL_H */