C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
view_engine.c File Reference

The working part of View. More...

#include <common.h>
#include <errno.h>
#include <fcntl.h>
#include <iso646.h>
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
Include dependency graph for view_engine.c:

Go to the source code of this file.

Macros

#define _Refresh(view)
#define _ui_perror(msg)
#define confirm()
#define get_next_char()
 read the next characater from the virtual file
#define get_prev_char()
 read the previous characater from the virtual fileThere is no need to track line numbers when moving backwards as they are stored in the line table and accessed as needed. When reading in reverse, the Beginning of Data (BOD) flag is set when the file position is zero, and cleared when the position or reading direction changes. Carriage-returns are ignored as they should be.

Functions

int a_toi (char *, bool *)
 a safer alternative to atoi() for converting ASCII strings to integers.
void build_prompt (View *view)
 Build Prompt String.
void cat_file (View *view)
 Concatenate File to Standard Output.
void destroy_line_table (View *view)
 Destroy Line Table.
void display_line (View *view)
 Display Line on Padparam View *view data structure.
void display_line_eod (View *view)
 Display End of Data.
int display_prompt (View *view, char *s)
 Display Command Line Prompt.
void display_split_line (View *view)
 Display Split Line on Pad.
bool enter_file_spec (Init *init, char *file_spec)
 use form to enter a file specification
int fmt_line (View *view)
 Format Line for Display.
int get_cmd_arg (View *view, char *prompt)
 Get Command Argument from User Input.
int get_cmd_char (View *view, off_t *n)
 Get Command Character from User Input.
void get_line (View *, off_t)
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, uint c)
 Go to Mark.
void go_to_percent (View *view, uint percent)
 Go to Percent of File.
void go_to_position (View *view, off_t 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.
off_t line_number (View *view, off_t position)
 Get Line Number for a Given File Position.
void log_cc_buf (View *view)
 Log Complex Character Buffer.
void log_split_lines (View *view)
 Log Split Lines.
void log_stripped_line_out (View *view)
 Log Stripped Line Output.
void log_strnz (char *str, uint len)
 Log String with Specified Length.
void lp (View *view, char *PrintFile)
 Send File to Print Queue.
int pad_refresh (View *view)
 Refresh Pad and Line Number Window.
void page_next (View *view)
 Advance to Next Page.
void page_prev (View *view)
 display previous page
void parse_ansi_str (char *ansi_str, attr_t *attrs, ushort *cpx)
 Parse ANSI SGR Escape Sequence.
void scroll_next (View *view, uint n)
 Scroll Down by n Lines.
void scroll_prev (View *view, uint n)
 Move the view scope n lines toward the beginning of the file.
bool search (View *view, int search_cmd, char *regex_pattern)
 Search for Regular Expression Pattern.
void sync_ln (View *view, off_t ln_no)
 Synchronize Line Table with Current File Position.
void sync_pos (View *, off_t pos)
int view_cmd_processor (Init *init)
 Main Command Processing Loop for View.
void view_display_help (Init *init)
 Display View Help File.
void view_display_page (View *view)
 Display Current Page.
int view_file (Init *init)
 Start view.
int write_view_buffer (Init *init, bool f_strip_ansi)
 Write buffer contents to files.

Variables

FILE * dbgfp
char err_msg [MAXLEN]
char prev_regex_pattern [MAXLEN]

Detailed Description

The working part of View.

Author
Bill Waller Copyright (c) 2025 MIT License billx.nosp@m.wall.nosp@m.er@gm.nosp@m.ail..nosp@m.com
Date
2026-02-09

Definition in file view_engine.c.

Macro Definition Documentation

◆ _Refresh

#define _Refresh ( view)
Value:
{ \
pad_refresh(view); \
ui_render(); \
}
View * view
Definition mem.c:38

Definition at line 103 of file view_engine.c.

103#define _Refresh(view) \
104 { \
105 pad_refresh(view); \
106 ui_render(); \
107 }

◆ _ui_perror

#define _ui_perror ( msg)
Value:
{ \
ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2); \
strnz__cpy(em1, msg, MAXLEN - 1); \
ui_display_error(em0, em1, nullptr, nullptr); \
}
#define MAXLEN
Definition lf.h:38
char em1[MAXLEN]
Definition lf.c:43
char em0[MAXLEN]
Definition lf.c:42
#define _(String)
Definition amort.c:23

Definition at line 96 of file view_engine.c.

96#define _ui_perror(msg) \
97 { \
98 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2); \
99 strnz__cpy(em1, msg, MAXLEN - 1); \
100 ui_display_error(em0, em1, nullptr, nullptr); \
101 }

◆ confirm

#define confirm ( )
Value:
{ \
if ((c = get_cmd_char(view, &n_cmd)) == 'y' || c == 'Y') \
ans = true; \
else if (c == 'n' || c == 'N') \
ans = false; \
}
int get_cmd_char(View *, off_t *)
Get Command Character from User Input.

Definition at line 88 of file view_engine.c.

88#define confirm() \
89 { \
90 if ((c = get_cmd_char(view, &n_cmd)) == 'y' || c == 'Y') \
91 ans = true; \
92 else if (c == 'n' || c == 'N') \
93 ans = false; \
94 }

Function Documentation

◆ get_line()

void get_line ( View * view,
off_t line )

__get_line

Definition at line 1809 of file view_engine.c.

1809 {
1810 // if (view->f_eod)
1811 // return;
1812 view->ln_no = line;
1813 view->file_pos = view->ln_tbl[view->ln_no];
1814 char c;
1815 char *line_in_p;
1816
1817 view->f_eod = false;
1818 get_next_char();
1819 if (view->f_eod) {
1820 view->ln_no = line;
1821 view->ln_no_max = view->ln_no;
1822 return;
1823 }
1824 line_in_p = view->line_in_s;
1825 view->line_in_beg_p = view->line_in_s;
1826 view->line_in_end_p = view->line_in_s + PAD_COLS - 1;
1827 while (1) {
1828 if (c == '\n' || c == '\0')
1829 break;
1830 if (line_in_p > view->line_in_end_p) {
1831 *line_in_p = '\0';
1833 view->ln_no_max = view->ln_no;
1834 break;
1835 }
1836 *line_in_p++ = c;
1837 get_next_char();
1838 if (view->f_eod) {
1839 view->ln_no = line;
1840 view->ln_no_max = view->ln_no;
1841 return;
1842 }
1843 }
1844 *line_in_p = '\0';
1845 if (view->f_squeeze) {
1846 while (1) {
1847 get_next_char();
1848 if (c != '\n' && c != '\0')
1849 break;
1850 if (view->f_eod) {
1851 view->ln_no = line;
1852 view->ln_no_max = view->ln_no;
1853 break;
1854 }
1855 }
1856 if (!view->f_eod) {
1857 get_prev_char();
1858 return;
1859 }
1860 }
1861
1862 view->ln_no = line;
1863 return;
1864}
#define PAD_COLS
Definition view.h:39
#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:75
#define get_next_char()
read the next characater from the virtual file
Definition view_engine.c:52
void increment_ln(View *)
Increment Line Index and Update Line Table.

References View::f_eod, View::f_squeeze, View::file_pos, increment_ln(), View::line_in_beg_p, View::line_in_end_p, View::line_in_s, View::ln_no, View::ln_no_max, and View::ln_tbl.

Referenced by page_prev(), scroll_next(), scroll_prev(), search(), view_display_page(), and write_view_buffer().

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

◆ sync_pos()

void sync_pos ( View * view,
off_t pos )

Definition at line 2052 of file view_engine.c.

2052 {
2053 int c = 0;
2054 // Advance view->ln_tbl[view->ln_no] to view->file_pos if necessary
2055 while (view->ln_tbl[view->ln_no] < pos) {
2056 if (view->ln_no >= view->ln_no_max) {
2057 get_next_char();
2058 if (view->f_eod)
2059 break;
2060 } else
2061 view->ln_no++;
2062 }
2063 while (view->ln_tbl[view->ln_no] > pos) {
2064 if (view->ln_no == 0)
2065 break;
2066 view->ln_no--;
2067 }
2068 view->file_pos = view->ln_tbl[view->ln_no];
2069}

References View::f_eod, View::file_pos, View::ln_no, View::ln_no_max, and View::ln_tbl.

Referenced by go_to_eof(), and go_to_position().

Here is the caller graph for this function:

Variable Documentation

◆ dbgfp

FILE * dbgfp

Definition at line 110 of file view_engine.c.

◆ err_msg

char err_msg[MAXLEN]

Definition at line 151 of file view_engine.c.

◆ prev_regex_pattern

char prev_regex_pattern

Definition at line 109 of file view_engine.c.

Referenced by view_cmd_processor().