1 #ifndef MC__VIEWER_INLINES_H
2 #define MC__VIEWER_INLINES_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 ****************************************************************************/
19 mcview_offset_doz (off_t a
, off_t b
)
21 return (a
>= b
) ? a
- b
: 0;
24 /* --------------------------------------------------------------------------------------------- */
27 mcview_offset_rounddown (off_t a
, off_t 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
))
89 *retval
= view
->ds_file_data
[byte_index
- view
->ds_file_offset
];
97 /* --------------------------------------------------------------------------------------------- */
99 static inline gboolean
100 mcview_get_byte (mcview_t
* view
, off_t offset
, int *retval
)
102 switch (view
->datasource
)
106 return mcview_get_byte_growing_buffer (view
, offset
, retval
);
108 return mcview_get_byte_file (view
, offset
, retval
);
110 return mcview_get_byte_string (view
, offset
, retval
);
112 return mcview_get_byte_none (view
, offset
, retval
);
114 assert (!"Unknown datasource type");
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
);
132 /* --------------------------------------------------------------------------------------------- */
135 mcview_count_backspaces (mcview_t
* view
, off_t offset
)
139 while (offset
>= 2 * backspaces
&& mcview_get_byte (view
, offset
- 2 * backspaces
, &c
)
145 /* --------------------------------------------------------------------------------------------- */
147 static inline gboolean
148 mcview_is_nroff_sequence (mcview_t
* view
, off_t offset
)
152 /* The following commands are ordered to speed up the calculation. */
154 if (!mcview_get_byte_indexed (view
, offset
, 1, &c1
) || c1
!= '\b')
157 if (!mcview_get_byte_indexed (view
, offset
, 0, &c0
) || !g_ascii_isprint (c0
))
160 if (!mcview_get_byte_indexed (view
, offset
, 2, &c2
) || !g_ascii_isprint (c2
))
163 return (c0
== c2
|| c0
== '_' || (c0
== '+' && c2
== 'o'));
166 /* --------------------------------------------------------------------------------------------- */
168 #endif /* MC__VIEWER_INLINES_H */