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 ****************************************************************************/
21 mcview_offset_doz (off_t a
, off_t b
)
23 return (a
>= b
) ? a
- b
: 0;
26 /* --------------------------------------------------------------------------------------------- */
29 mcview_offset_rounddown (off_t a
, off_t b
)
37 /* --------------------------------------------------------------------------------------------- */
39 /* difference or zero */
40 static inline screen_dimen
41 mcview_dimen_doz (screen_dimen a
, screen_dimen b
)
43 return (a
>= b
) ? a
- b
: 0;
46 /* --------------------------------------------------------------------------------------------- */
48 static inline screen_dimen
49 mcview_dimen_min (screen_dimen a
, screen_dimen b
)
51 return (a
< b
) ? a
: b
;
54 /* --------------------------------------------------------------------------------------------- */
56 /* {{{ Simple Primitive Functions for mcview_t }}} */
57 static inline gboolean
58 mcview_is_in_panel (mcview_t
* view
)
60 return (view
->dpy_frame_size
!= 0);
63 /* --------------------------------------------------------------------------------------------- */
65 static inline gboolean
66 mcview_may_still_grow (mcview_t
* view
)
68 return (view
->growbuf_in_use
&& !view
->growbuf_finished
);
71 /* --------------------------------------------------------------------------------------------- */
73 /* returns TRUE if the idx lies in the half-open interval
74 * [offset; offset + size), FALSE otherwise.
76 static inline gboolean
77 mcview_already_loaded (off_t offset
, off_t idx
, size_t size
)
79 return (offset
<= idx
&& idx
- offset
< (off_t
) size
);
82 /* --------------------------------------------------------------------------------------------- */
84 static inline gboolean
85 mcview_get_byte_file (mcview_t
* view
, off_t byte_index
, int *retval
)
88 assert (view
->datasource
== DS_FILE
);
91 mcview_file_load_data (view
, byte_index
);
92 if (mcview_already_loaded (view
->ds_file_offset
, byte_index
, view
->ds_file_datalen
))
95 *retval
= view
->ds_file_data
[byte_index
- view
->ds_file_offset
];
103 /* --------------------------------------------------------------------------------------------- */
105 static inline gboolean
106 mcview_get_byte (mcview_t
* view
, off_t offset
, int *retval
)
108 switch (view
->datasource
)
112 return mcview_get_byte_growing_buffer (view
, offset
, retval
);
114 return mcview_get_byte_file (view
, offset
, retval
);
116 return mcview_get_byte_string (view
, offset
, retval
);
118 return mcview_get_byte_none (view
, offset
, retval
);
121 assert (!"Unknown datasource type");
126 /* --------------------------------------------------------------------------------------------- */
128 static inline gboolean
129 mcview_get_byte_indexed (mcview_t
* view
, off_t base
, off_t ofs
, int *retval
)
131 if (base
<= OFFSETTYPE_MAX
- ofs
)
133 return mcview_get_byte (view
, base
+ ofs
, retval
);
140 /* --------------------------------------------------------------------------------------------- */
143 mcview_count_backspaces (mcview_t
* view
, off_t offset
)
147 while (offset
>= 2 * backspaces
&& mcview_get_byte (view
, offset
- 2 * backspaces
, &c
)
153 /* --------------------------------------------------------------------------------------------- */
155 static inline gboolean
156 mcview_is_nroff_sequence (mcview_t
* view
, off_t offset
)
160 /* The following commands are ordered to speed up the calculation. */
162 if (!mcview_get_byte_indexed (view
, offset
, 1, &c1
) || c1
!= '\b')
165 if (!mcview_get_byte_indexed (view
, offset
, 0, &c0
) || !g_ascii_isprint (c0
))
168 if (!mcview_get_byte_indexed (view
, offset
, 2, &c2
) || !g_ascii_isprint (c2
))
171 return (c0
== c2
|| c0
== '_' || (c0
== '+' && c2
== 'o'));
174 /* --------------------------------------------------------------------------------------------- */
176 #endif /* MC__VIEWER_INLINES_H */