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

1347 {
1348 char c;
1349 char *line_in_p;
1350
1351 view->file_pos = pos;
1352 view->f_eod = false;
1353 get_next_char();
1354 if (view->f_eod)
1355 return view->file_pos;
1356 line_in_p = view->line_in_s;
1357 view->line_in_beg_p = view->line_in_s;
1358 view->line_in_end_p = view->line_in_s + PAD_COLS;
1359 while (1) {
1360 if (c == '\n')
1361 break;
1362 if (line_in_p >= view->line_in_end_p)
1363 break;
1364 *line_in_p++ = c;
1365 get_next_char();
1366 if (view->f_eod)
1367 return view->file_pos;
1368 }
1369 *line_in_p = '\0';
1370 if (view->f_squeeze) {
1371 while (1) {
1372 get_next_char();
1373 if (c != '\n')
1374 break;
1375 if (view->f_eod)
1376 break;
1377 }
1378 get_prev_char();
1379 if (view->f_eod)
1380 return view->file_pos;
1381 }
1382 return view->file_pos;
1383}
#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 1402 of file view_engine.c.

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

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

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

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

1390 {
1391 pos = get_pos_prev_line(view, pos);
1392 view->file_pos = pos;
1393 get_next_line(view, view->file_pos);
1394 return pos;
1395}
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 1467 of file view_engine.c.

1467 {
1468 view->file_pos = view->file_size;
1469 sync_ln(view);
1470 if (view->ln > view->scroll_lines)
1471 view->ln -= view->scroll_lines;
1472 else
1473 view->page_top_ln = 0;
1474 view->page_top_ln = view->ln;
1475 view->page_top_pos = view->ln_tbl[view->ln];
1476 view->page_bot_pos = view->page_top_pos;
1477 view->file_pos = view->page_top_pos;
1478 view->cury = 0;
1479 next_page(view);
1480}
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 1509 of file view_engine.c.

1509 {
1510 if (line_idx <= 1) {
1511 go_to_position(view, 0);
1512 return EOF;
1513 }
1514 sync_ln(view);
1515 view->page_top_pos = view->file_pos;
1516 view->page_bot_pos = view->file_pos;
1517 view->file_pos = view->page_top_pos;
1518 next_page(view);
1519 return 0;
1520}
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 964 of file view_engine.c.

964 {
965 if (c == '\'')
966 view->file_pos = view->mark_tbl[(NMARKS - 1)];
967 else
968 view->file_pos = view->mark_tbl[c - 'a'];
969 if (view->file_pos == NULL_POSITION)
970 Perror("Mark not set");
971 else
972 go_to_position(view, view->file_pos);
973}
#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:1115

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

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

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

1456 {
1457 view->file_pos = go_to_pos;
1458 view->page_top_pos = view->file_pos;
1459 view->page_bot_pos = view->file_pos;
1460 sync_ln(view);
1461 next_page(view);
1462}

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

1550 {
1551 view->ln++;
1552 if (view->file_pos <= view->ln_max_pos)
1553 return;
1554 if (view->ln > view->ln_tbl_size - 1) {
1555 view->ln_tbl_size += LINE_TBL_INCR;
1556 view->ln_tbl =
1557 (off_t *)realloc(view->ln_tbl, view->ln_tbl_size * sizeof(off_t));
1558 if (view->ln_tbl == nullptr) {
1559 Perror("Memory allocation failed");
1560 exit(EXIT_FAILURE);
1561 }
1562 }
1563 view->ln_tbl_cnt = view->ln;
1564 view->ln_max_pos = view->file_pos;
1565 view->ln_tbl[view->ln] = view->file_pos;
1566}
#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 1529 of file view_engine.c.

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

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

1216 {
1217 view->file_pos = view->ln_tbl[view->ln];
1218 if (view->file_pos == view->file_size)
1219 return;
1220 view->maxcol = 0;
1221 view->cury = 0;
1222 view->page_top_ln = view->ln;
1224}
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 1193 of file view_engine.c.

1193 {
1194 if (view->page_top_pos == 0)
1195 return;
1196 view->cury = 0;
1197 view->ln = view->page_top_ln;
1198 if (view->ln - view->scroll_lines >= 0)
1199 view->ln -= view->scroll_lines;
1200 else
1201 view->ln = 0;
1202 next_page(view);
1203}

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

