WEdit::num_widget_lines and WEdit::num_widget_columns are removed.
[midnight-commander.git] / src / viewer / inlines.h
blob8a3233fdd8fb35a1b705d6155fdea7141e3353b4
1 #ifndef MC__VIEWER_INLINES_H
2 #define MC__VIEWER_INLINES_H
4 #include <assert.h>
6 /*** typedefs(not structures) and defined constants **********************************************/
8 /*** enums ***************************************************************************************/
10 /*** structures declarations (and typedefs of structures)*****************************************/
12 /*** global variables defined in .c file *********************************************************/
14 /*** declarations of public functions ************************************************************/
16 /*** inline functions ****************************************************************************/
18 static inline off_t
19 mcview_offset_doz (off_t a, off_t b)
21 return (a >= b) ? a - b : 0;
24 /* --------------------------------------------------------------------------------------------- */
26 static inline off_t
27 mcview_offset_rounddown (off_t a, off_t b)
29 assert (b != 0);
30 return a - a % b;
33 /* --------------------------------------------------------------------------------------------- */
35 /* difference or zero */
36 static inline screen_dimen
37 mcview_dimen_doz (screen_dimen a, screen_dimen b)
39 return (a >= b) ? a - b : 0;
42 /* --------------------------------------------------------------------------------------------- */
44 static inline screen_dimen
45 mcview_dimen_min (screen_dimen a, screen_dimen b)
47 return (a < b) ? a : b;
50 /* --------------------------------------------------------------------------------------------- */
52 /* {{{ Simple Primitive Functions for mcview_t }}} */
53 static inline gboolean
54 mcview_is_in_panel (mcview_t * view)
56 return (view->dpy_frame_size != 0);
59 /* --------------------------------------------------------------------------------------------- */
61 static inline gboolean
62 mcview_may_still_grow (mcview_t * view)
64 return (view->growbuf_in_use && !view->growbuf_finished);
67 /* --------------------------------------------------------------------------------------------- */
69 /* returns TRUE if the idx lies in the half-open interval
70 * [offset; offset + size), FALSE otherwise.
72 static inline gboolean
73 mcview_already_loaded (off_t offset, off_t idx, size_t size)
75 return (offset <= idx && idx - offset < (off_t) size);
78 /* --------------------------------------------------------------------------------------------- */
80 static inline gboolean
81 mcview_get_byte_file (mcview_t * view, off_t byte_index, int *retval)
83 assert (view->datasource == DS_FILE);
85 mcview_file_load_data (view, byte_index);
86 if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen))
88 if (retval)
89 *retval = view->ds_file_data[byte_index - view->ds_file_offset];
90 return TRUE;
92 if (retval)
93 *retval = -1;
94 return FALSE;
97 /* --------------------------------------------------------------------------------------------- */
99 static inline gboolean
100 mcview_get_byte (mcview_t * view, off_t offset, int *retval)
102 switch (view->datasource)
104 case DS_STDIO_PIPE:
105 case DS_VFS_PIPE:
106 return mcview_get_byte_growing_buffer (view, offset, retval);
107 case DS_FILE:
108 return mcview_get_byte_file (view, offset, retval);
109 case DS_STRING:
110 return mcview_get_byte_string (view, offset, retval);
111 case DS_NONE:
112 return mcview_get_byte_none (view, offset, retval);
114 assert (!"Unknown datasource type");
115 return -1;
118 /* --------------------------------------------------------------------------------------------- */
120 static inline gboolean
121 mcview_get_byte_indexed (mcview_t * view, off_t base, off_t ofs, int *retval)
123 if (base <= OFFSETTYPE_MAX - ofs)
125 return mcview_get_byte (view, base + ofs, retval);
127 if (retval)
128 *retval = -1;
129 return FALSE;
132 /* --------------------------------------------------------------------------------------------- */
134 static inline int
135 mcview_count_backspaces (mcview_t * view, off_t offset)
137 int backspaces = 0;
138 int c;
139 while (offset >= 2 * backspaces && mcview_get_byte (view, offset - 2 * backspaces, &c)
140 && c == '\b')
141 backspaces++;
142 return backspaces;
145 /* --------------------------------------------------------------------------------------------- */
147 static inline gboolean
148 mcview_is_nroff_sequence (mcview_t * view, off_t offset)
150 int c0, c1, c2;
152 /* The following commands are ordered to speed up the calculation. */
154 if (!mcview_get_byte_indexed (view, offset, 1, &c1) || c1 != '\b')
155 return FALSE;
157 if (!mcview_get_byte_indexed (view, offset, 0, &c0) || !g_ascii_isprint (c0))
158 return FALSE;
160 if (!mcview_get_byte_indexed (view, offset, 2, &c2) || !g_ascii_isprint (c2))
161 return FALSE;
163 return (c0 == c2 || c0 == '_' || (c0 == '+' && c2 == 'o'));
166 /* --------------------------------------------------------------------------------------------- */
168 #endif /* MC__VIEWER_INLINES_H */