C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
View Navigation

Navigation functions for the view application. More...

Functions

void go_to_mark (View *view, int c)
 Go to Mark.
bool search (View *view, int *search_cmd, char *regex_pattern)
 Search for Regular Expression Pattern.
void prev_page (View *view)
 display previous page
void next_page (View *view)
 Advance to Next Page.
void scroll_down_n_lines (View *view, int n)
 Scroll N Lines.
void scroll_up_n_lines (View *view, int n)
 Scroll Up N Lines.
off_t get_next_line (View *view, off_t pos)
 Get Next Line from View->buf.
off_t get_prev_line (View *view, off_t pos)
 Get Previous Line from View->buf.
off_t get_pos_next_line (View *view, off_t pos)
 Get Position of Next Line.
off_t get_pos_prev_line (View *view, off_t pos)
 Get Position of Previous Line.
void go_to_position (View *view, off_t go_to_pos)
 Go to Specific File Position.
void go_to_eof (View *view)
 Go to End of File.
void go_to_percent (View *view, int percent)
 Go to Percent of File.
int go_to_line (View *view, off_t line_idx)
 Go to Specific Line.
void initialize_line_table (View *view)
 Initialize Line Table.
void increment_ln (View *view)
 Increment Line Index and Update Line Table.
void sync_ln (View *view)
 Synchronize Line Table with Current File Position.

Detailed Description

Navigation functions for the view application.

Function Documentation

◆ get_next_line()

off_t get_next_line ( View * view,
off_t pos )

Get Next Line from View->buf.

Parameters
viewstruct
posbuffer offset
Returns
file position of next line
Note
gets view->line_in_s

Definition at line 1350 of file view_engine.c.

1350 {
1351 char c;
1352 char *line_in_p;
1353
1354 view->file_pos = pos;
1355 view->f_eod = false;
1356 get_next_char();
1357 if (view->f_eod)
1358 return view->file_pos;
1359 line_in_p = view->line_in_s;
1360 view->line_in_beg_p = view->line_in_s;
1361 view->line_in_end_p = view->line_in_s + PAD_COLS;
1362 while (1) {
1363 if (c == '\n')
1364 break;
1365 if (line_in_p >= view->line_in_end_p)
1366 break;
1367 *line_in_p++ = c;
1368 get_next_char();
1369 if (view->f_eod)
1370 return view->file_pos;
1371 }
1372 *line_in_p = '\0';
1373 if (view->f_squeeze) {
1374 while (1) {
1375 get_next_char();
1376 if (c != '\n')
1377 break;
1378 if (view->f_eod)
1379 break;
1380 }
1381 get_prev_char();
1382 if (view->f_eod)
1383 return view->file_pos;
1384 }
1385 return view->file_pos;
1386}
#define PAD_COLS
Definition view.h:30
View * view
Definition mem.c:48
#define get_prev_char()
read the previous characater from the virtual file
Definition view_engine.c:67
#define get_next_char()
read the next characater from the virtual file
Definition view_engine.c:44

References View::f_eod, View::f_squeeze, View::file_pos, View::line_in_beg_p, View::line_in_end_p, and View::line_in_s.

Referenced by get_prev_line(), scroll_down_n_lines(), scroll_up_n_lines(), search(), view_display_page(), and write_view_buffer().

Here is the caller graph for this function:

◆ get_pos_next_line()

off_t get_pos_next_line ( View * view,
off_t pos )

Get Position of Next Line.

Parameters
viewdata structure
posbuffer offset
Returns
file position of next line

Definition at line 1405 of file view_engine.c.

1405 {
1406 char c;
1407 if (pos == view->file_size) {
1408 view->f_eod = true;
1409 return view->file_pos;
1410 } else
1411 view->f_eod = false;
1412 view->file_pos = pos;
1413 get_next_char();
1414 if (view->f_eod)
1415 return view->file_pos;
1416 if (view->f_squeeze) {
1417 while (1) {
1418 if (c != '\n')
1419 break;
1420 get_next_char();
1421 if (view->f_eod)
1422 return view->file_pos;
1423 }
1424 get_prev_char();
1425 }
1426 while (!view->f_eod) {
1427 if (c == '\n') {
1428 break;
1429 }
1430 get_next_char();
1431 }
1432 return view->file_pos;
1433}