1260 {
1261 int i = 0;
1262 view->f_bod = false;
1263 if (view->page_bot_pos == view->file_size)
1264 return;
1266 if (view->page_top_ln + n < view->ln) {
1267 view->page_top_ln += n;
1268 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1269 } else
1270 view->page_top_ln = view->ln;
1272 if (n > view->scroll_lines) {
1273 if (view->f_ln) {
1274 wmove(view->ln_win, 0, 0);
1275 wclrtobot(view->ln_win);
1276 }
1277 wmove(view->pad, 0, 0);
1278 wclrtobot(view->pad);
1279 } else {
1280 if (view->f_ln)
1281 wscrl(view->ln_win, n);
1282 wscrl(view->pad, n);
1283 if (view->cury + n < view->scroll_lines)
1284 view->cury = view->scroll_lines - n;
1285 }
1287 wmove(view->pad, view->cury, 0);
1288 for (i = 0; i < n; i++) {
1289 view->page_bot_pos = get_next_line(view, view->page_bot_pos);
1290 view->page_bot_ln = view->ln;
1291 if (view->f_eod)
1292 break;
1293 fmt_line(view);
1295 }
1296}
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 1302 of file view_engine.c.

1302 {
1303 int i;
1304 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1305 view->f_eod = false;
1306 if (view->page_top_pos == 0)
1307 return;
1308 if (view->page_top_ln - n >= 0) {
1309 view->page_top_ln -= n;
1310 } else
1311 view->page_top_ln = 1;
1312 view->ln = view->page_top_ln;
1313 view->page_top_pos = view->ln_tbl[view->page_top_ln];
1314 view->file_pos = view->page_top_pos;
1315
1316 if (view->f_ln) {
1317 wscrl(view->ln_win, -n);
1318 wnoutrefresh(view->ln_win);
1319 }
1320 wscrl(view->pad, -n);
1321 view->cury = 0;
1322 wmove(view->pad, view->cury, 0);
1324 for (i = 0; i < n; i++) {
1325 view->file_pos = get_next_line(view, view->file_pos);
1326 if (view->f_eod)
1327 break;
1328 fmt_line(view);
1330 }
1331 if (view->page_bot_ln - n >= view->scroll_lines)
1332 view->page_bot_ln -= n;
1333 else
1334 view->page_bot_ln = view->scroll_lines;
1335 view->ln = view->page_bot_ln;
1336 view->page_bot_pos = view->ln_tbl[view->page_bot_ln];
1337 view->file_pos = view->page_bot_pos;
1338 return;
1339}

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, 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
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.

Definition at line 993 of file view_engine.c.

993 {
994 char tmp_str[MAXLEN];
995 int REG_FLAGS = 0;
996 regmatch_t pmatch[1];
997 regex_t compiled_regex;
998 int reti;
999 int line_offset;
1000 int line_len;
1001 int match_len;
1002 off_t prev_ln;
1003 bool f_page = false;
1004 if (*regex_pattern == '\0')
1005 return false;
1006 if (view->f_ignore_case)
1007 REG_FLAGS = REG_ICASE | REG_EXTENDED;
1008 else
1009 REG_FLAGS = REG_EXTENDED;
1010 reti = regcomp(&compiled_regex, regex_pattern, REG_FLAGS);
1011 if (reti) {
1012 Perror("Invalid pattern");
1013 return false;
1014 }
1016 while (1) {
1018 if (*search_cmd == '/') {
1019 if (view->srch_curr_pos == view->file_size)
1020 view->srch_curr_pos = 0;
1021 } else {
1022 if (view->srch_curr_pos == 0)
1023 view->srch_curr_pos = view->file_size;
1024 }
1025 if (view->srch_curr_pos == view->srch_beg_pos) {
1026 if (view->f_first_iter == true) {
1027 view->f_first_iter = false;
1028 view->f_search_complete = false;
1029 if (*search_cmd == '/')
1030 view->cury = 0;
1031 else
1032 view->cury = view->scroll_lines + 1;
1033 } else {
1034 view->f_search_complete = true;
1035 return true;
1036 }
1037 }
1038 view->file_pos = view->srch_curr_pos;
1039 sync_ln(view);
1041 if (*search_cmd == '/') {
1042 if (view->cury == view->scroll_lines)
1043 return true;
1044 prev_ln = view->ln;
1045 view->srch_curr_pos = get_next_line(view, view->srch_curr_pos);
1046 view->page_bot_pos = view->srch_curr_pos;
1047 } else {
1048 if (view->cury == 0)
1049 return true;
1050 view->srch_curr_pos = get_prev_line(view, view->srch_curr_pos);
1051 prev_ln = view->ln;
1052 view->page_top_pos = view->srch_curr_pos;
1053 }
1054 fmt_line(view);
1055 reti = regexec(&compiled_regex, view->stripped_line_out,
1056 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1057 if (reti == REG_NOMATCH) {
1058 if (f_page) {
1060 if (*search_cmd == '?')
1061 view->cury -= 2;
1063 if ((*search_cmd == '/' && view->cury == view->scroll_lines) ||
1064 (*search_cmd == '?' && view->cury == 1)) {
1065 break;
1066 }
1067 }
1068 continue;
1069 }
1070 if (reti) {
1071 char err_str[MAXLEN];
1072 regerror(reti, &compiled_regex, err_str, sizeof(err_str));
1073 strnz__cpy(tmp_str, "Regex match failed: ", MAXLEN - 1);
1074 strnz__cat(tmp_str, err_str, MAXLEN - 1);
1075 Perror(tmp_str);
1076 regfree(&compiled_regex);
1077 return false;
1078 }
1080 if (!f_page) {
1081 if (*search_cmd == '/') {
1082 view->page_top_ln = prev_ln;
1083 wmove(view->pad, view->cury, 0);
1084 } else {
1085 view->page_bot_ln = view->ln;
1086 wmove(view->pad, 0, 0);
1087 }
1088 wclrtobot(view->pad);
1089 f_page = true;
1090 }
1091 if (*search_cmd == '?')
1092 view->cury -= 2;
1097 view->first_match_x = -1;
1098 view->last_match_x = 0;
1099 line_len = strlen(view->stripped_line_out);
1100
1101 line_offset = 0;
1102 while (1) {
1103 view->curx = line_offset + pmatch[0].rm_so;
1104 match_len = pmatch[0].rm_eo - pmatch[0].rm_so;
1105 mvwchgat(view->pad, view->cury - 1, view->curx, match_len,
1106 WA_REVERSE, cp_win, nullptr);
1107 if (view->first_match_x == -1)
1108 view->first_match_x = pmatch[0].rm_so;
1109 view->last_match_x = line_offset + pmatch[0].rm_eo;
1110 line_offset += pmatch[0].rm_eo;
1111 if (line_offset >= line_len)
1112 break;
1113 view->line_out_p = view->stripped_line_out + line_offset;
1114 reti = regexec(&compiled_regex, view->line_out_p,
1115 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1116 if (reti == REG_NOMATCH)
1117 break;
1118 if (reti) {
1119 char msgbuf[100];
1120 regerror(reti, &compiled_regex, msgbuf, sizeof(msgbuf));
1121 sprintf(tmp_str, "Regex match failed: %s", msgbuf);
1122 Perror(tmp_str);
1123 regfree(&compiled_regex);
1124 return false;
1125 }
1126 if (*search_cmd == '/') {
1127 if (view->cury == view->scroll_lines) {
1128 regfree(&compiled_regex);
1129 return true;
1130 }
1131 } else if (view->cury == 1) {
1132 regfree(&compiled_regex);
1133 return true;
1134 }
1135 }
1136 }
1137 view->file_pos = view->srch_curr_pos;
1138#ifdef DEBUG_SEARCH
1140 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1141 "%s|%c%s|Pos %zu-%zu|(%zd) %zu %zu", view->file_name, *search_cmd,
1142 regex_pattern, view->page_top_pos, view->page_bot_pos,
1143 view->file_size, view->srch_beg_pos, view->srch_curr_pos);
1144#else
1145 if (view->last_match_x > view->maxcol)
1146 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1147 "%s|%c%s|Match Cols %d-%d of %d-%d|(%zd%%)", view->file_name,
1148 *search_cmd, regex_pattern, view->first_match_x,
1149 view->last_match_x, view->pmincol, view->smaxcol - view->begx,
1150 (view->page_bot_pos * 100 / view->file_size));
1151 else
1152 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1153 "%s|%c%s|Pos %zu-%zu|(%zd%%)", view->file_name, *search_cmd,
1154 regex_pattern, view->page_top_pos, view->page_bot_pos,
1155 (view->page_bot_pos * 100 / view->file_size));
1156#endif
1157 regfree(&compiled_regex);
1158 return true;
1159}
#define MAXLEN
Definition curskeys.c:15
int cp_win
Definition dwin.c:138
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:278
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:156
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:307
off_t get_prev_line(View *, off_t)
Get Previous Line from View->buf.

References View::begx, 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::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).

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

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

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: