Update po/mc.pot and po/*.po files.
[midnight-commander.git] / src / viewer / inlines.h
blob4e34caec8064aa10f5cedd6c8099d575caa2b5aa
1 #ifndef MC__VIEWER_INLINES_H
2 #define MC__VIEWER_INLINES_H
4 #ifdef HAVE_ASSERT_H
5 #include <assert.h>
6 #endif
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 static inline off_t
21 mcview_offset_doz (off_t a, off_t b)
23 return (a >= b) ? a - b : 0;
26 /* --------------------------------------------------------------------------------------------- */
28 static inline off_t
29 mcview_offset_rounddown (off_t a, off_t b)
31 #ifdef HAVE_ASSERT_H
32 assert (b != 0);
33 #endif
34 return a - a % 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)
87 #ifdef HAVE_ASSERT_H
88 assert (view->datasource == DS_FILE);
89 #endif
91 mcview_file_load_data (view, byte_index);
92 if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen))
94 if (retval)
95 *retval = view->ds_file_data[byte_index - view->ds_file_offset];
96 return TRUE;
98 if (retval)
99 *retval = -1;
100 return FALSE;
103 /* --------------------------------------------------------------------------------------------- */
105 static inline gboolean
106 mcview_get_byte (mcview_t * view, off_t offset, int *retval)
108 switch (view->datasource)
110 case DS_STDIO_PIPE:
111 case DS_VFS_PIPE:
112 return mcview_get_byte_growing_buffer (view, offset, retval);
113 case DS_FILE:
114 return mcview_get_byte_file (view, offset, retval);
115 case DS_STRING:
116 return mcview_get_byte_string (view, offset, retval);
117 case DS_NONE:
118 return mcview_get_byte_none (view, offset, retval);
120 #ifdef HAVE_ASSERT_H
121 assert (!"Unknown datasource type");
122 #endif
123 return -1;
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);
135 if (retval)
136 *retval = -1;
137 return FALSE;
140 /* --------------------------------------------------------------------------------------------- */
142 static inline int
143 mcview_count_backspaces (mcview_t * view, off_t offset)
145 int backspaces = 0;
146 int c;
147 while (offset >= 2 * backspaces && mcview_get_byte (view, offset - 2 * backspaces, &c)
148 && c == '\b')
149 backspaces++;
150 return backspaces;
153 /* --------------------------------------------------------------------------------------------- */
155 static inline gboolean
156 mcview_is_nroff_sequence (mcview_t * view, off_t offset)
158 int c0, c1, c2;
160 /* The following commands are ordered to speed up the calculation. */
162 if (!mcview_get_byte_indexed (view, offset, 1, &c1) || c1 != '\b')
163 return FALSE;
165 if (!mcview_get_byte_indexed (view, offset, 0, &c0) || !g_ascii_isprint (c0))
166 return FALSE;
168 if (!mcview_get_byte_indexed (view, offset, 2, &c2) || !g_ascii_isprint (c2))
169 return FALSE;
171 return (c0 == c2 || c0 == '_' || (c0 == '+' && c2 == 'o'));
174 /* --------------------------------------------------------------------------------------------- */
176 #endif /* MC__VIEWER_INLINES_H */