internal.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. #ifndef MC_VIEWER_INTERNAL_H
  2. #define MC_VIEWER_INTERNAL_H
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include "lib/global.h"
  7. #include "lib/search.h"
  8. #include "src/dialog.h"
  9. #include "src/widget.h"
  10. #include "src/keybind.h" /* global_keymap_t */
  11. /*** typedefs(not structures) and defined constants ********************/
  12. typedef unsigned char byte;
  13. /* A width or height on the screen */
  14. typedef unsigned int screen_dimen;
  15. #define OFFSETTYPE_PRIX "lX"
  16. #define OFFSETTYPE_PRId "lu"
  17. extern const off_t INVALID_OFFSET;
  18. extern const off_t OFFSETTYPE_MAX;
  19. /*** enums *************************************************************/
  20. /* data sources of the view */
  21. enum view_ds
  22. {
  23. DS_NONE, /* No data available */
  24. DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */
  25. DS_VFS_PIPE, /* Data comes from a piped-in VFS file */
  26. DS_FILE, /* Data comes from a VFS file */
  27. DS_STRING /* Data comes from a string in memory */
  28. };
  29. enum ccache_type
  30. {
  31. CCACHE_OFFSET,
  32. CCACHE_LINECOL
  33. };
  34. typedef enum
  35. {
  36. NROFF_TYPE_NONE = 0,
  37. NROFF_TYPE_BOLD = 1,
  38. NROFF_TYPE_UNDERLINE = 2
  39. } nroff_type_t;
  40. /*** structures declarations (and typedefs of structures)***************/
  41. /* A node for building a change list on change_list */
  42. struct hexedit_change_node
  43. {
  44. struct hexedit_change_node *next;
  45. off_t offset;
  46. byte value;
  47. };
  48. struct area
  49. {
  50. screen_dimen top, left;
  51. screen_dimen height, width;
  52. };
  53. /* A cache entry for mapping offsets into line/column pairs and vice versa.
  54. * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
  55. * line and column of that cache entry. cc_nroff_column is the column
  56. * corresponding to cc_offset in nroff mode.
  57. */
  58. typedef struct
  59. {
  60. off_t cc_offset;
  61. off_t cc_line;
  62. off_t cc_column;
  63. off_t cc_nroff_column;
  64. } coord_cache_entry_t;
  65. typedef struct
  66. {
  67. size_t size;
  68. size_t capacity;
  69. coord_cache_entry_t **cache;
  70. } coord_cache_t;
  71. struct mcview_nroff_struct;
  72. typedef struct mcview_struct
  73. {
  74. Widget widget;
  75. char *filename; /* Name of the file */
  76. char *command; /* Command used to pipe data in */
  77. enum view_ds datasource; /* Where the displayed data comes from */
  78. /* stdio pipe data source */
  79. FILE *ds_stdio_pipe; /* Output of a shell command */
  80. /* vfs pipe data source */
  81. int ds_vfs_pipe; /* Non-seekable vfs file descriptor */
  82. /* vfs file data source */
  83. int ds_file_fd; /* File with random access */
  84. off_t ds_file_filesize; /* Size of the file */
  85. off_t ds_file_offset; /* Offset of the currently loaded data */
  86. byte *ds_file_data; /* Currently loaded data */
  87. size_t ds_file_datalen; /* Number of valid bytes in file_data */
  88. size_t ds_file_datasize; /* Number of allocated bytes in file_data */
  89. /* string data source */
  90. byte *ds_string_data; /* The characters of the string */
  91. size_t ds_string_len; /* The length of the string */
  92. /* Growing buffers information */
  93. gboolean growbuf_in_use; /* Use the growing buffers? */
  94. GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */
  95. size_t growbuf_lastindex; /* Number of bytes in the last page of the
  96. growing buffer */
  97. gboolean growbuf_finished; /* TRUE when all data has been read. */
  98. /* Editor modes */
  99. gboolean hex_mode; /* Hexview or Hexedit */
  100. gboolean hexedit_mode; /* Hexedit */
  101. gboolean hexview_in_text; /* Is the hexview cursor in the text area? */
  102. gboolean text_nroff_mode; /* Nroff-style highlighting */
  103. gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */
  104. gboolean magic_mode; /* Preprocess the file using external programs */
  105. gboolean utf8; /* It's multibyte file codeset */
  106. /* Additional editor state */
  107. gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
  108. coord_cache_t *coord_cache; /* Cache for mapping offsets to cursor positions */
  109. /* Display information */
  110. screen_dimen dpy_frame_size; /* Size of the frame surrounding the real viewer */
  111. off_t dpy_start; /* Offset of the displayed data */
  112. off_t dpy_end; /* Offset after the displayed data */
  113. off_t dpy_text_column; /* Number of skipped columns in non-wrap
  114. * text mode */
  115. off_t hex_cursor; /* Hexview cursor position in file */
  116. screen_dimen cursor_col; /* Cursor column */
  117. screen_dimen cursor_row; /* Cursor row */
  118. struct hexedit_change_node *change_list; /* Linked list of changes */
  119. struct area status_area; /* Where the status line is displayed */
  120. struct area ruler_area; /* Where the ruler is displayed */
  121. struct area data_area; /* Where the data is displayed */
  122. int dirty; /* Number of skipped updates */
  123. gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */
  124. /* Mode variables */
  125. int bytes_per_line; /* Number of bytes per line in hex mode */
  126. /* Search variables */
  127. off_t search_start; /* First character to start searching from */
  128. off_t search_end; /* Length of found string or 0 if none was found */
  129. /* Pointer to the last search command */
  130. gboolean want_to_quit; /* Prepare for cleanup ... */
  131. /* Markers */
  132. int marker; /* mark to use */
  133. off_t marks[10]; /* 10 marks: 0..9 */
  134. int move_dir; /* return value from widget:
  135. * 0 do nothing
  136. * -1 view previous file
  137. * 1 view next file
  138. */
  139. off_t update_steps; /* The number of bytes between percent
  140. * increments */
  141. off_t update_activate; /* Last point where we updated the status */
  142. /* converter for translation of text */
  143. GIConv converter;
  144. /* keymaps */
  145. const global_keymap_t *plain_map;
  146. const global_keymap_t *hex_map;
  147. /* handle of search engine */
  148. mc_search_t *search;
  149. gchar *last_search_string;
  150. struct mcview_nroff_struct *search_nroff_seq;
  151. int search_numNeedSkipChar;
  152. } mcview_t;
  153. typedef struct mcview_nroff_struct
  154. {
  155. mcview_t *view;
  156. off_t index;
  157. int char_width;
  158. int current_char;
  159. nroff_type_t type;
  160. nroff_type_t prev_type;
  161. } mcview_nroff_t;
  162. typedef struct mcview_search_options_t
  163. {
  164. mc_search_type_t type;
  165. gboolean case_sens;
  166. gboolean backwards;
  167. gboolean whole_words;
  168. gboolean all_codepages;
  169. } mcview_search_options_t;
  170. /*** global variables defined in .c file *******************************/
  171. extern mcview_search_options_t mcview_search_options;
  172. /*** declarations of public functions **********************************/
  173. /* actions_cmd.c: */
  174. cb_ret_t mcview_callback (Widget * w, widget_msg_t msg, int parm);
  175. cb_ret_t mcview_dialog_callback (Dlg_head * h, Widget * sender,
  176. dlg_msg_t msg, int parm, void *data);
  177. /* coord_cache.c: */
  178. coord_cache_t *coord_cache_new (void);
  179. void coord_cache_free (coord_cache_t * cache);
  180. #ifdef MC_ENABLE_DEBUGGING_CODE
  181. void mcview_ccache_dump (mcview_t * view);
  182. #endif
  183. void mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord,
  184. enum ccache_type lookup_what);
  185. /* datasource.c: */
  186. void mcview_set_datasource_none (mcview_t *);
  187. off_t mcview_get_filesize (mcview_t *);
  188. void mcview_update_filesize (mcview_t * view);
  189. char *mcview_get_ptr_file (mcview_t *, off_t);
  190. char *mcview_get_ptr_string (mcview_t *, off_t);
  191. int mcview_get_utf (mcview_t *, off_t, int *, gboolean *);
  192. gboolean mcview_get_byte_string (mcview_t *, off_t, int *);
  193. gboolean mcview_get_byte_none (mcview_t *, off_t, int *);
  194. void mcview_set_byte (mcview_t *, off_t, byte);
  195. void mcview_file_load_data (mcview_t *, off_t);
  196. void mcview_close_datasource (mcview_t *);
  197. void mcview_set_datasource_file (mcview_t *, int, const struct stat *);
  198. gboolean mcview_load_command_output (mcview_t *, const char *);
  199. void mcview_set_datasource_vfs_pipe (mcview_t *, int);
  200. void mcview_set_datasource_string (mcview_t *, const char *);
  201. /* dialog.c: */
  202. gboolean mcview_dialog_search (mcview_t * view);
  203. gboolean mcview_dialog_goto (mcview_t * view, off_t * offset);
  204. /* display.c: */
  205. void mcview_update (mcview_t * view);
  206. void mcview_display (mcview_t * view);
  207. void mcview_compute_areas (mcview_t * view);
  208. void mcview_update_bytes_per_line (mcview_t * view);
  209. void mcview_display_toggle_ruler (mcview_t * view);
  210. void mcview_display_clean (mcview_t * view);
  211. void mcview_display_ruler (mcview_t * view);
  212. void mcview_percent (mcview_t * view, off_t p);
  213. /* growbuf.c: */
  214. void mcview_growbuf_init (mcview_t * view);
  215. void mcview_growbuf_free (mcview_t * view);
  216. off_t mcview_growbuf_filesize (mcview_t * view);
  217. void mcview_growbuf_read_until (mcview_t * view, off_t p);
  218. gboolean mcview_get_byte_growing_buffer (mcview_t * view, off_t p, int *);
  219. char *mcview_get_ptr_growing_buffer (mcview_t * view, off_t p);
  220. /* hex.c: */
  221. void mcview_display_hex (mcview_t * view);
  222. gboolean mcview_hexedit_save_changes (mcview_t * view);
  223. void mcview_toggle_hexedit_mode (mcview_t * view);
  224. void mcview_hexedit_free_change_list (mcview_t * view);
  225. void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
  226. /* lib.c: */
  227. void mcview_toggle_magic_mode (mcview_t * view);
  228. void mcview_toggle_wrap_mode (mcview_t * view);
  229. void mcview_toggle_nroff_mode (mcview_t * view);
  230. void mcview_toggle_hex_mode (mcview_t * view);
  231. void mcview_edit (mcview_t * view);
  232. gboolean mcview_ok_to_quit (mcview_t * view);
  233. void mcview_init (mcview_t * view);
  234. void mcview_done (mcview_t * view);
  235. void mcview_select_encoding (mcview_t * view);
  236. void mcview_set_codeset (mcview_t * view);
  237. void mcview_show_error (mcview_t * view, const char *error);
  238. off_t mcview_bol (mcview_t * view, off_t current);
  239. off_t mcview_eol (mcview_t * view, off_t current);
  240. /* move.c */
  241. void mcview_move_up (mcview_t *, off_t);
  242. void mcview_move_down (mcview_t *, off_t);
  243. void mcview_move_left (mcview_t *, off_t);
  244. void mcview_move_right (mcview_t *, off_t);
  245. void mcview_scroll_to_cursor (mcview_t *);
  246. void mcview_moveto_top (mcview_t *);
  247. void mcview_moveto_bottom (mcview_t *);
  248. void mcview_moveto_bol (mcview_t *);
  249. void mcview_moveto_eol (mcview_t *);
  250. void mcview_moveto_offset (mcview_t *, off_t);
  251. void mcview_moveto (mcview_t *, off_t, off_t);
  252. void mcview_coord_to_offset (mcview_t *, off_t *, off_t, off_t);
  253. void mcview_offset_to_coord (mcview_t *, off_t *, off_t *, off_t);
  254. void mcview_place_cursor (mcview_t *);
  255. void mcview_moveto_match (mcview_t *);
  256. /* nroff.c: */
  257. void mcview_display_nroff (mcview_t * view);
  258. int mcview__get_nroff_real_len (mcview_t * view, off_t, off_t p);
  259. mcview_nroff_t *mcview_nroff_seq_new_num (mcview_t * view, off_t p);
  260. mcview_nroff_t *mcview_nroff_seq_new (mcview_t * view);
  261. void mcview_nroff_seq_free (mcview_nroff_t **);
  262. nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
  263. int mcview_nroff_seq_next (mcview_nroff_t *);
  264. /* plain.c: */
  265. void mcview_display_text (mcview_t *);
  266. /* search.c: */
  267. int mcview_search_cmd_callback (const void *user_data, gsize char_offset);
  268. int mcview_search_update_cmd_callback (const void *, gsize);
  269. void mcview_do_search (mcview_t * view);
  270. /*** inline functions ****************************************************************************/
  271. #include "inlines.h"
  272. #endif /* MC_VIEWER_INTERNAL_H */