1 #ifndef MC_VIEWER_INLINES_H
2 #define MC_VIEWER_INLINES_H
4 /*** typedefs(not structures) and defined constants ********************/
6 /*** enums *************************************************************/
8 /*** structures declarations (and typedefs of structures)***************/
10 /*** global variables defined in .c file *******************************/
12 /*** declarations of public functions **********************************/
14 /*** inline functions ****************************************************************************/
17 mcview_offset_doz (off_t a
, off_t b
)
19 return (a
>= b
) ? a
- b
: 0;
22 /* --------------------------------------------------------------------------------------------- */
25 mcview_offset_rounddown (off_t a
, off_t b
)
31 /* --------------------------------------------------------------------------------------------- */
33 /* difference or zero */
34 static inline screen_dimen
35 mcview_dimen_doz (screen_dimen a
, screen_dimen b
)
37 return (a
>= b
) ? a
- b
: 0;
40 /* --------------------------------------------------------------------------------------------- */
42 static inline screen_dimen
43 mcview_dimen_min (screen_dimen a
, screen_dimen b
)
45 return (a
< b
) ? a
: b
;
48 /* --------------------------------------------------------------------------------------------- */
50 /* {{{ Simple Primitive Functions for mcview_t }}} */
51 static inline gboolean
52 mcview_is_in_panel (mcview_t
* view
)
54 return (view
->dpy_frame_size
!= 0);
57 /* --------------------------------------------------------------------------------------------- */
59 static inline gboolean
60 mcview_may_still_grow (mcview_t
* view
)
62 return (view
->growbuf_in_use
&& !view
->growbuf_finished
);
65 /* --------------------------------------------------------------------------------------------- */
67 /* returns TRUE if the idx lies in the half-open interval
68 * [offset; offset + size), FALSE otherwise.
70 static inline gboolean
71 mcview_already_loaded (off_t offset
, off_t idx
, size_t size
)
73 return (offset
<= idx
&& idx
- offset
< (off_t
) size
);
76 /* --------------------------------------------------------------------------------------------- */
78 static inline gboolean
79 mcview_get_byte_file (mcview_t
* view
, off_t byte_index
, int *retval
)
81 assert (view
->datasource
== DS_FILE
);
83 mcview_file_load_data (view
, byte_index
);
84 if (mcview_already_loaded (view
->ds_file_offset
, byte_index
, view
->ds_file_datalen
))
87 *retval
= view
->ds_file_data
[byte_index
- view
->ds_file_offset
];
95 /* --------------------------------------------------------------------------------------------- */
97 static inline gboolean
98 mcview_get_byte (mcview_t
* view
, off_t offset
, int *retval
)
100 switch (view
->datasource
)
104 return mcview_get_byte_growing_buffer (view
, offset
, retval
);
106 return mcview_get_byte_file (view
, offset
, retval
);
108 return mcview_get_byte_string (view
, offset
, retval
);
110 return mcview_get_byte_none (view
, offset
, retval
);
112 assert (!"Unknown datasource type");
116 /* --------------------------------------------------------------------------------------------- */
118 static inline gboolean
119 mcview_get_byte_indexed (mcview_t
* view
, off_t base
, off_t ofs
, int *retval
)
121 if (base
<= OFFSETTYPE_MAX
- ofs
)
123 return mcview_get_byte (view
, base
+ ofs
, retval
);
130 /* --------------------------------------------------------------------------------------------- */
133 mcview_count_backspaces (mcview_t
* view
, off_t offset
)
137 while (offset
>= 2 * backspaces
&& mcview_get_byte (view
, offset
- 2 * backspaces
, &c
)
143 /* --------------------------------------------------------------------------------------------- */
145 static inline gboolean
146 mcview_is_nroff_sequence (mcview_t
* view
, off_t offset
)
150 /* The following commands are ordered to speed up the calculation. */
152 if (!mcview_get_byte_indexed (view
, offset
, 1, &c1
) || c1
!= '\b')
155 if (!mcview_get_byte_indexed (view
, offset
, 0, &c0
) || !g_ascii_isprint (c0
))
158 if (!mcview_get_byte_indexed (view
, offset
, 2, &c2
) || !g_ascii_isprint (c2
))
161 return (c0
== c2
|| c0
== '_' || (c0
== '+' && c2
== 'o'));
164 /* --------------------------------------------------------------------------------------------- */