|
|
|
struct edit { line |
|
|
|
|
static void edit_init (struct edit* set) { set->overtype = 0; set->caps = 0; set->stamp_changed = 0; set->was_replacing = 0; set->search_lined.string = ED.search_str; set->search_lined.max_length = sizeof (ED.search_str); set->search_lined.history = ED.search_history; set->search_lined.history_max = sizeof (ED.search_history); set->search_lined.complete = p4_complete_dictionary; set->search_lined.executes = NULL; set->replace_lined.string = ED.replace_str; set->replace_lined.max_length = sizeof (ED.replace_str); set->replace_lined.history = ED.replace_history; set->replace_lined.history_max = sizeof (ED.replace_history); set->replace_lined.complete = p4_complete_dictionary; set->replace_lined.executes = NULL; set->editor = EDITOR; { |
FCode_RT (p4_edit_forget)
{ FX_USE_BODY_ADDR {
register struct edit* set = (struct edit*) FX_POP_BODY_ADDR[0];
P4_note ( |
FCode (p4_edit_init)
{
if (slot)
{
edit_init (&ED);
p4_forget_word ( |
|
|
static int scr_changed (void) { ED.blk = (line *)p4_block (BLOCK_FILE, SCR); return memcmp (ED.blk, ED.buf, sizeof (blck)) != 0; } |
static int
block_empty (char *p)
{
int n;
for (n = 64; n < BPBUF; n++)
if (p[n] != |
static int scr_empty (int n) { return block_empty (p4_block (BLOCK_FILE, n)); } |
static void scr_copy (int dst, int src) { p4_block (BLOCK_FILE, src); BLOCK_FILE->n = dst; p4_update (BLOCK_FILE); p4_save_buffers (BLOCK_FILE); } |
static void truncate_file (void) { int n; for (n = BLOCK_FILE->size; n; n--) if (!scr_empty (n - 1)) break; p4_resize_file (BLOCK_FILE, n * BPBUF); } |
static void
stamp_screen (void)
{
time_t t;
struct tm *tm;
char stamp[65];
int n;
time (&t);
tm = localtime (&t);
n = 64 - 3 - strlen (ED.log_name) - 6 - 9;
sprintf (stamp, |
static void writebuf (void) { int dummy; if (SCR != NOBLK && scr_changed ()) { if (ED.stamp_changed) stamp_screen (); ED.blk = (line *)p4_buffer (BLOCK_FILE, SCR, &dummy); memcpy (ED.blk, ED.buf, sizeof (blck)); p4_update (BLOCK_FILE); p4_save_buffers (BLOCK_FILE); } } |
static void readbuf (int n) { ED.blk = (line *)p4_block (BLOCK_FILE, n); memcpy (ED.buf, ED.blk, sizeof (blck)); SCR = n; } |
static void changescr (int n) { writebuf (); readbuf (n); } |
|
static int getckey (void) { char c = p4_getwskey (); return c < |
static void
c_printf (char const * fmt,...)
{
char buf[0x200] = |
static void type_line (char *p, int n) { int i; for (i = 0; i < n; i++) if (!p4_isprint (p[i])) break; if (i < n) while (n--) p4_putc_printable (*p++); else p4_type (p, n); } |
|
struct helpline { char row, col; char const * str; }; |
static struct helpline *displayed_help = NULL; |
static struct helpline primary_help[] = { {0, 0, |
static struct helpline ctl_k_help[] = { {0, 0, |
static struct helpline ctl_o_help[] = { {0, 0, |
static struct helpline ctl_q_help[] = { {0, 0, |
static void show_help (int row, int col, int n, struct helpline *h) { for (; n > 0; n--, h++) { setcursor (row + h->row, col + h->col); p4_puts (h->str); } } |
static void show_bottom_help (int n, struct helpline *h) { if (displayed_help == h) return; setcursor (17, -16); p4_dot_clrdown (); show_help (17, -16, n, h); displayed_help = h; } |
|
static int coleol (int row) { char *p = ED.buf[row]; int col; col = 63; if (p[col] == |
static char *
ptreol (int row)
{
char *p, *q = ED.buf[row];
for (p = q + 64; p > q && p[-1] == |
static void show_line (int i, int col) { char *p; int n; setcursor (i, col); p = &ED.buf[i][col]; n = ptreol (i) - p; if (n > 0) type_line (p, n); if (col + n < 64) p4_dot_clreol (); } |
static void show_all_lines (int from) { int i; for (i = from; i < 16; i++) show_line (i, 0); } |
static void
show_screen (void)
{
setcursor (0, -11);
c_printf ( |
static void show_status (void) { setcursor (4, -16); c_printf ( |
static void show_snr (void) { p4_dot_underline_on (); setcursor ( 8, -15), c_printf ( |
static void show_options (void) { setcursor (12, -15); c_printf ( |
static void show_line_stack (void) { char buf[65]; if (ED.linesp == ED.linetop) memset (buf, |
static void show_frame (void) { int i; setcursor ( 0, -16), p4_puts ( |
static void show_all (void) { p4_dot_normal (); p4_dot_clrscr (); show_frame (); show_snr (); show_options (); show_screen (); show_line_stack (); displayed_help = NULL; show_bottom_help (DIM (primary_help), primary_help); } |
static void show_ctl (char c) { setcursor (15, -7); if (c) c_printf ( |
static int prompt_for (char const * prompt, struct lined *l, char *dflt) { setcursor (16, -16); p4_dot_reverse (); c_printf ( |
static int yesno (char const * prompt) { int c; setcursor (16, -16); p4_dot_reverse (); c_printf ( |
static void word_from_cursor (char *p, int n) { char *q = &ED.buf[ED.row][ED.col]; while (q < ED.buf[16] && q[0] == |
|
static void insertc (char c) { char *p = &ED.buf[ED.row][ED.col], *q; for (q = &ED.buf[ED.row][coleol (ED.row)] + 1; --q > p;) q[0] = q[-1]; *p = c; } |
static void
deletec (void)
{
char *p, *q = ptreol (ED.row) - 1;
for (p = &ED.buf[ED.row][ED.col]; p < q; p++)
p[0] = p[1];
*p = |
static void
insertl (int row)
{
int i;
for (i = 15; i > row; i--)
COPY (ED.buf[i], ED.buf[i - 1]);
memset (ED.buf + i, |
static void
deletel (int row)
{
int i;
for (i = row; i < 15; i++)
COPY (ED.buf[i], ED.buf[i + 1]);
memset (ED.buf + 15, |
static void
clear_endl (void)
{
char *p = &ED.buf[ED.row][ED.col], *q = ptreol (ED.row);
if (q > p)
memset (p, |
static void strip_blanks (char **p, int *n) { while (*n && (*p)[*n - 1] == |
static int append_line (char *ln) { char *q = ptreol (ED.row); int n = 64, j = q - ED.buf[ED.row]; strip_blanks (&ln, &n); if (j) q++, j++; if (64 - j < n) return 0; memcpy (q, ln, n); return 1; } |
static void
split_line (void)
{
if (ED.row == 15)
clear_endl ();
else
{
insertl (ED.row);
memcpy (ED.buf[ED.row], ED.buf[ED.row + 1], ED.col);
memset (ED.buf[ED.row + 1], |
static void join_line (void) { if (ED.row < 15 && append_line (ED.buf[ED.row + 1])) deletel (ED.row + 1); else p4_dot_bell (); } |
static void deletew (void) { char *p = &ED.buf[ED.row][ED.col]; int n = ptreol (ED.row) - p; if (n <= 0) { join_line (); show_all_lines (ED.row); } else { while (n && *p != |
static void
inserts (void)
{
unsigned n;
writebuf ();
for (n = BLOCK_FILE->size; n > SCR; n--)
if (!scr_empty (n - 1))
break;
for (; n > SCR; n--)
scr_copy (n, n - 1);
memset (ED.buf, |
static int deletes (void) { unsigned n; if ((!scr_empty (SCR) || !block_empty (ED.buf[0])) && !yesno ( |
|
static void fwd_word (void) { char *p = &ED.buf[ED.row][ED.col]; int n; while (p < ED.buf[16] - 1) if (*p != |
static void back_word (void) { char *p = &ED.buf[ED.row][ED.col]; int n; while (ED.buf[0] < p) if (p[-1] == |
|
static int
push_to_linestk (char *p, int n)
{
if (ED.linesp == ED.linestk)
{
p4_dot_bell ();
return 0;
}
ED.linesp--;
memcpy (*ED.linesp, p, n);
memset (*ED.linesp + n, |
static int pushln (int row) { return push_to_linestk (ED.buf[ED.row], 64); } |
static int popln (char *to) { if (ED.linesp == ED.linetop) { p4_dot_bell (); return 0; } memcpy (to, *ED.linesp++, 64); show_line_stack (); return 1; } |
void push_del_line (void) { if (pushln (ED.row)) { deletel (ED.row); show_all_lines (ED.row); } } |
void push_line (void) { if (pushln (ED.row) && ED.row < 15) ED.row++; } |
void pop_spread_line (void) { if (ED.linesp < ED.linetop) { insertl (ED.row); popln (ED.buf[ED.row]); show_all_lines (ED.row); } else p4_dot_bell (); } |
void pop_line (void) { if (popln (ED.buf[ED.row])) { show_line (ED.row, 0); if (ED.row > 0) ED.row--; } } |
void push_line_end (void) { if (push_to_linestk (&ED.buf[ED.row][ED.col], 64 - ED.col)) { clear_endl (); show_line (ED.row, ED.col); } } |
void pop_line_end (void) { int c = coleol (ED.row); if (c >= 63) { p4_dot_bell (); return; } ED.col = c ? c + 1 : 0; if (ED.linesp < ED.linetop && append_line (*ED.linesp)) { ED.linesp++; show_line_stack (); show_line (ED.row, ED.col); } else p4_dot_bell (); } |
|
static int
search_string (int prompt)
{
unsigned i;
int n, l;
char *b, *p;
l = strlen (ED.search_str);
if (prompt || l == 0)
{
char buf[65];
word_from_cursor (buf, sizeof buf);
ED.search_lined.overtype = ED.overtype;
l = prompt_for ( |
static int
replace_string (int prompt)
{
int i, lr, ls;
if (!search_string (prompt))
return 0;
ls = strlen (ED.search_str);
lr = strlen (ED.replace_str);
if (prompt || lr == 0)
{
ED.replace_lined.overtype = ED.overtype;
lr = prompt_for ( |
|
static void show_sub_help (int sig) { |
|
unsigned int alarm (unsigned int sec) { return 0; } |
|
static void submenu (char key, int n, struct helpline *h) { show_ctl (key); if (key) { ED.sub_help_len = n; ED.sub_help = h; |
static void do_ctlK (void) { int c; submenu ( |
static void do_ctlO (void) { int c; submenu ( |
static void do_ctlQ (void) { int c; submenu ( |
static int do_key (char c) |
static void free_bufs (void) { if (ED.buf) p4_xfree (ED.buf); if (ED.linestk) p4_xfree (ED.linestk); if (ED.blkstk) p4_xfree (ED.blkstk); } |
static int p4_alloc_bufs (int ls, int bs) { ED.buf = (line *) p4_calloc (1, sizeof (blck)); ED.linestk = (line *) p4_calloc (1, sizeof (*ED.linestk) * ls); ED.blkstk = (blck *) p4_calloc (1, sizeof (*ED.blkstk) * bs); if (!ED.buf || !ED.linestk || !ED.blkstk) { free_bufs (); return 0; } ED.linesp = ED.linetop = ED.linestk + ls; ED.blksp = ED.blktop = ED.blkstk + bs; return 1; } |
|
static void ed_on_stop (void) { show_bottom_help (0, NULL); ED.saved_on_stop (); } |
static void ed_on_continue (void) { ED.saved_on_continue (); p4_tty_interrupt_key (0); longjmp (ED.after_stop, 1); } |
static void ed_on_winchg (void) { ED.saved_on_winchg (); show_all (); } |
void
p4_edit (int n, int r, int c)
{
char *logn;
volatile char intkey = p4_tty_interrupt_key (0);
logn = getenv ( |
/** EDIT-BLOCK |
|
|
P4_LISTWORDS (edit) =
{
(, ),
(, ),
(, ),
(, ),
(, ),
|
|
|