References View::f_eod, View::f_squeeze, View::file_pos, and View::file_size.

◆ get_pos_prev_line()

off_t get_pos_prev_line ( View * view,
off_t pos )

Get Position of Previous Line.

Parameters
viewdata structure
posbuffer offset
Returns
file position of previous line

Definition at line 1440 of file view_engine.c.

1440 {
1441 view->file_pos = pos;
1442 if (view->file_pos == 0) {
1443 view->f_bod = true;
1444 return view->file_pos;
1445 }
1446 while (view->ln_tbl[view->ln] >= view->file_pos) {
1447 if (view->ln == 0)
1448 break;
1449 view->ln--;
1450 }
1451 view->file_pos = view->ln_tbl[view->ln];
1452 return view->file_pos;
1453}

References View::f_bod, View::file_pos, View::ln, and View::ln_tbl.

Referenced by get_prev_line().

Here is the caller graph for this function:

◆ get_prev_line()

off_t get_prev_line ( View * view,
off_t pos )

Get Previous Line from View->buf.

Parameters
viewdata structure
posbuffer offset
Returns
file position of previous line

Definition at line 1393 of file view_engine.c.

1393 {
1394 pos = get_pos_prev_line(view, pos);
1395 view->file_pos = pos;
1396 get_next_line(view, view->file_pos);
1397 return pos;
1398}
off_t get_next_line(View *, off_t)
Get Next Line from View->buf.
off_t get_pos_prev_line(View *, off_t)
Get Position of Previous Line.

References View::file_pos, get_next_line(), and get_pos_prev_line().

Referenced by search().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ go_to_eof()

void go_to_eof ( View * view)

Go to End of File.

Parameters
viewdata structure

Definition at line 1470 of file view_engine.c.

1470 {
1471 view->file_pos = view->file_size;
1472 sync_ln(view);
1473 if (view->ln > view->scroll_lines)
1474 view->ln -= view->scroll_lines;
1475 else
1476 view->page_top_ln = 0;
1477 view->page_top_ln = view->ln;
1478 view->page_top_pos = view->ln_tbl[view->ln];
1479 view->page_bot_pos = view->page_top_pos;
1480 view->file_pos = view->page_top_pos;
1481 view->cury = 0;
1482 next_page(view);
1483}
void sync_ln(View *)
Synchronize Line Table with Current File Position.
void next_page(View *)
Advance to Next Page.

References View::cury, View::file_pos, View::file_size, View::ln, View::ln_tbl, next_page(), View::page_bot_pos, View::page_top_ln, View::page_top_pos, View::scroll_lines, and sync_ln().

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ go_to_line()

int go_to_line ( View * view,
off_t line_idx )

Go to Specific Line.

Parameters
viewdata structure
line_idxline number to go to (1-based index)
Returns
0 on success, EOF if line index is out of bounds or end of data is reached

Definition at line 1512 of file view_engine.c.

1512 {
1513 if (line_idx <= 1) {
1514 go_to_position(view, 0);
1515 return EOF;
1516 }
1517 sync_ln(view);
1518 view->page_top_pos = view->file_pos;
1519 view->page_bot_pos = view->file_pos;
1520 view->file_pos = view->page_top_pos;
1521 next_page(view);
1522 return 0;
1523}
void go_to_position(View *, off_t)
Go to Specific File Position.

References View::file_pos, go_to_position(), next_page(), View::page_bot_pos, View::page_top_pos, and sync_ln().

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ go_to_mark()

void go_to_mark ( View * view,
int c )

Go to Mark.

