Fixed search for first symbol in string.
[midnight-commander.git] / src / viewer / internal.h
blob8c078583fcf416e9fe8154fc016ba0a7e38788f4
1 #ifndef MC__VIEWER_INTERNAL_H
2 #define MC__VIEWER_INTERNAL_H
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <sys/types.h>
8 #include "lib/global.h"
10 #include "lib/search.h"
11 #include "lib/widget.h"
13 #include "src/keybind-defaults.h" /* global_keymap_t */
15 /*** typedefs(not structures) and defined constants **********************************************/
17 typedef unsigned char byte;
19 /* A width or height on the screen */
20 typedef unsigned int screen_dimen;
22 extern const off_t INVALID_OFFSET;
23 extern const off_t OFFSETTYPE_MAX;
25 /*** enums ***************************************************************************************/
27 /* data sources of the view */
28 enum view_ds
30 DS_NONE, /* No data available */
31 DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */
32 DS_VFS_PIPE, /* Data comes from a piped-in VFS file */
33 DS_FILE, /* Data comes from a VFS file */
34 DS_STRING /* Data comes from a string in memory */
37 enum ccache_type
39 CCACHE_OFFSET,
40 CCACHE_LINECOL
43 typedef enum
45 NROFF_TYPE_NONE = 0,
46 NROFF_TYPE_BOLD = 1,
47 NROFF_TYPE_UNDERLINE = 2
48 } nroff_type_t;
50 /*** structures declarations (and typedefs of structures)*****************************************/
52 /* A node for building a change list on change_list */
53 struct hexedit_change_node
55 struct hexedit_change_node *next;
56 off_t offset;
57 byte value;
60 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
73 off_t cc_offset;
74 off_t cc_line;
75 off_t cc_column;
76 off_t cc_nroff_column;
77 } coord_cache_entry_t;
79 typedef struct
81 size_t size;
82 size_t capacity;
83 coord_cache_entry_t **cache;
84 } coord_cache_t;
86 struct mcview_nroff_struct;
88 typedef struct mcview_struct
90 Widget widget;
92 char *filename; /* Name of the file */
93 char *workdir; /* Name of the working directory */
94 char *command; /* Command used to pipe data in */
96 enum view_ds datasource; /* Where the displayed data comes from */
98 /* stdio pipe data source */
99 FILE *ds_stdio_pipe; /* Output of a shell command */
101 /* vfs pipe data source */
102 int ds_vfs_pipe; /* Non-seekable vfs file descriptor */
104 /* vfs file data source */
105 int ds_file_fd; /* File with random access */
106 off_t ds_file_filesize; /* Size of the file */
107 off_t ds_file_offset; /* Offset of the currently loaded data */
108 byte *ds_file_data; /* Currently loaded data */
109 size_t ds_file_datalen; /* Number of valid bytes in file_data */
110 size_t ds_file_datasize; /* Number of allocated bytes in file_data */
112 /* string data source */
113 byte *ds_string_data; /* The characters of the string */
114 size_t ds_string_len; /* The length of the string */
116 /* Growing buffers information */
117 gboolean growbuf_in_use; /* Use the growing buffers? */
118 GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */
119 size_t growbuf_lastindex; /* Number of bytes in the last page of the
120 growing buffer */
121 gboolean growbuf_finished; /* TRUE when all data has been read. */
123 /* Editor modes */
124 gboolean hex_mode; /* Hexview or Hexedit */
125 gboolean hexedit_mode; /* Hexedit */
126 gboolean hexview_in_text; /* Is the hexview cursor in the text area? */
127 gboolean text_nroff_mode; /* Nroff-style highlighting */
128 gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */
129 gboolean magic_mode; /* Preprocess the file using external programs */
130 gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
131 gboolean locked; /* We hold lock on current file */
133 gboolean utf8; /* It's multibyte file codeset */
135 coord_cache_t *coord_cache; /* Cache for mapping offsets to cursor positions */
137 /* Display information */
138 screen_dimen dpy_frame_size; /* Size of the frame surrounding the real viewer */
139 off_t dpy_start; /* Offset of the displayed data */
140 off_t dpy_end; /* Offset after the displayed data */
141 off_t dpy_text_column; /* Number of skipped columns in non-wrap
142 * text mode */
143 off_t hex_cursor; /* Hexview cursor position in file */
144 screen_dimen cursor_col; /* Cursor column */
145 screen_dimen cursor_row; /* Cursor row */
146 struct hexedit_change_node *change_list; /* Linked list of changes */
147 struct area status_area; /* Where the status line is displayed */
148 struct area ruler_area; /* Where the ruler is displayed */
149 struct area data_area; /* Where the data is displayed */
151 int dirty; /* Number of skipped updates */
152 gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */
154 /* Mode variables */
155 int bytes_per_line; /* Number of bytes per line in hex mode */
157 /* Search variables */
158 off_t search_start; /* First character to start searching from */
159 off_t search_end; /* Length of found string or 0 if none was found */
161 /* Markers */
162 int marker; /* mark to use */
163 off_t marks[10]; /* 10 marks: 0..9 */
165 int move_dir; /* return value from widget:
166 * 0 do nothing
167 * -1 view previous file
168 * 1 view next file
171 off_t update_steps; /* The number of bytes between percent
172 * increments */
173 off_t update_activate; /* Last point where we updated the status */
175 /* converter for translation of text */
176 GIConv converter;
178 /* handle of search engine */
179 mc_search_t *search;
180 gchar *last_search_string;
181 struct mcview_nroff_struct *search_nroff_seq;
183 int search_numNeedSkipChar;
185 GArray *saved_bookmarks;
186 } mcview_t;
188 typedef struct mcview_nroff_struct
190 mcview_t *view;
191 off_t index;
192 int char_width;
193 int current_char;
194 nroff_type_t type;
195 nroff_type_t prev_type;
196 } mcview_nroff_t;
198 typedef struct mcview_search_options_t
200 mc_search_type_t type;
201 gboolean case_sens;
202 gboolean backwards;
203 gboolean whole_words;
204 gboolean all_codepages;
205 } mcview_search_options_t;
207 /*** global variables defined in .c file *********************************************************/
209 extern mcview_search_options_t mcview_search_options;
211 /*** declarations of public functions ************************************************************/
213 /* actions_cmd.c: */
214 cb_ret_t mcview_callback (Widget * w, widget_msg_t msg, int parm);
215 cb_ret_t mcview_dialog_callback (Dlg_head * h, Widget * sender,
216 dlg_msg_t msg, int parm, void *data);
218 /* coord_cache.c: */
219 coord_cache_t *coord_cache_new (void);
220 void coord_cache_free (coord_cache_t * cache);
222 #ifdef MC_ENABLE_DEBUGGING_CODE
223 void mcview_ccache_dump (mcview_t * view);
224 #endif
226 void mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord,
227 enum ccache_type lookup_what);
229 /* datasource.c: */
230 void mcview_set_datasource_none (mcview_t *);
231 off_t mcview_get_filesize (mcview_t *);
232 void mcview_update_filesize (mcview_t * view);
233 char *mcview_get_ptr_file (mcview_t *, off_t);
234 char *mcview_get_ptr_string (mcview_t *, off_t);
235 int mcview_get_utf (mcview_t *, off_t, int *, gboolean *);
236 gboolean mcview_get_byte_string (mcview_t *, off_t, int *);
237 gboolean mcview_get_byte_none (mcview_t *, off_t, int *);
238 void mcview_set_byte (mcview_t *, off_t, byte);
239 void mcview_file_load_data (mcview_t *, off_t);
240 void mcview_close_datasource (mcview_t *);
241 void mcview_set_datasource_file (mcview_t *, int, const struct stat *);
242 gboolean mcview_load_command_output (mcview_t *, const char *);
243 void mcview_set_datasource_vfs_pipe (mcview_t *, int);
244 void mcview_set_datasource_string (mcview_t *, const char *);
246 /* dialog.c: */
247 gboolean mcview_dialog_search (mcview_t * view);
248 gboolean mcview_dialog_goto (mcview_t * view, off_t * offset);
250 /* display.c: */
251 void mcview_update (mcview_t * view);
252 void mcview_display (mcview_t * view);
253 void mcview_compute_areas (mcview_t * view);
254 void mcview_update_bytes_per_line (mcview_t * view);
255 void mcview_display_toggle_ruler (mcview_t * view);
256 void mcview_display_clean (mcview_t * view);
257 void mcview_display_ruler (mcview_t * view);
258 void mcview_percent (mcview_t * view, off_t p);
260 /* growbuf.c: */
261 void mcview_growbuf_init (mcview_t * view);
262 void mcview_growbuf_free (mcview_t * view);
263 off_t mcview_growbuf_filesize (mcview_t * view);
264 void mcview_growbuf_read_until (mcview_t * view, off_t p);
265 gboolean mcview_get_byte_growing_buffer (mcview_t * view, off_t p, int *);
266 char *mcview_get_ptr_growing_buffer (mcview_t * view, off_t p);
268 /* hex.c: */
269 void mcview_display_hex (mcview_t * view);
270 gboolean mcview_hexedit_save_changes (mcview_t * view);
271 void mcview_toggle_hexedit_mode (mcview_t * view);
272 void mcview_hexedit_free_change_list (mcview_t * view);
273 void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
275 /* lib.c: */
276 void mcview_toggle_magic_mode (mcview_t * view);
277 void mcview_toggle_wrap_mode (mcview_t * view);
278 void mcview_toggle_nroff_mode (mcview_t * view);
279 void mcview_toggle_hex_mode (mcview_t * view);
280 gboolean mcview_ok_to_quit (mcview_t * view);
281 void mcview_init (mcview_t * view);
282 void mcview_done (mcview_t * view);
283 void mcview_select_encoding (mcview_t * view);
284 void mcview_set_codeset (mcview_t * view);
285 void mcview_show_error (mcview_t * view, const char *error);
286 off_t mcview_bol (mcview_t * view, off_t current, off_t limit);
287 off_t mcview_eol (mcview_t * view, off_t current, off_t limit);
288 char *mcview_get_title (const Dlg_head * h, size_t len);
289 gboolean mcview_lock_file (mcview_t * view);
290 gboolean mcview_unlock_file (mcview_t * view);
292 /* move.c */
293 void mcview_move_up (mcview_t *, off_t);
294 void mcview_move_down (mcview_t *, off_t);
295 void mcview_move_left (mcview_t *, off_t);
296 void mcview_move_right (mcview_t *, off_t);
297 void mcview_scroll_to_cursor (mcview_t *);
298 void mcview_moveto_top (mcview_t *);
299 void mcview_moveto_bottom (mcview_t *);
300 void mcview_moveto_bol (mcview_t *);
301 void mcview_moveto_eol (mcview_t *);
302 void mcview_moveto_offset (mcview_t *, off_t);
303 void mcview_moveto (mcview_t *, off_t, off_t);
304 void mcview_coord_to_offset (mcview_t *, off_t *, off_t, off_t);
305 void mcview_offset_to_coord (mcview_t *, off_t *, off_t *, off_t);
306 void mcview_place_cursor (mcview_t *);
307 void mcview_moveto_match (mcview_t *);
309 /* nroff.c: */
310 void mcview_display_nroff (mcview_t * view);
311 int mcview__get_nroff_real_len (mcview_t * view, off_t, off_t p);
313 mcview_nroff_t *mcview_nroff_seq_new_num (mcview_t * view, off_t p);
314 mcview_nroff_t *mcview_nroff_seq_new (mcview_t * view);
315 void mcview_nroff_seq_free (mcview_nroff_t **);
316 nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
317 int mcview_nroff_seq_next (mcview_nroff_t *);
319 /* plain.c: */
320 void mcview_display_text (mcview_t *);
322 /* search.c: */
323 int mcview_search_cmd_callback (const void *user_data, gsize char_offset);
324 int mcview_search_update_cmd_callback (const void *, gsize);
325 void mcview_do_search (mcview_t * view);
327 /*** inline functions ****************************************************************************/
329 #include "inlines.h"
331 #endif /* MC__VIEWER_INTERNAL_H */