Cleanup of code. Reidentation.
[midnight-commander.git] / src / viewer / internal.h
blob0068d637944e9a3c8e75b7f61deaf3e1d1407b53
1 #ifndef MC_VIEWER_INTERNAL_H
2 #define MC_VIEWER_INTERNAL_H
4 #include "../src/widget.h"
5 #include "../src/search/search.h"
7 /*** typedefs(not structures) and defined constants ********************/
9 typedef unsigned char byte;
11 /* A width or height on the screen */
12 typedef unsigned int screen_dimen;
14 /* Offset in bytes into a file */
15 typedef unsigned long offset_type;
17 #define OFFSETTYPE_PRIX "lX"
18 #define OFFSETTYPE_PRId "lu"
20 /*** enums *************************************************************/
22 /* data sources of the view */
23 enum view_ds {
24 DS_NONE, /* No data available */
25 DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */
26 DS_VFS_PIPE, /* Data comes from a piped-in VFS file */
27 DS_FILE, /* Data comes from a VFS file */
28 DS_STRING /* Data comes from a string in memory */
32 /* Offset in bytes into a file */
33 typedef enum {
34 INVALID_OFFSET = ((off_t) - 1),
35 OFFSETTYPE_MAX = ((off_t) (1 << (sizeof (off_t) * 8 - 1) - 1))
37 mcview_offset_t;
39 enum ccache_type {
40 CCACHE_OFFSET,
41 CCACHE_LINECOL
44 /*** structures declarations (and typedefs of structures)***************/
46 /* A node for building a change list on change_list */
47 struct hexedit_change_node {
48 struct hexedit_change_node *next;
49 off_t offset;
50 byte value;
53 struct area {
54 screen_dimen top, left;
55 screen_dimen height, width;
59 /* A cache entry for mapping offsets into line/column pairs and vice versa.
60 * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
61 * line and column of that cache entry. cc_nroff_column is the column
62 * corresponding to cc_offset in nroff mode.
64 struct coord_cache_entry {
65 off_t cc_offset;
66 off_t cc_line;
67 off_t cc_column;
68 off_t cc_nroff_column;
72 typedef struct mcview_struct {
73 Widget widget;
75 char *filename; /* Name of the file */
76 char *command; /* Command used to pipe data in */
78 enum view_ds datasource; /* Where the displayed data comes from */
80 /* stdio pipe data source */
81 FILE *ds_stdio_pipe; /* Output of a shell command */
83 /* vfs pipe data source */
84 int ds_vfs_pipe; /* Non-seekable vfs file descriptor */
86 /* vfs file data source */
87 int ds_file_fd; /* File with random access */
88 off_t ds_file_filesize; /* Size of the file */
89 off_t ds_file_offset; /* Offset of the currently loaded data */
90 byte *ds_file_data; /* Currently loaded data */
91 size_t ds_file_datalen; /* Number of valid bytes in file_data */
92 size_t ds_file_datasize; /* Number of allocated bytes in file_data */
94 /* string data source */
95 byte *ds_string_data; /* The characters of the string */
96 size_t ds_string_len; /* The length of the string */
98 /* Growing buffers information */
99 gboolean growbuf_in_use; /* Use the growing buffers? */
100 byte **growbuf_blockptr; /* Pointer to the block pointers */
101 size_t growbuf_blocks; /* The number of blocks in *block_ptr */
102 size_t growbuf_lastindex; /* Number of bytes in the last page of the
103 growing buffer */
104 gboolean growbuf_finished; /* TRUE when all data has been read. */
106 /* Editor modes */
107 gboolean hex_mode; /* Hexview or Hexedit */
108 gboolean hexedit_mode; /* Hexedit */
109 gboolean hexview_in_text; /* Is the hexview cursor in the text area? */
110 gboolean text_nroff_mode; /* Nroff-style highlighting */
111 gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */
112 gboolean magic_mode; /* Preprocess the file using external programs */
113 gboolean utf8; /* It's multibyte file codeset */
115 /* Additional editor state */
116 gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
117 GArray *coord_cache; /* Cache for mapping offsets to cursor positions */
119 /* Display information */
120 screen_dimen dpy_frame_size; /* Size of the frame surrounding the real viewer */
121 offset_type dpy_start; /* Offset of the displayed data */
122 offset_type dpy_end; /* Offset after the displayed data */
123 offset_type dpy_text_column; /* Number of skipped columns in non-wrap
124 * text mode */
125 offset_type hex_cursor; /* Hexview cursor position in file */
126 screen_dimen cursor_col; /* Cursor column */
127 screen_dimen cursor_row; /* Cursor row */
128 struct hexedit_change_node *change_list; /* Linked list of changes */
129 struct area status_area; /* Where the status line is displayed */
130 struct area ruler_area; /* Where the ruler is displayed */
131 struct area data_area; /* Where the data is displayed */
133 int dirty; /* Number of skipped updates */
134 gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */
136 /* Mode variables */
137 int bytes_per_line; /* Number of bytes per line in hex mode */
139 /* Search variables */
140 offset_type search_start; /* First character to start searching from */
141 offset_type search_end; /* Length of found string or 0 if none was found */
143 /* Pointer to the last search command */
144 gboolean want_to_quit; /* Prepare for cleanup ... */
146 /* Markers */
147 int marker; /* mark to use */
148 offset_type marks[10]; /* 10 marks: 0..9 */
150 int move_dir; /* return value from widget:
151 * 0 do nothing
152 * -1 view previous file
153 * 1 view next file
156 offset_type update_steps; /* The number of bytes between percent
157 * increments */
158 offset_type update_activate; /* Last point where we updated the status */
160 /* converter for translation of text */
161 GIConv converter;
163 /* handle of search engine */
164 mc_search_t *search;
165 gchar *last_search_string;
166 mc_search_type_t search_type;
167 gboolean search_all_codepages;
168 gboolean search_case;
169 gboolean search_backwards;
171 int search_numNeedSkipChar;
172 } mcview_t;
174 /*** global variables defined in .c file *******************************/
176 /*** declarations of public functions **********************************/
178 /* actions_cmd.c: callbacks */
179 cb_ret_t mcview_callback (Widget *, widget_msg_t, int);
180 cb_ret_t mcview_dialog_callback (Dlg_head *, dlg_msg_t, int);
181 void mcview_help_cmd (void);
182 void mcview_quit_cmd (mcview_t *);
183 void mcview_toggle_hex_mode_cmd (mcview_t *);
184 void mcview_moveto_line_cmd (mcview_t *);
185 void mcview_moveto_addr_cmd (mcview_t *);
186 void mcview_toggle_hexedit_mode_cmd (mcview_t *);
187 void mcview_hexedit_save_changes_cmd (mcview_t *);
188 void mcview_toggle_wrap_mode_cmd (mcview_t *);
189 void mcview_search_cmd (mcview_t *);
190 void mcview_toggle_magic_mode_cmd (mcview_t *);
191 void mcview_toggle_nroff_mode_cmd (mcview_t *);
192 void mcview_toggle_ruler_cmd (mcview_t *);
195 /* coord_cache.c: */
196 gboolean mcview_coord_cache_entry_less (const struct coord_cache_entry *,
197 const struct coord_cache_entry *, enum ccache_type,
198 gboolean);
199 #ifdef MC_ENABLE_DEBUGGING_CODE
200 void mcview_ccache_dump (mcview_t *);
201 #endif
204 /* datasource.c: */
205 void mcview_set_datasource_none (mcview_t *);
206 off_t mcview_get_filesize (mcview_t *);
207 char *mcview_get_ptr_file (mcview_t *, off_t);
208 char *mcview_get_ptr_string (mcview_t *, off_t);
209 int mcview_get_utf (mcview_t *, off_t, int *, gboolean *);
210 int mcview_get_byte_string (mcview_t *, off_t);
211 int mcview_get_byte_none (mcview_t *, off_t);
212 void mcview_set_byte (mcview_t *, off_t, byte);
213 void mcview_file_load_data (mcview_t *, off_t);
214 void mcview_close_datasource (mcview_t *);
215 void mcview_set_datasource_file (mcview_t *, int, const struct stat *);
216 gboolean mcview_load_command_output (mcview_t *, const char *);
217 void mcview_set_datasource_vfs_pipe (mcview_t *, int);
218 void mcview_set_datasource_string (mcview_t *, const char *);
220 /* dialog.c: */
221 gboolean mcview_dialog_search (mcview_t *);
223 /* display.c: */
224 void mcview_update (mcview_t *);
225 void mcview_display (mcview_t *);
226 void mcview_compute_areas (mcview_t *);
227 void mcview_update_bytes_per_line (mcview_t *);
228 void mcview_display_toggle_ruler (mcview_t *);
229 void mcview_display_clean (mcview_t *);
230 void mcview_display_ruler (mcview_t *);
231 void mcview_adjust_size (Dlg_head *);
232 void mcview_percent (mcview_t *, off_t);
234 /* growbuf.c: */
235 void mcview_growbuf_init (mcview_t *);
236 void mcview_growbuf_free (mcview_t *);
237 off_t mcview_growbuf_filesize (mcview_t *);
238 void mcview_growbuf_read_until (mcview_t *, off_t);
239 int mcview_get_byte_growing_buffer (mcview_t *, off_t);
240 char *mcview_get_ptr_growing_buffer (mcview_t *, off_t);
242 /* hex.c: */
243 void mcview_display_hex (mcview_t *);
244 gboolean mcview_hexedit_save_changes (mcview_t *);
245 void mcview_toggle_hexedit_mode (mcview_t *);
246 void mcview_hexedit_free_change_list (mcview_t *);
247 void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
249 /* lib.c: */
250 void mcview_toggle_magic_mode (mcview_t *);
251 void mcview_toggle_wrap_mode (mcview_t *);
252 void mcview_toggle_nroff_mode (mcview_t *);
253 void mcview_toggle_hex_mode (mcview_t *);
254 gboolean mcview_ok_to_quit (mcview_t *);
255 void mcview_done (mcview_t *);
256 void mcview_select_encoding (mcview_t *);
257 void mcview_show_error (mcview_t *, const char *);
259 /* move.c */
260 void mcview_move_up (mcview_t *, off_t);
261 void mcview_move_down (mcview_t *, off_t);
262 void mcview_move_left (mcview_t *, off_t);
263 void mcview_move_right (mcview_t *, off_t);
264 void mcview_scroll_to_cursor (mcview_t *);
265 void mcview_moveto_top (mcview_t *);
266 void mcview_moveto_bottom (mcview_t *);
267 void mcview_moveto_bol (mcview_t *);
268 void mcview_moveto_eol (mcview_t *);
269 void mcview_moveto_offset (mcview_t *, off_t);
270 void mcview_moveto (mcview_t *, off_t, off_t);
271 void mcview_coord_to_offset (mcview_t *, off_t *, off_t, off_t);
272 void mcview_offset_to_coord (mcview_t *, off_t *, off_t *, off_t);
273 void mcview_place_cursor (mcview_t *);
274 void mcview_moveto_match (mcview_t *);
276 /* nforr.c: */
277 void mcview_display_nroff (mcview_t *);
278 int mcview__get_nroff_real_len (mcview_t *, off_t, off_t);
280 /* plain.c: */
281 void mcview_display_text (mcview_t *);
283 /* search.c: */
284 int mcview_search_cmd_callback (const void *user_data, gsize char_offset);
285 int mcview_search_update_cmd_callback (const void *, gsize);
286 void mcview_do_search (mcview_t *);
289 /*** inline functions ****************************************************************************/
291 #include "../src/viewer/inlines.h"
293 #endif