Parameters
viewPointer to the View structure containing the state and parameters of the view application. This structure is used to access and modify the state of the application as needed.
cThe character representing the mark to go to. This character is typically a lowercase letter (a-z) corresponding to a mark that has been set previously in the view application. The function will attempt to navigate to the position associated with this mark, allowing the user to quickly jump to specific locations in the file based on the marks they have set. If the mark is not set, an error message will be displayed to the user.

Definition at line 942 of file view_engine.c.

942 {
943 if (c == '\'')
944 view->file_pos = view->mark_tbl[(NMARKS - 1)];
945 else
946 view->file_pos = view->mark_tbl[c - 'a'];
947 if (view->file_pos == NULL_POSITION)
948 Perror("Mark not set");
949 else
950 go_to_position(view, view->file_pos);
951}
#define NMARKS
Definition view.h:24
#define NULL_POSITION
Definition view.h:27
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1110

References View::file_pos, go_to_position(), View::mark_tbl, and Perror().

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ go_to_percent()

void go_to_percent ( View * view,
int percent )

Go to Percent of File.

Parameters
viewdata structure
percentof file

Definition at line 1489 of file view_engine.c.

1489 {
1490 if (view->file_size < 0) {
1491 Perror("Cannot determine file length");
1492 return;
1493 }
1494 view->file_pos = (percent * view->file_size) / 100;
1495 sync_ln(view);
1496 if (view->ln > view->scroll_lines)
1497 view->page_top_ln = view->ln - view->scroll_lines;
1498 else
1499 view->page_top_ln = 0;
1500 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1501 view->page_bot_pos = view->page_top_pos;
1502 view->file_pos = view->page_top_pos;
1503 next_page(view);
1504}

References View::file_pos, View::file_size, View::ln, View::ln_tbl, next_page(), View::page_bot_pos, View::page_top_ln, View::page_top_pos, Perror(), View::scroll_lines, and sync_ln().

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ go_to_position()

void go_to_position ( View * view,
off_t go_to_pos )

Go to Specific File Position.

Parameters
viewdata Structure
go_to_pos

Definition at line 1459 of file view_engine.c.

1459 {
1460 view->file_pos = go_to_pos;
1461 view->page_top_pos = view->file_pos;
1462 view->page_bot_pos = view->file_pos;
1463 sync_ln(view);
1464 next_page(view);
1465}

References View::file_pos, next_page(), View::page_bot_pos, View::page_top_pos, and sync_ln().

Here is the call graph for this function:

◆ increment_ln()

void increment_ln ( View * view)

Increment Line Index and Update Line Table.

Parameters
viewdata structure

This function is called when a line feed character is encountered while reading the file. It increments the line index (view->ln) and checks if the current file position exceeds the maximum position recorded in the line table. If it does, it updates the line table with the new file position. If the line index exceeds the current size of the line table, the table is resized by allocating more memory.

Definition at line 1553 of file view_engine.c.

1553 {
1554 view->ln++;
1555 if (view->file_pos <= view->ln_max_pos)
1556 return;
1557 if (view->ln > view->ln_tbl_size - 1) {
1558 view->ln_tbl_size += LINE_TBL_INCR;
1559 view->ln_tbl =
1560 (off_t *)realloc(view->ln_tbl, view->ln_tbl_size * sizeof(off_t));
1561 if (view->ln_tbl == nullptr) {
1562 Perror("Memory allocation failed");
1563 exit(EXIT_FAILURE);
1564 }
1565 }
1566 view->ln_tbl_cnt = view->ln;
1567 view->ln_max_pos = view->file_pos;
1568 view->ln_tbl[view->ln] = view->file_pos;
1569}
#define LINE_TBL_INCR
Definition view.h:34

References View::file_pos, View::ln, View::ln_max_pos, View::ln_tbl, View::ln_tbl_cnt, View::ln_tbl_size, and Perror().

Here is the call graph for this function:

◆ initialize_line_table()

void initialize_line_table ( View * view)

Initialize Line Table.

Parameters
viewdata structure

