1 #ifndef MC__VIEWER_INLINES_H
2 #define MC__VIEWER_INLINES_H
8 /*** typedefs(not structures) and defined constants **********************************************/
10 /*** enums ***************************************************************************************/
12 /*** structures declarations (and typedefs of structures)*****************************************/
14 /*** global variables defined in .c file *********************************************************/
16 /*** declarations of public functions ************************************************************/
18 /*** inline functions ****************************************************************************/
20 /* difference or zero */
22 mcview_offset_doz (off_t a
, off_t b
)
24 return (a
>= b
) ? a
- b
: 0;
27 /* --------------------------------------------------------------------------------------------- */
30 mcview_offset_rounddown (off_t a
, off_t b
)
38 /* --------------------------------------------------------------------------------------------- */
40 /* difference or zero */
41 static inline screen_dimen
42 mcview_dimen_doz (screen_dimen a
, screen_dimen b
)
44 return (a
>= b
) ? a
- b
: 0;
47 /* --------------------------------------------------------------------------------------------- */
49 /* {{{ Simple Primitive Functions for WView }}} */
50 static inline gboolean
51 mcview_is_in_panel (WView
* view
)
53 return (view
->dpy_frame_size
!= 0);
56 /* --------------------------------------------------------------------------------------------- */
58 static inline gboolean
59 mcview_may_still_grow (WView
* view
)
61 return (view
->growbuf_in_use
&& !view
->growbuf_finished
);
64 /* --------------------------------------------------------------------------------------------- */
66 /* returns TRUE if the idx lies in the half-open interval
67 * [offset; offset + size), FALSE otherwise.
69 static inline gboolean
70 mcview_already_loaded (off_t offset
, off_t idx
, size_t size
)
72 return (offset
<= idx
&& idx
- offset
< (off_t
) size
);
75 /* --------------------------------------------------------------------------------------------- */
77 static inline gboolean
78 mcview_get_byte_file (WView
* view
, off_t byte_index
, int *retval
)
81 assert (view
->datasource
== DS_FILE
);
84 mcview_file_load_data (view
, byte_index
);
85 if (mcview_already_loaded (view
->ds_file_offset
, byte_index
, view
->ds_file_datalen
))
88 *retval
= view
->ds_file_data
[byte_index
- view
->ds_file_offset
];
96 /* --------------------------------------------------------------------------------------------- */
98 static inline gboolean
99 mcview_get_byte (WView
* view
, off_t offset
, int *retval
)
101 switch (view
->datasource
)
105 return mcview_get_byte_growing_buffer (view
, offset
, retval
);
107 return mcview_get_byte_file (view
, offset
, retval
);
109 return mcview_get_byte_string (view
, offset
, retval
);
111 return mcview_get_byte_none (view
, offset
, retval
);
114 assert (!"Unknown datasource type");
120 /* --------------------------------------------------------------------------------------------- */
122 static inline gboolean
123 mcview_get_byte_indexed (WView
* view
, off_t base
, off_t ofs
, int *retval
)
125 if (base
<= OFFSETTYPE_MAX
- ofs
)
127 return mcview_get_byte (view
, base
+ ofs
, retval
);
134 /* --------------------------------------------------------------------------------------------- */
137 mcview_count_backspaces (WView
* view
, off_t offset
)
141 while (offset
>= 2 * backspaces
&& mcview_get_byte (view
, offset
- 2 * backspaces
, &c
)
147 /* --------------------------------------------------------------------------------------------- */
149 static inline gboolean
150 mcview_is_nroff_sequence (WView
* view
, off_t offset
)
154 /* The following commands are ordered to speed up the calculation. */
156 if (!mcview_get_byte_indexed (view
, offset
, 1, &c1
) || c1
!= '\b')
159 if (!mcview_get_byte_indexed (view
, offset
, 0, &c0
) || !g_ascii_isprint (c0
))
162 if (!mcview_get_byte_indexed (view
, offset
, 2, &c2
) || !g_ascii_isprint (c2
))
165 return (c0
== c2
|| c0
== '_' || (c0
== '+' && c2
== 'o'));
168 /* --------------------------------------------------------------------------------------------- */
170 #endif /* MC__VIEWER_INLINES_H */