diff --git a/src/viewer/internal.h b/src/viewer/internal.h
index fdabc79..6c229df 100644
a
|
b
|
void mcview_done (mcview_t *view); |
274 | 274 | void mcview_select_encoding (mcview_t *view); |
275 | 275 | void mcview_set_codeset (mcview_t *view); |
276 | 276 | void mcview_show_error (mcview_t *view, const char *error); |
277 | | off_t mcview_bol (mcview_t *view, off_t current, int *eol_width); |
278 | | off_t mcview_eol (mcview_t *view, off_t current, int *eol_width); |
| 277 | off_t mcview_bol (mcview_t *view, off_t current); |
| 278 | off_t mcview_eol (mcview_t *view, off_t current); |
279 | 279 | |
280 | 280 | /* move.c */ |
281 | 281 | void mcview_move_up (mcview_t *, off_t); |
diff --git a/src/viewer/lib.c b/src/viewer/lib.c
index a01a8ff..142e24c 100644
a
|
b
|
mcview_show_error (mcview_t * view, const char *msg) |
244 | 244 | |
245 | 245 | /* --------------------------------------------------------------------------------------------- */ |
246 | 246 | |
247 | | /* returns index of first char on line */ |
| 247 | /* returns index of the first char in the line */ |
| 248 | /* it is constant for all line characters */ |
248 | 249 | off_t |
249 | | mcview_bol (mcview_t * view, off_t current, int * eol_width) |
| 250 | mcview_bol (mcview_t * view, off_t current) |
250 | 251 | { |
251 | | int c, prev_ch = 0; |
252 | | |
253 | | *eol_width = 1; |
| 252 | int c; |
| 253 | off_t filesize; |
| 254 | filesize = mcview_get_filesize (view); |
| 255 | if (current <= 0) |
| 256 | return 0; |
| 257 | if (current > filesize) |
| 258 | return filesize; |
| 259 | if (!mcview_get_byte (view, current, &c)) |
| 260 | return current; |
| 261 | if (c == '\n') { |
| 262 | if (!mcview_get_byte (view, current - 1, &c)) |
| 263 | return current; |
| 264 | if (c == '\r') |
| 265 | current--; |
| 266 | } |
254 | 267 | while (current > 0) { |
255 | 268 | if (!mcview_get_byte (view, current - 1, &c)) |
256 | 269 | break; |
257 | | if (c == '\r') { |
258 | | if (prev_ch == '\n') { |
259 | | /* Windows/DOS (CR LF) width of eol = 2 bytes */ |
260 | | if (current > 0) |
261 | | current++; |
262 | | *eol_width = 2; |
263 | | } |
264 | | /* Macintosh (CR) width of eol = 1 byte */ |
265 | | break; |
266 | | } else if (prev_ch == '\n') { |
267 | | /* UNIX (LF) width of eol = 1 byte */ |
268 | | if (current > 0) |
269 | | current++; |
| 270 | if (c == '\r' || c == '\n') |
270 | 271 | break; |
271 | | } |
272 | 272 | current--; |
273 | | prev_ch = c; |
274 | 273 | } |
275 | | if (current < 0) |
276 | | return 0; |
277 | 274 | return current; |
278 | 275 | } |
279 | 276 | |
280 | 277 | /* returns index of last char on line + width EOL */ |
281 | 278 | /* mcview_eol of the current line == mcview_bol next line */ |
282 | 279 | off_t |
283 | | mcview_eol (mcview_t * view, off_t current, int * eol_width) |
| 280 | mcview_eol (mcview_t * view, off_t current) |
284 | 281 | { |
285 | 282 | int c, prev_ch = 0; |
286 | 283 | off_t filesize; |
287 | | *eol_width = 1; |
288 | 284 | filesize = mcview_get_filesize (view); |
| 285 | if (current < 0) |
| 286 | return 0; |
| 287 | if (current >= filesize) |
| 288 | return filesize; |
289 | 289 | while (current < filesize) { |
290 | 290 | if (!mcview_get_byte (view, current, &c)) |
291 | 291 | break; |
292 | 292 | if (c == '\n') { |
293 | | if (prev_ch == '\r') { |
294 | | /* Windows/DOS (CR LF) width of eol = 2 bytes */ |
295 | | *eol_width = 2; |
296 | | } |
297 | | /* Macintosh (CR) width of eol = 1 byte */ |
| 293 | current++; |
298 | 294 | break; |
299 | 295 | } else if (prev_ch == '\r') { |
300 | | /* UNIX (LF) width of eol = 1 byte */ |
301 | 296 | break; |
302 | 297 | } |
303 | 298 | current++; |
304 | 299 | prev_ch = c; |
305 | 300 | } |
306 | | current += *eol_width; |
307 | | if (current > filesize) |
308 | | return filesize; |
309 | 301 | return current; |
310 | 302 | } |
diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c
index b8fc167..a520d17 100644
a
|
b
|
mcview_load (mcview_t * view, const char *command, const char *file, int start_l |
381 | 381 | if (mcview_remember_file_position && view->filename != NULL) { |
382 | 382 | long line, col; |
383 | 383 | off_t new_offset; |
384 | | int eol_len; |
385 | 384 | canon_fname = vfs_canon (view->filename); |
386 | 385 | load_file_position (canon_fname, &line, &col, &new_offset); |
387 | 386 | new_offset = min (new_offset, mcview_get_filesize (view)); |
388 | | view->dpy_start = mcview_bol (view, new_offset, &eol_len); |
| 387 | view->dpy_start = mcview_bol (view, new_offset); |
389 | 388 | g_free (canon_fname); |
390 | 389 | } |
391 | 390 | |
diff --git a/src/viewer/move.c b/src/viewer/move.c
index b4d0d5a..9e9e47e 100644
a
|
b
|
mcview_move_up (mcview_t * view, off_t lines) |
100 | 100 | } else { |
101 | 101 | const screen_dimen width = view->data_area.width; |
102 | 102 | off_t i; |
103 | | int eol_len = 1; |
104 | 103 | for (i = 0; i < lines; i++) { |
105 | | new_offset = mcview_bol (view, view->dpy_start, &eol_len); |
| 104 | new_offset = mcview_bol (view, view->dpy_start); |
106 | 105 | if (new_offset > 0) |
107 | | new_offset -= eol_len; |
108 | | new_offset = mcview_bol (view, new_offset, &eol_len); |
| 106 | new_offset--; |
| 107 | new_offset = mcview_bol (view, new_offset); |
109 | 108 | if (new_offset < 0) |
110 | 109 | new_offset = 0; |
111 | 110 | view->dpy_start = new_offset; |
… |
… |
mcview_move_down (mcview_t * view, off_t lines) |
141 | 140 | int c; |
142 | 141 | for (i = 0; i < lines; i++) { |
143 | 142 | off_t new_offset; |
144 | | int eol_len; |
145 | | new_offset = mcview_eol(view, view->dpy_start, &eol_len); |
| 143 | new_offset = mcview_eol(view, view->dpy_start); |
146 | 144 | view->dpy_start = new_offset; |
147 | 145 | } |
148 | 146 | } |
… |
… |
mcview_moveto_bol (mcview_t * view) |
258 | 256 | if (view->hex_mode) { |
259 | 257 | view->hex_cursor -= view->hex_cursor % view->bytes_per_line; |
260 | 258 | } else if (!view->text_wrap_mode) { |
261 | | int eol_len; |
262 | | view->dpy_start = mcview_bol (view, view->dpy_start, &eol_len); |
| 259 | view->dpy_start = mcview_bol (view, view->dpy_start); |
263 | 260 | } |
264 | 261 | mcview_movement_fixups (view, TRUE); |
265 | 262 | } |
… |
… |
mcview_moveto_match (mcview_t * view) |
366 | 363 | view->hex_cursor = offset; |
367 | 364 | view->dpy_start = offset - offset % view->bytes_per_line; |
368 | 365 | } else { |
369 | | int eol_len; |
370 | | view->dpy_start = mcview_bol (view, offset, &eol_len); |
| 366 | view->dpy_start = mcview_bol (view, offset); |
371 | 367 | } |
372 | 368 | |
373 | 369 | mcview_scroll_to_cursor (view); |