The line table is initialized with a specified increment size (LINE_TBL_INCR). Memory is allocated for the line table, and the first entry is set to 0, indicating the file position of the first line. The line index (view->ln) is initialized to 0.

Definition at line 1532 of file view_engine.c.

1532 {
1533 view->ln_tbl_size = LINE_TBL_INCR;
1534 view->ln_tbl = (off_t *)malloc(view->ln_tbl_size * sizeof(off_t));
1535 if (view->ln_tbl == nullptr) {
1536 Perror("Memory allocation failed");
1537 exit(EXIT_FAILURE);
1538 }
1539 view->ln_max_pos = 0;
1540 view->ln_tbl[0] = 0;
1541 view->ln = 0;
1542}

References View::ln, View::ln_max_pos, View::ln_tbl, View::ln_tbl_size, and Perror().

Referenced by view_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ next_page()

void next_page ( View * view)

Advance to Next Page.

Parameters
viewdata structure

Advances from view->page_bot_pos to view the next page of content. view->page_bot_pos must be set properly when calling this function. If the current bottom position of the page is at the end of the file, the function returns without making any changes. Otherwise, it resets the maximum column and current line position to the top of the page, updates the file position to the current bottom position of the page, and sets the top position and line number of the page accordingly. Finally, it calls the function to display the new page content.

Definition at line 1226 of file view_engine.c.

1226 {
1227 view->file_pos = view->ln_tbl[view->ln];
1228 if (view->file_pos == view->file_size)
1229 return;
1230 view->maxcol = 0;
1231 view->cury = 0;
1232 view->page_top_ln = view->ln;
1234}
void view_display_page(View *)
Display Current Page.

References View::cury, View::file_pos, View::file_size, View::ln, View::ln_tbl, View::maxcol, View::page_top_ln, and view_display_page().

Referenced by go_to_eof(), go_to_line(), go_to_percent(), go_to_position(), prev_page(), view_cmd_processor(), and view_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prev_page()

void prev_page ( View * view)

display previous page

Parameters
viewdata structure

Displays the previous page starting at (view->page_top_ln - view->scroll_lines).

Definition at line 1203 of file view_engine.c.

1203 {
1204 if (view->page_top_pos == 0)
1205 return;
1206 view->cury = 0;
1207 view->ln = view->page_top_ln;
1208 if (view->ln - view->scroll_lines >= 0)
1209 view->ln -= view->scroll_lines;
1210 else
1211 view->ln = 0;
1212 next_page(view);
1213}

References View::cury, View::ln, next_page(), View::page_top_ln, View::page_top_pos, and View::scroll_lines.

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scroll_down_n_lines()

void scroll_down_n_lines ( View * view,
int n )

Scroll N Lines.

Parameters
viewdata Structure
nnumber of lines to scroll

Locate New Top of Page

Scroll

Fill in Page Bottom

Definition at line 1269 of file view_engine.c.

1269 {
1270 int i = 0;
1271 view->f_bod = false;
1272 if (view->page_bot_pos == view->file_size)
1273 return;
1275 if (view->page_top_ln + n < view->ln) {
1276 view->page_top_ln += n;
1277 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1278 } else
1279 view->page_top_ln = view->ln;
1281 if (n > view->scroll_lines) {
1282 if (view->f_ln) {
1283 wmove(view->ln_win, 0, 0);
1284 wclrtobot(view->ln_win);
1285 }
1286 wmove(view->pad, 0, 0);
1287 wclrtobot(view->pad);
1288 } else {
1289 if (view->f_ln)
1290 wscrl(view->ln_win, n);
1291 wscrl(view->pad, n);
1292 if (view->cury + n < view->scroll_lines)
1293 view->cury = view->scroll_lines - n;
1294 }
1296 wmove(view->pad, view->cury, 0);
1297 for (i = 0; i < n; i++) {
1298 view->page_bot_pos = get_next_line(view, view->page_bot_pos);
1299 view->page_bot_ln = view->ln;
1300 if (view->f_eod)
1301 break;
1302 fmt_line(view);
1304 }
1305}
void display_line(View *)
Display Line on Padparam View *view data structure.
int fmt_line(View *)
Format Line for Display.

References View::cury, display_line(), View::f_bod, View::f_eod, View::f_ln, View::file_size, fmt_line(), get_next_line(), View::ln, View::ln_tbl, View::ln_win, View::pad, View::page_bot_ln, View::page_bot_pos, View::page_top_ln, View::page_top_pos, and View::scroll_lines.

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scroll_up_n_lines()

void scroll_up_n_lines ( View * view,
int n )

Scroll Up N Lines.

Parameters
viewdata Structure
nnumber of lines to scroll

Fill in Page Top

Definition at line 1311 of file view_engine.c.

1311 {
1312 int i;
1313 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1314 view->f_eod = false;
1315 if (view->page_top_pos == 0)
1316 return;
1317 if (view->page_top_ln - n >= 0)
1318 view->page_top_ln -= n;
1319 else
1320 view->page_top_ln = 1;
1321 view->ln = view->page_top_ln;
1322 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1323 view->file_pos = view->page_top_pos;
1324 if (view->f_ln) {
1325 wscrl(view->ln_win, -n);
1326 wnoutrefresh(view->ln_win);
1327 }
1328 wscrl(view->pad, -n);
1329 view->cury = 0;
1330 wmove(view->pad, view->cury, 0);
1332 for (i = 0; i < n; i++) {
1333 view->file_pos = get_next_line(view, view->file_pos);
1334 if (view->f_eod)
1335 break;
1336 fmt_line(view);
1338 }
1339 view->page_bot_pos = view->file_pos;
1340 view->page_bot_ln = view->ln;
1341 return;
1342}

References View::cury, display_line(), View::f_eod, View::f_ln, View::file_pos, fmt_line(), get_next_line(), View::ln, View::ln_tbl, View::ln_win, View::pad, View::page_bot_ln, View::page_bot_pos, View::page_top_ln, and View::page_top_pos.

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search()

bool search ( View * view,
int * search_cmd,
char * regex_pattern )

Search for Regular Expression Pattern.

Parameters
viewPointer to View Structure
search_cmdSearch Command Character ('/' or '?')
regex_patternRegular Expression Pattern to Search For
Returns
true if a match is found and displayed, false if the search completes without finding a match or if an error occurs
Note
The search performs extended regular expression matching, ignoring ANSI sequences and Unicode characters. Matches are highlighted on the screen, and the search continues until the page is full or the end of the file is reached. If the search wraps around the file, a message is displayed indicating that the search is complete.
The search state is maintained in the view structure, allowing for repeat searches and tracking of the current search position.
this function highlights all matches in the current ncurses pad, including those not displayed on the screen, and tracks the first and last match columns for prompt display.
ANSI sequences and Unicode characters are stripped before matching, so matching corresponds to the visual display

initialize iteration

get line to scan

< Note placement before get_next_line

< Note placement after get_prev_line

non-matching page filler

Display matching lines

All matches on the current line are highlighted, including those not displayed on the screen. Track first and last match columns for prompt display.

Statistics for debugging

Definition at line 971 of file view_engine.c.

971 {
972 char tmp_str[MAXLEN];
973 int REG_FLAGS = 0;
974 regmatch_t pmatch[1];
975 regex_t compiled_regex;
976 int reti;
977 int line_offset;
978 int line_len;
979 int match_len;
980 off_t prev_ln;
981 bool f_page = false;
982 if (*regex_pattern == '\0')
983 return false;
984 if (view->f_ignore_case)
985 REG_FLAGS = REG_ICASE | REG_EXTENDED;
986 else
987 REG_FLAGS = REG_EXTENDED;
988 reti = regcomp(&compiled_regex, regex_pattern, REG_FLAGS);
989 if (reti) {
990 Perror("Invalid pattern");
991 return false;
992 }
994 while (1) {
996 if (*search_cmd == '/') {
997 if (view->srch_curr_pos == view->file_size)
998 view->srch_curr_pos = 0;
999 } else {
1000 if (view->srch_curr_pos == 0)
1001 view->srch_curr_pos = view->file_size;
1002 }
1003 if (view->srch_curr_pos == view->srch_beg_pos) {
1004 if (view->f_first_iter == true) {
1005 view->f_first_iter = false;
1006 view->f_search_complete = false;
1007 if (*search_cmd == '/')
1008 view->cury = 0;
1009 else
1010 view->cury = view->scroll_lines + 1;
1011 } else {
1012 view->f_search_complete = true;
1013 return true;
1014 }
1015 }
1016 view->file_pos = view->srch_curr_pos;
1017 sync_ln(view);
1019 if (*search_cmd == '/') {
1020 if (view->cury == view->scroll_lines)
1021 return true;
1022 prev_ln = view->ln;
1023 view->srch_curr_pos = get_next_line(view, view->srch_curr_pos);
1024 view->page_bot_pos = view->srch_curr_pos;
1025 } else {
1026 if (view->cury == 0)
1027 return true;
1028 view->srch_curr_pos = get_prev_line(view, view->srch_curr_pos);
1029 prev_ln = view->ln;
1030 view->page_top_pos = view->srch_curr_pos;
1031 }
1032 fmt_line(view);
1033 reti = regexec(&compiled_regex, view->stripped_line_out,
1034 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1035 if (reti == REG_NOMATCH) {
1036 if (f_page) {
1038 if (*search_cmd == '?')
1039 view->cury -= 2;
1041 if ((*search_cmd == '/' && view->cury == view->scroll_lines) ||
1042 (*search_cmd == '?' && view->cury == 1)) {
1043 break;
1044 }
1045 }
1046 continue;
1047 }
1048 if (reti) {
1049 char err_str[MAXLEN];
1050 regerror(reti, &compiled_regex, err_str, sizeof(err_str));
1051 strnz__cpy(tmp_str, "Regex match failed: ", MAXLEN - 1);
1052 strnz__cat(tmp_str, err_str, MAXLEN - 1);
1053 Perror(tmp_str);
1054 regfree(&compiled_regex);
1055 return false;
1056 }
1058 if (!f_page) {
1059 if (*search_cmd == '/') {
1060 view->page_top_ln = prev_ln;
1061 wmove(view->pad, view->cury, 0);
1062 } else {
1063 view->page_bot_ln = view->ln;
1064 wmove(view->pad, 0, 0);
1065 }
1066 wclrtobot(view->pad);
1067 f_page = true;
1068 }
1069 if (*search_cmd == '?')
1070 view->cury -= 2;
1075 view->first_match_x = -1;
1076 view->last_match_x = 0;
1077 line_len = strlen(view->stripped_line_out);
1078
1079 line_offset = 0;
1080 while (1) {
1081 view->curx = line_offset + pmatch[0].rm_so;
1082 match_len = pmatch[0].rm_eo - pmatch[0].rm_so;
1083 mvwchgat(view->pad, view->cury - 1, view->curx, match_len,
1084 WA_REVERSE, cp_win, nullptr);
1085 if (view->first_match_x == -1)
1086 view->first_match_x = pmatch[0].rm_so;
1087 view->last_match_x = line_offset + pmatch[0].rm_eo;
1088 line_offset += pmatch[0].rm_eo;
1089 if (line_offset >= line_len)
1090 break;
1091 view->line_out_p = view->stripped_line_out + line_offset;
1092 reti = regexec(&compiled_regex, view->line_out_p,
1093 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1094 if (reti == REG_NOMATCH)
1095 break;
1096 if (reti) {
1097 char msgbuf[100];
1098 regerror(reti, &compiled_regex, msgbuf, sizeof(msgbuf));
1099 sprintf(tmp_str, "Regex match failed: %s", msgbuf);
1100 Perror(tmp_str);
1101 regfree(&compiled_regex);
1102 return false;
1103 }
1104 if (*search_cmd == '/') {
1105 if (view->cury == view->scroll_lines) {
1106 regfree(&compiled_regex);
1107 return true;
1108 }
1109 } else if (view->cury == 1) {
1110 regfree(&compiled_regex);
1111 return true;
1112 }
1113 }
1114 }
1115 view->file_pos = view->srch_curr_pos;
1116#ifdef DEBUG
1118 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1119 "%s|%c%s|Pos %zu-%zu|(%zd) %zu %zu", view->file_name, *search_cmd,
1120 regex_pattern, view->page_top_pos, view->page_bot_pos,
1121 view->file_size, view->srch_beg_pos, view->srch_curr_pos);
1122#else
1123 if (view->last_match_x > view->maxcol)
1124 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1125 "%s|%c%s|Match Cols %d-%d of %d-%d|(%zd%%)", view->file_name,
1126 *search_cmd, regex_pattern, view->first_match_x,
1127 view->last_match_x, view->pmincol, view->smaxcol - view->begx,
1128 (view->page_bot_pos * 100 / view->file_size));
1129 else
1130 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1131 "%s|%c%s|Pos %zu-%zu|(%zd%%)", view->file_name, *search_cmd,
1132 regex_pattern, view->page_top_pos, view->page_bot_pos,
1133 (view->page_bot_pos * 100 / view->file_size));
1134#endif
1135 regfree(&compiled_regex);
1136 return true;
1137}
#define MAXLEN
Definition curskeys.c:15
int cp_win
Definition dwin.c:137
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:269
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:147
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:298
off_t get_prev_line(View *, off_t)
Get Previous Line from View->buf.

References cp_win, View::curx, View::cury, display_line(), View::f_first_iter, View::f_ignore_case, View::f_search_complete, View::file_name, View::file_pos, View::file_size, View::first_match_x, fmt_line(), get_next_line(), get_prev_line(), View::last_match_x, View::line_out_p, View::ln, View::pad, View::page_bot_ln, View::page_bot_pos, View::page_top_ln, View::page_top_pos, Perror(), View::scroll_lines, View::srch_beg_pos, View::srch_curr_pos, ssnprintf(), View::stripped_line_out, strnz__cat(), strnz__cpy(), sync_ln(), and View::tmp_prompt_str.

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sync_ln()

void sync_ln ( View * view)

Synchronize Line Table with Current File Position.

Parameters
viewdata Structure

The line table (view->ln_tbl) is an array that stores the file position of each line. The index (view->ln + 1) corresponds to the current line number. (the line number table is 0-based, while line numbering starts at 1).

Note
If the line or position requested is not in the line table, this function reads forward to sycn.
If the line or positione requested is behind the current line table index, the line index will be decremented it matches the file position.

Definition at line 1582 of file view_engine.c.

1582 {
1583 int c = 0;
1584 off_t idx;
1585 off_t target_pos;
1586 if (view->ln_tbl[view->ln] == view->file_pos)
1587 return;
1588 target_pos = view->file_pos;
1589 view->file_pos = view->ln_tbl[view->ln_tbl_cnt];
1590 if (view->file_pos < target_pos) {
1591 view->ln = view->ln_tbl_cnt;
1592 while (view->ln_max_pos < target_pos) {
1593 get_next_char();
1594 if (view->f_eod)
1595 return;
1596 }
1597 } else if (view->ln_tbl[view->ln] > target_pos) {
1598 idx = view->ln - 1;
1599 while (view->ln_tbl[idx] > target_pos)
1600 idx--;
1601 view->ln = idx;
1602 view->file_pos = view->ln_tbl[view->ln];
1603 } else {
1604 view->ln = view->ln_tbl_cnt;
1605 view->file_pos = view->ln_tbl[view->ln];
1606 }
1607}

References View::f_eod, View::file_pos, View::ln, View::ln_max_pos, View::ln_tbl, and View::ln_tbl_cnt.

Referenced by go_to_eof(), go_to_line(), go_to_percent(), go_to_position(), and search().

Here is the caller graph for this function: