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

Navigation functions for the view application. More...

Functions

off_t get_next_line (View *view, off_t pos)
 Get Next 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.
off_t get_prev_line (View *view, off_t pos)
 Get Previous Line from View->buf.
void go_to_eof (View *view)
 Go to End of File.
int go_to_line (View *view, off_t line_idx)
 Go to Specific Line.
void go_to_mark (View *view, int c)
 Go to Mark.
void go_to_percent (View *view, int percent)
 Go to Percent of File.
void go_to_position (View *view, off_t go_to_pos)
 Go to Specific File Position.
void increment_ln (View *view)
 Increment Line Index and Update Line Table.
void initialize_line_table (View *view)
 Initialize Line Table.
void next_page (View *view)
 Advance to Next Page.
void prev_page (View *view)
 display previous 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.
bool search (View *view, int search_cmd, char *regex_pattern)
 Search for Regular Expression Pattern.
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

gets view->line_in_s

Definition at line 1460 of file view_engine.c.

1460 {
1461 char c;
1462 char *line_in_p;
1463
1464 view->file_pos = pos;
1465 view->f_eod = false;
1466 get_next_char();
1467 if (view->f_eod)
1468 return view->file_pos;
1469 line_in_p = view->line_in_s;
1470 view->line_in_beg_p = view->line_in_s;
1471 view->line_in_end_p = view->line_in_s + PAD_COLS;
1472 while (1) {
1473 if (c == '\n')
1474 break;
1475 if (line_in_p >= view->line_in_end_p)
1476 break;
1477 *line_in_p++ = c;
1478 get_next_char();
1479 if (view->f_eod)
1480 return view->file_pos;
1481 }
1482 *line_in_p = '\0';
1483 if (view->f_squeeze) {
1484 while (1) {
1485 get_next_char();
1486 if (c != '\n')
1487 break;
1488 if (view->f_eod)
1489 break;
1490 }
1491 get_prev_char();
1492 if (view->f_eod)
1493 return view->file_pos;
1494 }
1495 return view->file_pos;
1496}
#define PAD_COLS
Definition view.h:32
View * view
Definition mem.c:49
#define get_prev_char()
read the previous characater from the virtual fileThere is no need to track line numbers when moving ...
Definition view_engine.c:68
#define get_next_char()
read the next characater from the virtual file
Definition view_engine.c:45

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 1515 of file view_engine.c.

1515 {
1516 char c;
1517 if (pos == view->file_size) {
1518 view->f_eod = true;
1519 return view->file_pos;
1520 } else
1521 view->f_eod = false;
1522 view->file_pos = pos;
1523 get_next_char();
1524 if (view->f_eod)
1525 return view->file_pos;
1526 if (view->f_squeeze) {
1527 while (1) {
1528 if (c != '\n')
1529 break;
1530 get_next_char();
1531 if (view->f_eod)
1532 return view->file_pos;
1533 }
1534 get_prev_char();
1535 }
1536 while (!view->f_eod) {
1537 if (c == '\n') {
1538 break;
1539 }
1540 get_next_char();
1541 }
1542 return view->file_pos;
1543}

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 1550 of file view_engine.c.

1550 {
1551 view->file_pos = pos;
1552 if (view->file_pos == 0) {
1553 view->f_bod = true;
1554 return view->file_pos;
1555 }
1556 while (view->ln_tbl[view->ln] >= view->file_pos) {
1557 if (view->ln == 0)
1558 break;
1559 view->ln--;
1560 }
1561 view->file_pos = view->ln_tbl[view->ln];
1562 return view->file_pos;
1563}

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 1503 of file view_engine.c.

1503 {
1504 pos = get_pos_prev_line(view, pos);
1505 view->file_pos = pos;
1506 get_next_line(view, view->file_pos);
1507 return pos;
1508}
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 1580 of file view_engine.c.

1580 {
1581 view->file_pos = view->file_size;
1582 sync_ln(view);
1583 if (view->ln > view->scroll_lines)
1584 view->ln -= view->scroll_lines;
1585 else
1586 view->page_top_ln = 0;
1587 view->page_top_ln = view->ln;
1588 view->page_top_pos = view->ln_tbl[view->ln];
1589 view->page_bot_pos = view->page_top_pos;
1590 view->file_pos = view->page_top_pos;
1591 view->cury = 0;
1592 next_page(view);
1593}
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 1622 of file view_engine.c.

1622 {
1623 if (line_idx <= 1) {
1624 go_to_position(view, 0);
1625 return EOF;
1626 }
1627 sync_ln(view);
1628 view->page_top_pos = view->file_pos;
1629 view->page_bot_pos = view->file_pos;
1630 view->file_pos = view->page_top_pos;
1631 next_page(view);
1632 return 0;
1633}
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 1072 of file view_engine.c.

1072 {
1073 if (c == '\'')
1074 view->file_pos = view->mark_tbl[(NMARKS - 1)];
1075 else
1076 view->file_pos = view->mark_tbl[c - 'a'];
1077 if (view->file_pos == NULL_POSITION)
1078 Perror("Mark not set");
1079 else
1080 go_to_position(view, view->file_pos);
1081}
#define NMARKS
Definition view.h:26
#define NULL_POSITION
Definition view.h:29
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1526

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 1599 of file view_engine.c.

1599 {
1600 if (view->file_size < 0) {
1601 Perror("Cannot determine file length");
1602 return;
1603 }
1604 view->file_pos = (percent * view->file_size) / 100;
1605 sync_ln(view);
1606 if (view->ln > view->scroll_lines)
1607 view->page_top_ln = view->ln - view->scroll_lines;
1608 else
1609 view->page_top_ln = 0;
1610 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1611 view->page_bot_pos = view->page_top_pos;
1612 view->file_pos = view->page_top_pos;
1613 next_page(view);
1614}

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 1569 of file view_engine.c.

1569 {
1570 view->file_pos = go_to_pos;
1571 view->page_top_pos = view->file_pos;
1572 view->page_bot_pos = view->file_pos;
1573 sync_ln(view);
1574 next_page(view);
1575}

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 1672 of file view_engine.c.

1672 {
1673 view->ln++;
1674 if (view->file_pos <= view->ln_max_pos)
1675 return;
1676 if (view->ln > view->ln_tbl_size - 1) {
1677 view->ln_tbl_size += LINE_TBL_INCR;
1678 view->ln_tbl =
1679 (off_t *)realloc(view->ln_tbl, view->ln_tbl_size * sizeof(off_t));
1680 if (view->ln_tbl == nullptr) {
1681 Perror("Memory allocation failed");
1682 exit(EXIT_FAILURE);
1683 }
1684 }
1685 view->ln_tbl_cnt = view->ln;
1686 view->ln_max_pos = view->file_pos;
1687 view->ln_tbl[view->ln] = view->file_pos;
1688}
#define LINE_TBL_INCR
Definition view.h:39

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 1642 of file view_engine.c.

1642 {
1643 view->ln_tbl_size = LINE_TBL_INCR;
1644 view->ln_tbl = (off_t *)calloc(view->ln_tbl_size, sizeof(off_t));
1645 if (view->ln_tbl == nullptr) {
1646 Perror("Memory allocation failed");
1647 exit(EXIT_FAILURE);
1648 }
1649 view->ln_max_pos = 0;
1650 view->ln_tbl[0] = 0;
1651 view->ln = 0;
1652}

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

Referenced by new_view_file(), and 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 1331 of file view_engine.c.

1331 {
1332 view->file_pos = view->ln_tbl[view->ln];
1333 if (view->file_pos == view->file_size)
1334 return;
1335 view->maxcol = 0;
1336 view->cury = 0;
1337 view->page_top_ln = view->ln;
1339}
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(), new_view_file(), 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 1308 of file view_engine.c.

1308 {
1309 if (view->page_top_pos == 0)
1310 return;
1311 view->cury = 0;
1312 view->ln = view->page_top_ln;
1313 if (view->ln - view->scroll_lines >= 0)
1314 view->ln -= view->scroll_lines;
1315 else
1316 view->ln = 0;
1317 next_page(view);
1318}

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 1375 of file view_engine.c.

1375 {
1376 int i = 0;
1377 view->f_bod = false;
1378 if (view->page_bot_pos == view->file_size)
1379 return;
1381 if (view->page_top_ln + n < view->ln) {
1382 view->page_top_ln += n;
1383 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1384 } else
1385 view->page_top_ln = view->ln;
1387 if (n > view->scroll_lines) {
1388 if (view->f_ln) {
1389 wmove(view->lnno_win, 0, 0);
1390 wclrtobot(view->lnno_win);
1391 }
1392 wmove(view->pad, 0, 0);
1393 wclrtobot(view->pad);
1394 } else {
1395 if (view->f_ln)
1396 wscrl(view->lnno_win, n);
1397 wscrl(view->pad, n);
1398 // scrolled up
1399 if (n < view->scroll_lines)
1400 view->cury = view->scroll_lines - n;
1401 }
1403 wmove(view->pad, view->cury, 0);
1404 for (i = 0; i < n; i++) {
1405 view->page_bot_pos = get_next_line(view, view->page_bot_pos);
1406 view->page_bot_ln = view->ln;
1407 if (view->f_eod)
1408 break;
1409 fmt_line(view);
1411 }
1412}
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::lnno_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 1418 of file view_engine.c.

1418 {
1419 int i;
1420 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1421 view->f_eod = false;
1422 if (view->page_top_pos == 0)
1423 return;
1424 if (view->page_top_ln - n >= 0) {
1425 view->page_top_ln -= n;
1426 } else
1427 view->page_top_ln = 1;
1428 view->ln = view->page_top_ln;
1429 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1430 view->file_pos = view->page_top_pos;
1431 if (view->f_ln)
1432 wscrl(view->lnno_win, -n);
1433 wscrl(view->pad, -n);
1434 view->cury = 0;
1435 wmove(view->pad, view->cury, 0);
1437 for (i = 0; i < n; i++) {
1438 view->file_pos = get_next_line(view, view->file_pos);
1439 if (view->f_eod)
1440 break;
1441 fmt_line(view);
1443 }
1444 if (view->page_bot_ln - n >= view->scroll_lines)
1445 view->page_bot_ln -= n;
1446 else
1447 view->page_bot_ln = view->scroll_lines;
1448 view->ln = view->page_bot_ln;
1449 view->page_bot_pos = view->ln_tbl[view->page_bot_ln];
1450 view->file_pos = view->page_bot_pos;
1451 return;
1452}

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::lnno_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:

◆ 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

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.

Definition at line 1101 of file view_engine.c.

1101 {
1102 char tmp_str[MAXLEN];
1103 int REG_FLAGS = 0;
1104 regmatch_t pmatch[1];
1105 regex_t compiled_regex;
1106 int reti;
1107 int line_offset;
1108 int line_len;
1109 int match_len;
1110 off_t prev_ln;
1111 bool f_page = false;
1112 if (*regex_pattern == '\0')
1113 return false;
1114 if (view->f_ignore_case)
1115 REG_FLAGS = REG_ICASE | REG_EXTENDED;
1116 else
1117 REG_FLAGS = REG_EXTENDED;
1118 reti = regcomp(&compiled_regex, regex_pattern, REG_FLAGS);
1119 if (reti) {
1120 Perror("Invalid pattern");
1121 return false;
1122 }
1123 bool rc = false;
1124 while (1) {
1126 if (search_cmd == '/') {
1127 if (view->srch_curr_pos == view->file_size)
1128 view->srch_curr_pos = 0;
1129 } else {
1130 if (view->srch_curr_pos == 0)
1131 view->srch_curr_pos = view->file_size;
1132 }
1133 if (view->srch_curr_pos == view->srch_beg_pos) {
1134 if (view->f_first_iter == true) {
1135 view->f_first_iter = false;
1136 view->f_search_complete = false;
1137 if (search_cmd == '/')
1138 view->cury = 0;
1139 else
1140 view->cury = view->scroll_lines + 1;
1141 } else {
1142 view->f_search_complete = true;
1143 return rc;
1144 }
1145 }
1146 view->file_pos = view->srch_curr_pos;
1147 sync_ln(view);
1149 if (search_cmd == '/') {
1150 if (view->cury == view->scroll_lines)
1151 return rc;
1152 prev_ln = view->ln;
1153 view->srch_curr_pos = get_next_line(view, view->srch_curr_pos);
1154 view->page_bot_ln = view->ln;
1155 view->page_bot_pos = view->srch_curr_pos;
1156 } else {
1157 if (view->cury == 0)
1158 return rc;
1159 view->srch_curr_pos = get_prev_line(view, view->srch_curr_pos);
1160 prev_ln = view->ln;
1161 view->page_top_ln = view->ln;
1162 view->page_top_pos = view->srch_curr_pos;
1163 }
1164 fmt_line(view);
1165 reti = regexec(&compiled_regex, view->stripped_line_out,
1166 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1167 if (reti == REG_NOMATCH) {
1168 if (f_page) {
1170 if (search_cmd == '?')
1171 view->cury -= 2;
1173 if ((search_cmd == '/' && view->cury == view->scroll_lines) ||
1174 (search_cmd == '?' && view->cury == 1)) {
1175 break;
1176 }
1177 }
1178 continue;
1179 }
1180 if (reti) {
1181 char err_str[MAXLEN];
1182 regerror(reti, &compiled_regex, err_str, sizeof(err_str));
1183 strnz__cpy(tmp_str, "Regex match failed: ", MAXLEN - 1);
1184 strnz__cat(tmp_str, err_str, MAXLEN - 1);
1185 Perror(tmp_str);
1186 regfree(&compiled_regex);
1187 return false;
1188 }
1189 rc = true;
1191 if (!f_page) {
1192 if (search_cmd == '/') {
1193 view->page_top_ln = prev_ln;
1194 wmove(view->pad, view->cury, 0);
1195 } else {
1196 view->page_bot_ln = view->ln;
1197 wmove(view->pad, 0, 0);
1198 }
1199 wclrtobot(view->pad);
1200 f_page = true;
1201 }
1202 if (search_cmd == '?')
1203 view->cury -= 2;
1208 view->first_match_x = -1;
1209 view->last_match_x = 0;
1210 line_len = strlen(view->stripped_line_out);
1211
1212 line_offset = 0;
1213 while (1) {
1214 view->curx = line_offset + pmatch[0].rm_so;
1215 match_len = pmatch[0].rm_eo - pmatch[0].rm_so;
1216 mvwchgat(view->pad, view->cury - 1, view->curx, match_len,
1217 WA_NORMAL, cp_nt_rev, nullptr);
1218 if (view->first_match_x == -1)
1219 view->first_match_x = pmatch[0].rm_so;
1220 view->last_match_x = line_offset + pmatch[0].rm_eo;
1221 line_offset += pmatch[0].rm_eo;
1222 if (line_offset >= line_len)
1223 break;
1224 view->line_out_p = view->stripped_line_out + line_offset;
1225 reti = regexec(&compiled_regex, view->line_out_p,
1226 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1227 if (reti == REG_NOMATCH)
1228 break;
1229 if (reti) {
1230 char msgbuf[100];
1231 regerror(reti, &compiled_regex, msgbuf, sizeof(msgbuf));
1232 sprintf(tmp_str, "Regex match failed: %s", msgbuf);
1233 Perror(tmp_str);
1234 regfree(&compiled_regex);
1235 return false;
1236 }
1237 if (search_cmd == '/') {
1238 if (view->cury == view->scroll_lines) {
1239 regfree(&compiled_regex);
1240 break;
1241 }
1242 } else if (view->cury == 1) {
1243 regfree(&compiled_regex);
1244 break;
1245 }
1246 }
1247 }
1248 view->file_pos = view->srch_curr_pos;
1249#ifdef DEBUG_SEARCH
1251 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1252 "%s|%c%s|Pos %zu-%zu|(%zd) %zu %zu", view->file_name, search_cmd,
1253 regex_pattern, view->page_top_pos, view->page_bot_pos,
1254 view->file_size, view->srch_beg_pos, view->srch_curr_pos);
1255#else
1256 if (view->last_match_x > view->maxcol)
1257 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1258 "%s|%c%s|Match Cols %d-%d of %d-%d|(%zd%%)", view->file_name,
1259 search_cmd, regex_pattern, view->first_match_x,
1260 view->last_match_x, view->pmincol, view->smaxcol - view->begx,
1261 (view->page_bot_pos * 100 / view->file_size));
1262 else
1263 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1264 "%s|%c%s|Pos %zu-%zu|(%zd%%)", view->file_name, search_cmd,
1265 regex_pattern, view->page_top_pos, view->page_bot_pos,
1266 (view->page_bot_pos * 100 / view->file_size));
1267#endif
1268 regfree(&compiled_regex);
1269 return rc;
1270}
int cp_nt_rev
Definition dwin.c:184
#define MAXLEN
Definition curskeys.c:15
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:544
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:420
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:573
off_t get_prev_line(View *, off_t)
Get Previous Line from View->buf.

References View::begx, cp_nt_rev, 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::maxcol, View::pad, View::page_bot_ln, View::page_bot_pos, View::page_top_ln, View::page_top_pos, Perror(), View::pmincol, View::scroll_lines, View::smaxcol, 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).

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 1702 of file view_engine.c.

1702 {
1703 int c = 0;
1704 off_t idx;
1705 off_t target_pos;
1706 if (view->ln_tbl[view->ln] == view->file_pos)
1707 return;
1708 target_pos = view->file_pos;
1709 view->file_pos = view->ln_tbl[view->ln_tbl_cnt];
1710 if (view->file_pos < target_pos) {
1711 view->ln = view->ln_tbl_cnt;
1712 while (view->ln_max_pos < target_pos) {
1713 get_next_char();
1714 if (view->f_eod)
1715 return;
1716 }
1717 } else if (view->ln_tbl[view->ln] > target_pos) {
1718 idx = view->ln - 1;
1719 while (view->ln_tbl[idx] > target_pos)
1720 idx--;
1721 view->ln = idx;
1722 view->file_pos = view->ln_tbl[view->ln];
1723 } else {
1724 view->ln = view->ln_tbl_cnt;
1725 view->file_pos = view->ln_tbl[view->ln];
1726 }
1727}

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: