1
0
mirror of https://github.com/rfivet/uemacs.git synced 2025-11-23 11:41:15 -05:00

18 Commits
4.2.2 ... 4.2.3

Author SHA1 Message Date
19e33fef82 Increase version number before merge to master branch. 2017-03-22 14:37:26 +08:00
5b7d419b1d Add comments clarifying $overlap and $target 2017-03-22 14:18:29 +08:00
7e71cf52a3 Review cursor move commands in basic. 2016-05-22 22:22:39 +08:00
14e6240b9c Transpose-characters valid with mixed UTF-8 and extended ASCII. 2016-05-21 07:52:19 +08:00
f11dea468f Insure transpose-characters works with UTF8. 2016-05-20 20:42:37 +08:00
92078e5595 Check consistency of forwchar/backchar calls.
Review entab dot movement.
2016-05-20 19:46:54 +08:00
2b21a98e9c Review forwchar and backchar. 2016-05-19 21:27:26 +08:00
d4b2a4c1aa Review ldelchar and ldelete. 2016-05-19 14:02:43 +08:00
a7c34c747d cppcheck: The scope of the variable 'bp' can be reduced. 2016-05-19 11:26:07 +08:00
ef7207b421 cppcheck: Variable 'startflag' was assigned a value that is never used. 2016-05-19 11:20:21 +08:00
1b2307e056 Partial fix of issues when using unicode sequence with describe-key, search-forward, query-replace-string. 2016-04-09 11:46:40 +08:00
f83ab08609 Review formatted string printing when '%' is at end of string.
Clean up unused IO return code.
2016-04-05 11:33:38 +08:00
16e6f87ad5 Review windows update when reading or writing buffers to file. 2016-04-01 13:25:05 +08:00
af23c6b3b5 Fix previous commit break: Handle case of non override of locked file in Linux. 2016-03-30 20:14:19 +08:00
ac3c2aa6dd Review file read and write into buffers. 2016-03-30 17:44:46 +08:00
06eba37779 Include stddef on Linux for offsetof macro definition. 2016-03-25 19:27:09 +08:00
135866231d Rework line allocation. 2016-03-25 14:56:34 +08:00
3e2d73394a Review buffer list related functions. 2016-03-24 21:53:36 +08:00
26 changed files with 1001 additions and 1027 deletions

View File

@@ -129,8 +129,8 @@ depend: ${SRC}
# DO NOT DELETE THIS LINE -- make depend uses it
basic.o: basic.c basic.h buffer.h line.h retcode.h utf8.h estruct.h \
input.h bind.h mlout.h random.h terminal.h defines.h window.h
basic.o: basic.c basic.h retcode.h input.h bind.h mlout.h random.h \
terminal.h defines.h utf8.h window.h buffer.h line.h
bind.o: bind.c bind.h estruct.h bindable.h buffer.h line.h retcode.h \
utf8.h display.h ebind.h exec.h file.h flook.h input.h names.h window.h \
defines.h
@@ -139,40 +139,40 @@ bindable.o: bindable.c bindable.h defines.h buffer.h line.h retcode.h \
terminal.h
buffer.o: buffer.c buffer.h line.h retcode.h utf8.h defines.h estruct.h \
file.h input.h bind.h mlout.h window.h
display.o: display.c display.h estruct.h buffer.h line.h retcode.h utf8.h \
display.o: display.c display.h estruct.h utf8.h buffer.h line.h retcode.h \
input.h bind.h termio.h terminal.h defines.h version.h wrapper.h \
window.h
ebind.o: ebind.c ebind.h basic.h bind.h estruct.h bindable.h buffer.h \
line.h retcode.h utf8.h eval.h exec.h file.h isearch.h random.h region.h \
ebind.o: ebind.c ebind.h basic.h retcode.h bind.h estruct.h bindable.h \
buffer.h line.h utf8.h eval.h exec.h file.h isearch.h random.h region.h \
search.h spawn.h window.h defines.h word.h
eval.o: eval.c eval.h basic.h bind.h buffer.h line.h retcode.h utf8.h \
eval.o: eval.c eval.h basic.h retcode.h bind.h buffer.h line.h utf8.h \
display.h estruct.h exec.h execute.h flook.h input.h random.h search.h \
terminal.h defines.h termio.h version.h window.h
exec.o: exec.c exec.h retcode.h buffer.h line.h utf8.h bind.h display.h \
estruct.h eval.h file.h flook.h input.h random.h window.h defines.h
execute.o: execute.c execute.h estruct.h bind.h random.h retcode.h \
display.h file.h buffer.h line.h utf8.h input.h mlout.h search.h \
display.h utf8.h file.h buffer.h line.h input.h mlout.h search.h \
terminal.h defines.h window.h
file.o: file.c file.h buffer.h line.h retcode.h utf8.h defines.h \
display.h estruct.h execute.h fileio.h input.h bind.h lock.h mlout.h \
window.h
fileio.o: fileio.c fileio.h defines.h retcode.h utf8.h
flook.o: flook.c flook.h retcode.h defines.h fileio.h
input.o: input.c input.h bind.h estruct.h bindable.h display.h exec.h \
retcode.h names.h terminal.h defines.h utf8.h wrapper.h
isearch.o: isearch.c isearch.h basic.h buffer.h line.h retcode.h utf8.h \
input.o: input.c input.h bind.h estruct.h bindable.h display.h utf8.h \
exec.h retcode.h names.h terminal.h defines.h wrapper.h
isearch.o: isearch.c isearch.h basic.h retcode.h buffer.h line.h utf8.h \
display.h estruct.h exec.h input.h bind.h search.h terminal.h defines.h \
window.h
line.o: line.c line.h retcode.h utf8.h buffer.h estruct.h mlout.h \
window.h defines.h
lock.o: lock.c estruct.h lock.h
main.o: main.c estruct.h basic.h bind.h bindable.h buffer.h line.h \
retcode.h utf8.h display.h eval.h execute.h file.h lock.h mlout.h \
random.h search.h terminal.h defines.h termio.h version.h window.h
main.o: main.c estruct.h basic.h retcode.h bind.h bindable.h buffer.h \
line.h utf8.h display.h eval.h execute.h file.h lock.h mlout.h random.h \
search.h terminal.h defines.h termio.h version.h window.h
mingw32.o: mingw32.c
mlout.o: mlout.c mlout.h
names.o: names.c names.h basic.h bind.h bindable.h buffer.h line.h \
retcode.h utf8.h display.h estruct.h eval.h exec.h file.h isearch.h \
names.o: names.c names.h basic.h retcode.h bind.h bindable.h buffer.h \
line.h utf8.h display.h estruct.h eval.h exec.h file.h isearch.h \
region.h random.h search.h spawn.h window.h defines.h word.h
pklock.o: pklock.c estruct.h pklock.h
posix.o: posix.c
@@ -186,13 +186,13 @@ search.o: search.c search.h line.h retcode.h utf8.h basic.h buffer.h \
spawn.o: spawn.c spawn.h defines.h buffer.h line.h retcode.h utf8.h \
display.h estruct.h exec.h file.h flook.h input.h bind.h terminal.h \
window.h
tcap.o: tcap.c terminal.h defines.h retcode.h display.h estruct.h \
tcap.o: tcap.c terminal.h defines.h retcode.h utf8.h display.h estruct.h \
termio.h
termio.o: termio.c termio.h estruct.h retcode.h utf8.h
termio.o: termio.c termio.h utf8.h estruct.h retcode.h
utf8.o: utf8.c utf8.h
window.o: window.c window.h defines.h buffer.h line.h retcode.h utf8.h \
basic.h display.h estruct.h execute.h terminal.h wrapper.h
word.o: word.c word.h basic.h buffer.h line.h retcode.h utf8.h estruct.h \
word.o: word.c word.h basic.h retcode.h buffer.h line.h utf8.h estruct.h \
mlout.h random.h region.h window.h defines.h
wrapper.o: wrapper.c wrapper.h
wscreen.o: wscreen.c wscreen.h

309
basic.c
View File

@@ -2,8 +2,6 @@
#include "basic.h"
#define CVMVAS 1 /* arguments to page forward/back in pages */
/* basic.c
*
* The routines in this file move the cursor around on the screen. They
@@ -18,19 +16,18 @@
#include <stdio.h>
#include <stdlib.h>
#include "buffer.h"
#include "estruct.h"
#include "input.h"
#include "line.h"
#include "mlout.h"
#include "random.h"
#include "terminal.h"
#include "utf8.h"
#include "window.h"
int overlap = 0 ; /* line overlap in forw/back page */
int curgoal ; /* Goal for C-P, C-N */
#define CVMVAS 1 /* arguments to page forward/back in pages */
int overlap = DEFAULT_OVERLAP ; /* line overlap in forw/back page */
int curgoal ; /* Goal for C-P, C-N */
/*
@@ -38,7 +35,7 @@ int curgoal ; /* Goal for C-P, C-N */
* column, return the best choice for the offset. The offset is returned.
* Used by "C-N" and "C-P".
*/
static unsigned getgoal( struct line *dlp) {
static unsigned getgoal( line_p dlp) {
int col ;
unsigned idx ;
const unsigned len = llength( dlp) ;
@@ -69,21 +66,117 @@ static unsigned getgoal( struct line *dlp) {
}
/*
* Move the cursor to the beginning of the current line.
* Move the cursor to the beginning of the current line of active window.
*/
int gotobol(int f, int n)
{
curwp->w_doto = 0;
return TRUE;
boolean gotobol( int f, int n) {
curwp->w_doto = 0 ;
return TRUE ;
}
/*
* Move the cursor to the end of the current line. Trivial. No errors.
* Move the cursor to the end of the current line of active window.
*/
int gotoeol(int f, int n)
{
curwp->w_doto = llength(curwp->w_dotp);
return TRUE;
boolean gotoeol( int f, int n) {
curwp->w_doto = llength( curwp->w_dotp) ;
return TRUE ;
}
/*
* Goto the beginning of the buffer. Massive adjustment of dot. This is
* considered to be hard motion; it really isn't if the original value of dot
* is the same as the new value of dot. Normally bound to "M-<".
*/
boolean gotobob( int f, int n) {
curwp->w_dotp = lforw( curbp->b_linep) ;
curwp->w_doto = 0 ;
curwp->w_flag |= WFHARD ;
return TRUE ;
}
/*
* Move to the end of the buffer. Dot is always put at the end of the file
* (ZJ). The standard screen code does most of the hard parts of update.
* Bound to "M->".
*/
boolean gotoeob( int f, int n) {
curwp->w_dotp = curbp->b_linep ;
curwp->w_doto = 0 ;
curwp->w_flag |= WFHARD ;
return TRUE ;
}
/*
* Move forward by full lines. If the number of lines to move is less than
* zero, call the backward line function to actually do it. The last command
* controls how the goal column is set. Bound to "C-N". No errors are
* possible.
*/
boolean forwline( int f, int n) {
line_p dlp ;
if (n < 0)
return backline(f, -n);
/* if we are on the last line as we start....fail the command */
if (curwp->w_dotp == curbp->b_linep)
return FALSE;
/* if the last command was not a line move, reset the goal column */
if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE);
/* flag this command as a line move */
thisflag |= CFCPCN;
/* and move the point down */
dlp = curwp->w_dotp;
while( n && dlp != curbp->b_linep) {
dlp = lforw( dlp) ;
n -= 1 ;
}
/* reseting the current position */
curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE;
return (n == 0) ? TRUE : FALSE ;
}
/*
* This function is like "forwline", but goes backwards. The scheme is exactly
* the same. Check for arguments that are less than zero and call your
* alternate. Figure out the new line and call "movedot" to perform the
* motion. No errors are possible. Bound to "C-P".
*/
boolean backline( int f, int n) {
line_p dlp ;
if (n < 0)
return forwline(f, -n);
/* if we are on the first line as we start....fail the command */
if (lback(curwp->w_dotp) == curbp->b_linep)
return FALSE;
/* if the last command was not a line move, reset the goal column */
if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE);
/* flag this command as a line move */
thisflag |= CFCPCN;
/* and move the point up */
dlp = curwp->w_dotp;
while( n && lback( dlp) != curbp->b_linep) {
dlp = lback( dlp) ;
n -= 1 ;
}
/* reseting the current position */
curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE;
return (n == 0) ? TRUE : FALSE ;
}
/*
@@ -120,107 +213,7 @@ int gotoline( int f, int n) {
/* First, we go to the begin of the buffer. */
gotobob(f, n);
return forwline(f, n - 1);
}
/*
* Goto the beginning of the buffer. Massive adjustment of dot. This is
* considered to be hard motion; it really isn't if the original value of dot
* is the same as the new value of dot. Normally bound to "M-<".
*/
int gotobob(int f, int n)
{
curwp->w_dotp = lforw(curbp->b_linep);
curwp->w_doto = 0;
curwp->w_flag |= WFHARD;
return TRUE;
}
/*
* Move to the end of the buffer. Dot is always put at the end of the file
* (ZJ). The standard screen code does most of the hard parts of update.
* Bound to "M->".
*/
int gotoeob(int f, int n)
{
curwp->w_dotp = curbp->b_linep;
curwp->w_doto = 0;
curwp->w_flag |= WFHARD;
return TRUE;
}
/*
* Move forward by full lines. If the number of lines to move is less than
* zero, call the backward line function to actually do it. The last command
* controls how the goal column is set. Bound to "C-N". No errors are
* possible.
*/
int forwline(int f, int n)
{
struct line *dlp;
if (n < 0)
return backline(f, -n);
/* if we are on the last line as we start....fail the command */
if (curwp->w_dotp == curbp->b_linep)
return FALSE;
/* if the last command was not note a line move,
reset the goal column */
if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE);
/* flag this command as a line move */
thisflag |= CFCPCN;
/* and move the point down */
dlp = curwp->w_dotp;
while (n-- && dlp != curbp->b_linep)
dlp = lforw(dlp);
/* reseting the current position */
curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE;
return TRUE;
}
/*
* This function is like "forwline", but goes backwards. The scheme is exactly
* the same. Check for arguments that are less than zero and call your
* alternate. Figure out the new line and call "movedot" to perform the
* motion. No errors are possible. Bound to "C-P".
*/
int backline(int f, int n)
{
struct line *dlp;
if (n < 0)
return forwline(f, -n);
/* if we are on the last line as we start....fail the command */
if (lback(curwp->w_dotp) == curbp->b_linep)
return FALSE;
/* if the last command was not note a line move,
reset the goal column */
if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE);
/* flag this command as a line move */
thisflag |= CFCPCN;
/* and move the point up */
dlp = curwp->w_dotp;
while (n-- && lback(dlp) != curbp->b_linep)
dlp = lback(dlp);
/* reseting the current position */
curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE;
return TRUE;
return (n == 1) ? TRUE : forwline( f, n - 1) ;
}
/*
@@ -229,20 +222,20 @@ int backline(int f, int n)
* the overlap; this value is the default overlap value in ITS EMACS. Because
* this zaps the top line in the display window, we have to do a hard update.
*/
int forwpage(int f, int n)
{
struct line *lp;
boolean forwpage( int f, int n) {
line_p lp ;
if (f == FALSE) {
#if SCROLLCODE
if (term.t_scroll != NULL)
if (overlap == 0)
n = curwp->w_ntrows / 3 * 2;
if (term.t_scroll != NULL) /* $scroll == FALSE */
if (overlap == 0) /* $overlap == 0 */
n = curwp->w_ntrows * 2 / 3 ;
else
n = curwp->w_ntrows - overlap;
else
#endif
n = curwp->w_ntrows - 2; /* Default scroll. */
if (n <= 0) /* Forget the overlap. */
n = 1; /* If tiny window. */
} else if (n < 0)
@@ -251,12 +244,19 @@ int forwpage(int f, int n)
else /* Convert from pages. */
n *= curwp->w_ntrows; /* To lines. */
#endif
lp = curwp->w_linep;
while (n-- && lp != curbp->b_linep)
lp = lforw(lp);
curwp->w_linep = lp;
/* lp = curwp->w_linep; */
lp = curwp->w_dotp ;
while( n && lp != curbp->b_linep) {
lp = lforw( lp) ;
n -= 1 ;
}
/* curwp->w_linep = lp; */
curwp->w_dotp = lp;
curwp->w_doto = 0;
reposition( TRUE, 0) ;
#if SCROLLCODE
curwp->w_flag |= WFHARD | WFKILLS;
#else
@@ -271,20 +271,28 @@ int forwpage(int f, int n)
* EMACS manual. Bound to "M-V". We do a hard update for exactly the same
* reason.
*/
int backpage(int f, int n)
{
struct line *lp;
boolean backpage( int f, int n) {
line_p lp ;
if (f == FALSE) { /* interactive, default n = 1 supplied */
/* in interactive mode, first move dot to top of window */
if( curwp->w_dotp != curwp->w_linep) {
curwp->w_dotp = curwp->w_linep ;
curwp->w_doto = 0 ;
/* curwp->w_flag |= WFMOVE ; */
return TRUE ;
}
if (f == FALSE) {
#if SCROLLCODE
if (term.t_scroll != NULL)
if (overlap == 0)
n = curwp->w_ntrows / 3 * 2;
if (term.t_scroll != NULL) /* $scroll != FALSE */
if (overlap == 0) /* $overlap == 0 */
n = curwp->w_ntrows * 2 / 3 ;
else
n = curwp->w_ntrows - overlap;
else
#endif
n = curwp->w_ntrows - 2; /* Default scroll. */
if (n <= 0) /* Don't blow up if the. */
n = 1; /* Window is tiny. */
} else if (n < 0)
@@ -293,12 +301,19 @@ int backpage(int f, int n)
else /* Convert from pages. */
n *= curwp->w_ntrows; /* To lines. */
#endif
lp = curwp->w_linep;
while (n-- && lback(lp) != curbp->b_linep)
lp = lback(lp);
curwp->w_linep = lp;
/* lp = curwp->w_linep; */
lp = curwp->w_dotp ;
while( n && lback( lp) != curbp->b_linep) {
lp = lback( lp) ;
n -= 1 ;
}
/* curwp->w_linep = lp; */
curwp->w_dotp = lp;
curwp->w_doto = 0;
reposition( TRUE, (f == FALSE) ? 1 : 0) ;
#if SCROLLCODE
curwp->w_flag |= WFHARD | WFINS;
#else
@@ -311,8 +326,7 @@ int backpage(int f, int n)
* Set the mark in the current window to the value of "." in the window. No
* errors are possible. Bound to "M-.".
*/
int setmark(int f, int n)
{
boolean setmark( int f, int n) {
curwp->w_markp = curwp->w_dotp;
curwp->w_marko = curwp->w_doto;
mloutstr( "(Mark set)") ;
@@ -321,13 +335,12 @@ int setmark(int f, int n)
/*
* Swap the values of "." and "mark" in the current window. This is pretty
* easy, bacause all of the hard work gets done by the standard routine
* easy, because all of the hard work gets done by the standard routine
* that moves the mark about. The only possible error is "no mark". Bound to
* "C-X C-X".
*/
int swapmark(int f, int n)
{
struct line *odotp;
boolean swapmark( int f, int n) {
line_p odotp ;
int odoto;
if( curwp->w_markp == NULL) {
@@ -344,3 +357,5 @@ int swapmark(int f, int n)
curwp->w_flag |= WFMOVE;
return TRUE;
}
/* end of basic.c */

37
basic.h
View File

@@ -1,20 +1,35 @@
/* basic.h -- basic commands for cursor movement in active window */
#ifndef _BASIC_H_
#define _BASIC_H_
#include "retcode.h"
/*
** $overlap is the size of the line overlap when kbd calls page forw/back
** if 0, page will move by 2/3 of the window size (1/3 page overlap)
** default to 0
*/
#define DEFAULT_OVERLAP 0
extern int overlap ; /* line overlap in forw/back page */
extern int curgoal ; /* Goal for C-P, C-N */
int gotobol( int f, int n) ;
int gotoeol( int f, int n) ;
/* $target (== curgoal) is the column target when doing line move */
extern int curgoal ; /* Goal for C-P previous-line, C-N next-line */
boolean gotobol( int f, int n) ;
boolean gotoeol( int f, int n) ;
int gotoline( int f, int n) ;
int gotobob( int f, int n) ;
int gotoeob( int f, int n) ;
int forwline( int f, int n) ;
int backline( int f, int n) ;
int forwpage( int f, int n) ;
int backpage( int f, int n) ;
int setmark( int f, int n) ;
int swapmark( int f, int n) ;
boolean gotobob( int f, int n) ;
boolean gotoeob( int f, int n) ;
boolean forwline( int f, int n) ;
boolean backline( int f, int n) ;
boolean forwpage( int f, int n) ;
boolean backpage( int f, int n) ;
boolean setmark( int f, int n) ;
boolean swapmark( int f, int n) ;
#endif
/* end of basic.h */

117
buffer.c
View File

@@ -36,9 +36,6 @@ const char *modename[] = { /* name of modes */
int gmode = 0 ; /* global editor mode */
static const char modecode[] = "WCEVOMAUD" ; /* letters to represent modes */
static int makelist( int iflag) ;
static int addline( char *text) ;
static void l_to_a( char *buf, int width, long num) ;
@@ -272,12 +269,13 @@ ask:
int listbuffers(int f, int n)
{
struct window *wp;
struct buffer *bp;
int s;
if ((s = makelist(f)) != TRUE)
return s;
if (blistp->b_nwnd == 0) { /* Not on screen yet. */
struct buffer *bp ;
if ((wp = wpopup()) == NULL)
return FALSE;
bp = wp->w_bufp;
@@ -322,90 +320,77 @@ int listbuffers(int f, int n)
*/
#define FNAMSTART (3 + 1 + NUMMODES + 10 + 1 + (sizeof( bname_t) - 1) + 1)
static void do_layout( char *line, int mode) {
int i ;
/* build line to report global mode settings */
strcpy( line, " WCEVOMAUD Global Modes") ;
/* output the mode codes */
for( i = 0 ; i < NUMMODES ; i++)
if( 0 == (mode & (1 << i)))
line[ 4 + i] = '.' ;
}
static int makelist( int iflag)
{
char *cp1;
char *cp2;
int c;
struct buffer *bp;
struct line *lp;
int s;
int i;
long nbytes; /* # of bytes in current buffer */
long nlines ; /* # of lines in current buffer */
char line[ FNAMSTART + sizeof( fname_t)] ;
blistp->b_flag &= ~BFCHG; /* Don't complain! */
blistp->b_flag &= ~BFCHG; /* Don't complain! Mute bclear() */
if ((s = bclear(blistp)) != TRUE) /* Blow old text away */
return s;
blistp->b_fname[ 0] = 0 ;
blistp->b_fname[ 0] = 0 ; /* in case of user override */
if( addline("ACT MODES Size Buffer File") == FALSE
|| addline("‾‾‾ ‾‾‾‾‾ ‾‾‾‾ ‾‾‾‾‾‾ ‾‾‾‾") == FALSE)
return FALSE;
/* build line to report global mode settings */
strcpy( line, " ") ;
cp1 = &line[ 4] ;
/* report global mode settings */
do_layout( line, gmode) ;
if( addline( line) == FALSE)
return FALSE ;
/* output the mode codes */
for (i = 0; i < NUMMODES; i++)
if (gmode & (1 << i))
*cp1++ = modecode[i];
else
*cp1++ = '.';
strcpy(cp1, " Global Modes");
if (addline(line) == FALSE)
return FALSE;
/* output the list of buffers */
/* output the list of buffers */
for( bp = bheadp ; bp != NULL ; bp = bp->b_bufp) { /* For all buffers */
/* skip invisible buffers if iflag is false */
char *cp1, *cp2 ;
int c ;
struct line *lp ;
long nbytes ; /* # of bytes in current buffer */
long nlines ; /* # of lines in current buffer */
/* skip invisible buffers if iflag is false */
if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE))
continue;
cp1 = &line[0]; /* Start at left edge */
do_layout( line, bp->b_mode) ;
cp1 = line ; /* Start at left edge */
/* output status of ACTIVE flag ('@' when the file has been read in) */
/* output status of ACTIVE flag ('@' when the file has been read in) */
*cp1++ = (bp->b_active == TRUE) ? '@' : ' ' ;
/* report if the file is truncated */
/* report if the file is truncated */
*cp1++ = ((bp->b_flag & BFTRUNC) != 0) ? '#' : ' ' ;
/* output status of changed flag ('*' when the buffer is changed) */
*cp1++ = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ' ;
*cp1++ = ' '; /* space */
/* output the mode codes */
for (i = 0; i < NUMMODES; i++) {
if (bp->b_mode & (1 << i))
*cp1++ = modecode[i];
else
*cp1++ = '.';
}
/* No gap as buffer size is left-padded with space */
/* output status of changed flag ('*' when the buffer is changed) */
*cp1 = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ' ;
/* Buffer size */
nbytes = 0L; /* Count bytes in buf. */
nlines = 0 ;
lp = lforw(bp->b_linep);
while (lp != bp->b_linep) {
for( lp = lforw( bp->b_linep) ; lp != bp->b_linep ; lp = lforw( lp)) {
nbytes += (long) llength(lp) + 1L;
nlines += 1 ;
lp = lforw(lp);
}
if( bp->b_mode & MDDOS)
nbytes += nlines ;
l_to_a( cp1, 10 + 1, nbytes) ; /* "%10d" formatted numbers */
cp1 += 10 ;
*cp1++ = ' '; /* Gap. */
l_to_a( &line[ 13], 10 + 1, nbytes) ; /* "%10d" formatted numbers */
cp1 = &line[ 23] ;
*cp1++ = ' ' ;
cp2 = &bp->b_bname[0]; /* Buffer name */
while ((c = *cp2++) != 0)
*cp1++ = c;
@@ -499,15 +484,12 @@ int anycb(void)
struct buffer *bfind( const char *bname, int cflag, int bflag)
{
struct buffer *bp;
struct buffer *sb; /* buffer to insert after */
struct line *lp;
bp = bheadp;
while (bp != NULL) {
if (strcmp(bname, bp->b_bname) == 0)
return bp;
bp = bp->b_bufp;
}
for( bp = bheadp ; bp != NULL ; bp = bp->b_bufp)
if( strcmp( bname, bp->b_bname) == 0)
return bp ;
if (cflag != FALSE) {
if ((bp = (struct buffer *)malloc(sizeof(struct buffer))) == NULL)
return NULL;
@@ -521,16 +503,15 @@ struct buffer *bfind( const char *bname, int cflag, int bflag)
bp->b_bufp = bheadp;
bheadp = bp;
} else {
sb = bheadp;
while (sb->b_bufp != NULL) {
if (strcmp(sb->b_bufp->b_bname, bname) > 0)
break;
sb = sb->b_bufp;
}
struct buffer *sb; /* buffer to insert after */
for( sb = bheadp ; sb->b_bufp != NULL ; sb = sb->b_bufp)
if( strcmp( sb->b_bufp->b_bname, bname) > 0)
break ;
/* and insert it */
bp->b_bufp = sb->b_bufp;
sb->b_bufp = bp;
bp->b_bufp = sb->b_bufp ;
sb->b_bufp = bp ;
}
/* and set up the other buffer fields */

View File

@@ -15,10 +15,10 @@
#define NSTRING 128 /* # of bytes, string buffers */
#define CONTROL 0x10000000 /* Control flag, or'ed in */
#define META 0x20000000 /* Meta flag, or'ed in */
#define CTLX 0x40000000 /* ^X flag, or'ed in */
#define SPEC 0x80000000 /* special key (function keys) */
#define CONTROL 0x01000000 /* Control flag, or'ed in */
#define META 0x02000000 /* Meta flag, or'ed in */
#define CTLX 0x04000000 /* ^X flag, or'ed in */
#define SPEC 0x08000000 /* special key (function keys) */
/* Actual 380x134 on a 1920x1080 screen in landscape,
if smaller font or portrait orientation limit to 400x150 */

View File

@@ -1284,7 +1284,7 @@ void mlerase( void) {
TTflush() ;
}
static void mlputc( char c) {
static void mlputc( unicode_t c) {
if( ttcol < term.t_ncol) {
TTputc( c) ;
++ttcol ;
@@ -1297,9 +1297,11 @@ static void mlputc( char c) {
* char *s; string to output
*/
void ostring( char *s) {
unsigned char c ;
if( discmd)
while( *s)
mlputc( *s++ & 0xFF) ;
while( (c = *s++) != 0)
mlputc( c) ;
}
@@ -1333,12 +1335,14 @@ void vmlwrite( const char *fmt, va_list ap) {
movecursor( term.t_nrow, 0) ;
mpresf = *fmt ? TRUE : FALSE ; /* flag if line has content or not */
while ((c = *fmt++) != 0) {
if (c != '%')
while( ( c = *fmt++) != 0)
if( c != '%')
mlputc( c) ;
else {
c = *fmt++;
switch (c) {
else if( ( c = *fmt++) == 0) {
mlputc( '%') ;
break ;
} else
switch( c) {
case 'd':
mlputi(va_arg(ap, int), 10);
break;
@@ -1369,11 +1373,10 @@ void vmlwrite( const char *fmt, va_list ap) {
default:
mlputc( '%') ;
/* fallthrough */
case '%':
mlputc( c) ;
}
}
}
/* if we can, erase to the end of screen */
if( eolexist == TRUE && ttcol < term.t_ncol)
@@ -1551,7 +1554,7 @@ static int newscreensize(int h, int w)
*
* char c ; character to output
*/
void echoc( char c) {
void echoc( unicode_t c) {
if( disinp)
TTputc( c) ;
}

View File

@@ -4,6 +4,7 @@
#include <stdarg.h>
#include "estruct.h"
#include "utf8.h"
extern int mpresf ; /* Stuff in message line */
extern int scrollcount ; /* number of lines to scroll */
@@ -28,7 +29,7 @@ void mlerase( void) ;
void vmlwrite( const char *fmt, va_list ap) ;
void mlwrite( const char *fmt, ...) ;
void ostring( char *s) ;
void echoc( char c) ;
void echoc( unicode_t c) ;
void echos( char *s) ;
void getscreensize( int *widthp, int *heightp) ;

72
ebind.c
View File

@@ -35,17 +35,17 @@
* control-X commands.
*/
struct key_tab keytab[NBINDS] = {
{CONTROL | 'A', gotobol}
{CONTROL | 'A', (fn_t) gotobol}
,
{CONTROL | 'B', backchar}
{CONTROL | 'B', (fn_t) backchar}
,
{CONTROL | 'C', insspace}
,
{CONTROL | 'D', forwdel}
,
{CONTROL | 'E', gotoeol}
{CONTROL | 'E', (fn_t) gotoeol}
,
{CONTROL | 'F', forwchar}
{CONTROL | 'F', (fn_t) forwchar}
,
{CONTROL | 'G', ctrlg}
,
@@ -61,11 +61,11 @@ struct key_tab keytab[NBINDS] = {
,
{CONTROL | 'M', insert_newline}
,
{CONTROL | 'N', forwline}
{CONTROL | 'N', (fn_t) forwline}
,
{CONTROL | 'O', openline}
,
{CONTROL | 'P', backline}
{CONTROL | 'P', (fn_t) backline}
,
{CONTROL | 'Q', quote}
,
@@ -73,11 +73,11 @@ struct key_tab keytab[NBINDS] = {
,
{CONTROL | 'S', forwsearch}
,
{CONTROL | 'T', twiddle}
{CONTROL | 'T', (fn_t) twiddle}
,
{CONTROL | 'U', unarg}
,
{CONTROL | 'V', forwpage}
{CONTROL | 'V', (fn_t) forwpage}
,
{CONTROL | 'W', killregion}
,
@@ -85,7 +85,7 @@ struct key_tab keytab[NBINDS] = {
,
{CONTROL | 'Y', yank}
,
{CONTROL | 'Z', backpage}
{CONTROL | 'Z', (fn_t) backpage}
,
{CONTROL | ']', metafn}
,
@@ -138,7 +138,7 @@ struct key_tab keytab[NBINDS] = {
,
{CTLX | CONTROL | 'W', filewrite}
,
{CTLX | CONTROL | 'X', swapmark}
{CTLX | CONTROL | 'X', (fn_t) swapmark}
,
{CTLX | CONTROL | 'Z', shrinkwind}
,
@@ -246,17 +246,17 @@ struct key_tab keytab[NBINDS] = {
#endif
{META | CONTROL | 'Z', scrnextup}
,
{META | ' ', setmark}
{META | ' ', (fn_t) setmark}
,
{META | '?', help}
,
{META | '!', reposition}
,
{META | '.', setmark}
{META | '.', (fn_t) setmark}
,
{META | '>', gotoeob}
{META | '>', (fn_t) gotoeob}
,
{META | '<', gotobob}
{META | '<', (fn_t) gotobob}
,
{META | '~', unmark}
,
@@ -307,7 +307,7 @@ struct key_tab keytab[NBINDS] = {
#endif
{META | 'U', upperword}
,
{META | 'V', backpage}
{META | 'V', (fn_t) backpage}
,
{META | 'W', copyregion}
,
@@ -323,21 +323,21 @@ struct key_tab keytab[NBINDS] = {
,
{SPEC | CONTROL | 'S', backhunt}
,
{SPEC | 71, gotobol}
{SPEC | 71, (fn_t) gotobol}
,
{SPEC | 72, backline}
{SPEC | 72, (fn_t) backline}
,
{SPEC | 73, backpage}
{SPEC | 73, (fn_t) backpage}
,
{SPEC | 75, backchar}
{SPEC | 75, (fn_t) backchar}
,
{SPEC | 77, forwchar}
{SPEC | 77, (fn_t) forwchar}
,
{SPEC | 79, gotoeol}
{SPEC | 79, (fn_t) gotoeol}
,
{SPEC | 80, forwline}
{SPEC | 80, (fn_t) forwline}
,
{SPEC | 81, forwpage}
{SPEC | 81, (fn_t) forwpage}
,
{SPEC | 82, insspace}
,
@@ -374,9 +374,9 @@ struct key_tab keytab[NBINDS] = {
{SPEC | 93, cbuf10}
,
#if PKCODE
{SPEC | 117, gotoeob}
{SPEC | 117, (fn_t) gotoeob}
,
{SPEC | 119, gotobob}
{SPEC | 119, (fn_t) gotobob}
,
{SPEC | 141, gotobop}
,
@@ -390,33 +390,33 @@ struct key_tab keytab[NBINDS] = {
#endif
#if VT220
{SPEC | '1', gotobob /* fisearch */}
{SPEC | '1', (fn_t) gotobob /* fisearch */}
, /* VT220 keys */
{SPEC | '2', yank}
,
{SPEC | '3', forwdel /* killregion */}
,
{SPEC | '4', gotoeob /* setmark */}
{SPEC | '4', (fn_t) gotoeob /* setmark */}
,
{SPEC | '5', backpage}
{SPEC | '5', (fn_t) backpage}
,
{SPEC | '6', forwpage}
{SPEC | '6', (fn_t) forwpage}
,
{SPEC | 'A', backline}
{SPEC | 'A', (fn_t) backline}
,
{SPEC | 'B', forwline}
{SPEC | 'B', (fn_t) forwline}
,
{SPEC | 'C', forwchar}
{SPEC | 'C', (fn_t) forwchar}
,
{SPEC | 'D', backchar}
{SPEC | 'D', (fn_t) backchar}
,
{SPEC | 'c', metafn}
,
{SPEC | 'd', backchar}
{SPEC | 'd', (fn_t) backchar}
,
{SPEC | 'e', forwline}
{SPEC | 'e', (fn_t) forwline}
,
{SPEC | 'f', gotobob}
{SPEC | 'f', (fn_t) gotobob}
,
{SPEC | 'h', help}
,

852
file.c

File diff suppressed because it is too large Load Diff

114
fileio.c
View File

@@ -118,57 +118,57 @@ fio_code ffputline( char *buf, int nbuf, int dosflag) {
* at the end of the file that don't have a newline present. Check for I/O
* errors too. Return status.
*/
fio_code ffgetline(void)
{
int c; /* current character read */
int i; /* current index into fline */
int lcode = FCODE_ASCII ; /* line encoding, defaults to ASCII */
fio_code ffgetline( void) {
int c ; /* current character read */
int i ; /* current index into fline */
int lcode = FCODE_ASCII ; /* line encoding, defaults to ASCII */
/* if we are at the end...return it */
if (eofflag)
return FIOEOF;
/* if we are at the end...return it */
if( eofflag)
return FIOEOF ;
/* dump fline if it ended up too big */
if (flen > NSTRING) {
free(fline);
fline = NULL;
}
/* dump fline if it ended up too big */
if( flen > NSTRING) {
free( fline) ;
fline = NULL ;
}
/* if we don't have an fline, allocate one */
if (fline == NULL)
if ((fline = malloc(flen = NSTRING)) == NULL)
return FIOMEM;
/* if we don't have an fline, allocate one */
if( fline == NULL)
if( (fline = malloc( flen = NSTRING)) == NULL)
return FIOMEM ;
/* read the line in */
i = 0;
while ((c = fgetc(ffp)) != EOF && c != '\r' && c != '\n') {
fline[i++] = c;
/* read the line in */
i = 0 ;
while( (c = fgetc( ffp)) != EOF && c != '\r' && c != '\n') {
/* if line is full, get more room */
if( i >= flen) {
char *tmpline ; /* temp storage for expanding line */
tmpline = malloc( flen + NSTRING) ;
if( tmpline == NULL)
return FIOMEM ;
memcpy( tmpline, fline, flen) ;
flen += NSTRING ;
free( fline) ;
fline = tmpline ;
}
fline[ i++] = c ;
lcode |= c ;
/* if it's longer, get more room */
if (i >= flen) {
char *tmpline; /* temp storage for expanding line */
fpayload = i ;
tmpline = malloc(flen + NSTRING) ;
if( tmpline == NULL)
return FIOMEM ;
memcpy( tmpline, fline, flen) ;
flen += NSTRING;
free(fline);
fline = tmpline;
}
}
}
fpayload = i ;
lcode &= FCODE_MASK ;
if( lcode && (fcode != FCODE_MIXED)) { /* line contains extended chars */
/* Check if consistent UTF-8 encoding */
int bytes ;
int pos = 0 ;
unicode_t uc ;
while( (pos < i) && (lcode != FCODE_MIXED)) {
unicode_t uc ;
int bytes ;
bytes = utf8_to_unicode( fline, pos, i, &uc) ;
pos += bytes ;
if( bytes > 1) /* Multi byte UTF-8 sequence */
@@ -180,26 +180,24 @@ fio_code ffgetline(void)
fcode |= lcode ;
}
/* test for any errors that may have occured */
if (c == EOF) {
if( ferror( ffp))
return FIOERR ;
/* test for any errors that may have occured */
if( c == EOF) {
if( ferror( ffp))
return FIOERR ;
if (i != 0)
eofflag = TRUE;
else
return FIOEOF;
} else if( c == '\r') {
c = fgetc( ffp) ;
if( c != '\n') {
ftype |= FTYPE_MAC ;
ungetc( c, ffp) ;
} else
ftype |= FTYPE_DOS ;
} else /* c == '\n' */
ftype |= FTYPE_UNIX ;
if( i != 0)
eofflag = TRUE ;
else
return FIOEOF ;
} else if( c == '\r') {
c = fgetc( ffp) ;
if( c != '\n') {
ftype |= FTYPE_MAC ;
ungetc( c, ffp) ;
} else
ftype |= FTYPE_DOS ;
} else /* c == '\n' */
ftype |= FTYPE_UNIX ;
/* terminate the string */
fline[i] = 0;
return FIOSUC;
return FIOSUC ;
}

View File

@@ -6,8 +6,7 @@ typedef enum {
FIOFNF, /* File I/O, file not found. */
FIOEOF, /* File I/O, end of file. */
FIOERR, /* File I/O, error. */
FIOMEM, /* File I/O, out of memory */
FIOFUN /* File I/O, eod of file/bad line */
FIOMEM /* File I/O, out of memory */
} fio_code ;
#define FTYPE_NONE 0

View File

@@ -724,7 +724,7 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
for (n = 0; n < cpos; n++) {
c = buf[n];
if ((c < ' ') && (c != '\n')) {
echos("^");
echoc( '^') ;
++ttcol;
c ^= 0x40;
}
@@ -751,7 +751,7 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
buf[cpos++] = c;
if ((c < ' ') && (c != '\n')) {
echos("^");
echoc( '^') ;
++ttcol;
c ^= 0x40;
}

149
line.c
View File

@@ -16,6 +16,7 @@
#include "line.h"
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -28,8 +29,6 @@
int tabwidth = 8 ; /* column span of a tab */
#define BLOCK_SIZE 16 /* Line block chunk size. */
static int ldelnewline( void) ;
/* The editor holds deleted text chunks in the struct kill buffer. The
@@ -92,16 +91,39 @@ char *getkill( void) {
* location. Error if you try and move out of the buffer. Set the flag if the
* line pointer for dot changes.
*/
int backchar( int f, int n) {
static unsigned utf8_revdelta( unsigned char *p, unsigned pos) {
unsigned delta = 0 ;
if( (*p & 0xC0) == 0x80) {
unsigned char c ;
c = *--p ;
if( (c & 0xE0) == 0xC0) /* valid 2 bytes unicode seq */
delta = 1 ;
else if( ((c & 0xC0) == 0x80) && (pos > 1)) {
c = *--p ;
if( (c & 0xF0) == 0xE0) /* valid 3 bytes unicode seq */
delta = 2 ;
else if( ((c & 0xC0) == 0x80) && (pos > 2))
if( (p[ -1] & 0xF8) == 0xF0) /* valid 4 bytes unicode seq */
delta = 3 ;
}
}
return delta ;
}
boolean backchar( int f, int n) {
assert( f == TRUE || (f == FALSE && n == 1)) ;
if( n < 0)
return forwchar( f, -n) ;
while( n--) {
if( curwp->w_doto == 0) {
struct line *lp ;
if( curwp->w_doto == 0) { /* at beginning of line */
line_p lp ;
lp = lback( curwp->w_dotp) ;
if( lp == curbp->b_linep)
if( lp == curbp->b_linep) /* at beginning of buffer */
return FALSE ;
curwp->w_dotp = lp ;
@@ -111,29 +133,8 @@ int backchar( int f, int n) {
unsigned pos ;
pos = curwp->w_doto -= 1 ;
if( pos > 0) {
unsigned char *p ;
p = (unsigned char *) &( (curwp->w_dotp)->l_text[ pos]) ;
if( (*p & 0xC0) == 0x80) {
unsigned char c ;
int delta = 0 ;
c = *--p ;
if( (c & 0xE0) == 0xC0) /* valid 2 bytes unicode seq */
delta = 1 ;
else if( ((c & 0xC0) == 0x80) && (pos > 1)) {
c = *--p ;
if( (c & 0xF0) == 0xE0) /* valid 3 bytes unicode seq */
delta = 2 ;
else if( ((c & 0xC0) == 0x80) && (pos > 2))
if( (p[ -1] & 0xF8) == 0xF0) /* valid 4 bytes unicode seq */
delta = 3 ;
}
curwp->w_doto -= delta ;
}
}
if( pos > 0)
curwp->w_doto -= utf8_revdelta( (unsigned char *) &( (curwp->w_dotp)->l_text[ pos]), pos) ;
}
}
@@ -146,18 +147,20 @@ int backchar( int f, int n) {
* location, and move ".". Error if you try and move off the end of the
* buffer. Set the flag if the line pointer for dot changes.
*/
int forwchar(int f, int n)
{
if (n < 0)
return backchar(f, -n);
while (n--) {
int len = llength(curwp->w_dotp);
if (curwp->w_doto == len) {
if (curwp->w_dotp == curbp->b_linep)
return FALSE;
curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_doto = 0;
curwp->w_flag |= WFMOVE;
boolean forwchar( int f, int n) {
assert( f == TRUE || (f == FALSE && n == 1)) ;
if( n < 0)
return backchar( f, -n) ;
while( n--) {
int len = llength( curwp->w_dotp) ;
if( curwp->w_doto == len) { /* at end of line */
if( curwp->w_dotp == curbp->b_linep) /* at end of buffer */
return FALSE ;
curwp->w_dotp = lforw( curwp->w_dotp) ;
curwp->w_doto = 0 ;
curwp->w_flag |= WFMOVE ;
} else {
unicode_t unc ;
unsigned bytes ;
@@ -166,7 +169,8 @@ int forwchar(int f, int n)
curwp->w_doto += bytes ;
}
}
return TRUE;
return TRUE ;
}
/*
@@ -175,21 +179,22 @@ int forwchar(int f, int n)
* a pointer to the new block, or NULL if there isn't any memory left. Print a
* message in the message line if no space.
*/
struct line *lalloc(int used)
{
struct line *lp;
int size;
line_p lalloc( int used) {
#define BLOCK_SIZE 16 /* Line block chunk size. */
line_p lp ;
int size ;
size = (used + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1);
if (size == 0) /* Assume that is an empty. */
size = BLOCK_SIZE; /* Line is for type-in. */
if ((lp = (struct line *)malloc(sizeof(struct line) + size)) == NULL) {
/* size = used + BLOCK_SIZE - used % BLOCK_SIZE ; */
size = (used + BLOCK_SIZE) & ~(BLOCK_SIZE - 1) ; /* as BLOCK_SIZE is power of 2 */
lp = (line_p) malloc( offsetof( struct line, l_text) + size) ;
if( lp == NULL)
mloutstr( "(OUT OF MEMORY)") ;
return NULL;
else {
lp->l_size = size ;
lp->l_used = used ;
}
lp->l_size = size;
lp->l_used = used;
return lp;
return lp ;
}
/*
@@ -198,8 +203,7 @@ struct line *lalloc(int used)
* might be in. Release the memory. The buffers are updated too; the magic
* conditions described in the above comments don't hold here.
*/
void lfree(struct line *lp)
{
void lfree( line_p lp) {
struct buffer *bp;
struct window *wp;
@@ -273,8 +277,6 @@ int insspace(int f, int n)
return TRUE;
}
static int linsert_byte( int n, int c) ;
/*
* linstr -- Insert a string at the current point
*/
@@ -287,7 +289,7 @@ int linstr( char *instr) {
while( (tmpc = *instr++ & 0xFF)) {
status =
(tmpc == '\n' ? lnewline() : linsert_byte( 1, tmpc)) ;
(tmpc == '\n' ? lnewline() : (int) linsert_byte( 1, tmpc)) ;
/* Insertion error? */
if( status != TRUE) {
@@ -310,8 +312,7 @@ int linstr( char *instr) {
* well, and FALSE on errors.
*/
static int linsert_byte(int n, int c)
{
boolean linsert_byte( int n, int c) {
char *cp1;
char *cp2;
struct line *lp1;
@@ -533,8 +534,8 @@ int lgetchar(unicode_t *c)
*
* If you want to delete characters, use ldelchar().
*/
int ldelchar(long n, int kflag)
{
boolean ldelchar( long n, boolean kflag) {
/* testing for read only mode is done by ldelete() */
while (n-- > 0) {
unicode_t c;
if (!ldelete(lgetchar(&c), kflag))
@@ -552,8 +553,7 @@ int ldelchar(long n, int kflag)
* long n; # of chars to delete
* int kflag; put killed text in kill buffer flag
*/
int ldelete(long n, int kflag)
{
boolean ldelete( long n, boolean kflag) {
char *cp1;
char *cp2;
struct line *dotp;
@@ -563,7 +563,8 @@ int ldelete(long n, int kflag)
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
while (n != 0) {
while( n > 0) {
dotp = curwp->w_dotp;
doto = curwp->w_doto;
if (dotp == curbp->b_linep) /* Hit end of buffer. */
@@ -620,18 +621,14 @@ int ldelete(long n, int kflag)
* getctext: grab and return a string with the text of
* the current line
*/
char *getctext(void)
{
struct line *lp; /* line to copy */
char *getctext( void) {
line_p lp ; /* line to copy */
int size; /* length of line to return */
char *sp; /* string pointer into line */
char *dp; /* string pointer into returned line */
static int rsize = 0 ;
static char *rline ; /* line to return */
/* find the contents of the current line and its length */
lp = curwp->w_dotp;
sp = lp->l_text;
size = lp->l_used;
if( size >= rsize) {
if( rsize)
@@ -646,11 +643,9 @@ char *getctext(void)
}
/* copy it across */
dp = rline;
while (size--)
*dp++ = *sp++;
*dp = 0;
return rline;
memcpy( rline, lp->l_text, size) ;
rline[ size] = 0 ;
return rline ;
}
/*

37
line.h
View File

@@ -4,23 +4,21 @@
#include "retcode.h"
#include "utf8.h"
#define NLINE 256 /* # of bytes, input line */
/*
* All text is kept in circularly linked lists of "struct line" structures. These
* begin at the header line (which is the blank line beyond the end of the
* buffer). This line is pointed to by the "struct buffer". Each line contains a the
* All text is kept in circularly linked lists of "struct line" structures.
* These begin at the header line (which is the blank line beyond the end of the
* buffer). This line is pointed to by the "struct buffer". Each line contains a
* number of bytes in the line (the "used" size), the size of the text array,
* and the text. The end of line is not stored as a byte; it's implied. Future
* additions will include update hints, and a list of marks into the line.
*/
struct line {
struct line *l_fp; /* Link to the next line */
struct line *l_bp; /* Link to the previous line */
int l_size; /* Allocated size */
int l_used; /* Used size */
char l_text[1]; /* A bunch of characters. */
};
typedef struct line {
struct line *l_fp ; /* Forward link to the next line */
struct line *l_bp ; /* Backward link to the previous line */
int l_size ; /* Allocated size */
int l_used ; /* Used size */
char l_text[ 1] ; /* A bunch of characters */
} *line_p ;
#define lforw(lp) ((lp)->l_fp)
#define lback(lp) ((lp)->l_bp)
@@ -28,28 +26,29 @@ struct line {
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
#define llength(lp) ((lp)->l_used)
extern int tabwidth ;
extern int tabwidth ; /* Map to $tab, default to 8, can be set to [1, .. */
char *getkill( void) ;
int backchar( int f, int n) ;
int forwchar( int f, int n) ;
boolean backchar( int f, int n) ;
boolean forwchar( int f, int n) ;
void lfree( struct line *lp) ;
void lfree( line_p lp) ;
void lchange( int flag) ;
int insspace( int f, int n) ;
int linstr( char *instr) ;
int linsert( int n, unicode_t c) ;
boolean linsert_byte( int n, int c) ;
int lover( char *ostr) ;
int lnewline( void) ;
int ldelete( long n, int kflag) ;
int ldelchar( long n, int kflag) ;
boolean ldelete( long n, boolean kflag) ;
boolean ldelchar( long n, boolean kflag) ;
int lgetchar( unicode_t *) ;
char *getctext( void) ;
void kdelete( void) ;
int kinsert( int c) ;
int yank( int f, int n) ;
struct line *lalloc( int) ; /* Allocate a line. */
line_p lalloc( int minsize) ; /* Allocate a line of at least minsize chars. */
boolean rdonly( void) ; /* Read Only error message */

15
main.c
View File

@@ -297,12 +297,8 @@ int main(int argc, char **argv)
/* if invoked with no other startup files,
run the system startup file here */
if( startflag == FALSE) {
if( startup( "") != TRUE)
mloutstr( "Default startup failed!") ;
startflag = TRUE ;
}
if( (startflag == FALSE) && (startup( "") != TRUE))
mloutstr( "Default startup failed!") ;
discmd = TRUE; /* P.K. */
@@ -347,10 +343,9 @@ static void edinit(char *bname)
struct buffer *bp;
struct window *wp;
bp = bfind(bname, TRUE, 0); /* First buffer */
blistp = bfind("*List*", TRUE, BFINVS); /* Buffer list buffer */
wp = (struct window *)malloc(sizeof(struct window)); /* First window */
if (bp == NULL || wp == NULL || blistp == NULL) {
if( NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */
|| NULL == (blistp = bfind( "*List*", TRUE, BFINVS)) /* Buffer list buffer */
|| NULL == (wp = (struct window *) malloc( sizeof( struct window)))) { /* First window */
fputs( "First initialisation failed!\n", stderr) ;
exit( EXIT_FAILURE) ;
}

26
names.c
View File

@@ -34,10 +34,10 @@ struct name_bind names[] = {
#if APROP
{"apropos", apro},
#endif
{"backward-character", backchar},
{"backward-character", (fn_t) backchar},
{"begin-macro", ctlxlp},
{"beginning-of-file", gotobob},
{"beginning-of-line", gotobol},
{"beginning-of-file", (fn_t) gotobob},
{"beginning-of-line", (fn_t) gotobol},
{"bind-to-key", bindtokey},
{"buffer-position", showcpos},
{"case-region-lower", lowerregion},
@@ -71,12 +71,12 @@ struct name_bind names[] = {
{"detab-line", detab},
#endif
{"end-macro", ctlxrp},
{"end-of-file", gotoeob},
{"end-of-line", gotoeol},
{"end-of-file", (fn_t) gotoeob},
{"end-of-line", (fn_t) gotoeol},
#if AEDIT
{"entab-line", entab},
#endif
{"exchange-point-and-mark", swapmark},
{"exchange-point-and-mark", (fn_t) swapmark},
{"execute-buffer", execbuf},
{"execute-command-line", execcmd},
{"execute-file", execfile},
@@ -132,7 +132,7 @@ struct name_bind names[] = {
#endif
{"filter-buffer", filter_buffer},
{"find-file", filefind},
{"forward-character", forwchar},
{"forward-character", (fn_t) forwchar},
{"goto-line", gotoline},
#if CFENCE
{"goto-matching-fence", getfence},
@@ -165,8 +165,8 @@ struct name_bind names[] = {
{"newline", insert_newline},
{"newline-and-indent", indent},
{"next-buffer", nextbuffer},
{"next-line", forwline},
{"next-page", forwpage},
{"next-line", (fn_t) forwline},
{"next-page", (fn_t) forwpage},
#if WORDPRO
{"next-paragraph", gotoeop},
#endif
@@ -176,8 +176,8 @@ struct name_bind names[] = {
{"open-line", openline},
{"overwrite-string", ovstring},
{"pipe-command", pipecmd},
{"previous-line", backline},
{"previous-page", backpage},
{"previous-line", (fn_t) backline},
{"previous-page", (fn_t) backpage},
#if WORDPRO
{"previous-paragraph", gotobop},
#endif
@@ -206,7 +206,7 @@ struct name_bind names[] = {
{"select-buffer", usebuffer},
{"set", setvar},
{"set-fill-column", setfillcol},
{"set-mark", setmark},
{"set-mark", (fn_t) setmark},
{"shell-command", spawn},
{"shrink-window", shrinkwind},
{"split-current-window", splitwind},
@@ -217,7 +217,7 @@ struct name_bind names[] = {
#if BSD | __hpux | SVR4
{"suspend-emacs", bktoshell},
#endif
{"transpose-characters", twiddle},
{"transpose-characters", (fn_t) twiddle},
#if AEDIT
{"trim-line", trim},
#endif

View File

@@ -119,8 +119,7 @@ void ttclose(void)
* On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
* MS-DOS (use the very very raw console output routine).
*/
int ttputc(int c)
{
int ttputc( unicode_t c) {
char utf8[6];
int bytes;

167
random.c
View File

@@ -81,9 +81,6 @@ int showcpos(int f, int n)
int savepos; /* temp save for current offset */
int ecol; /* column pos/end of current line */
/* starting at the beginning of the buffer */
lp = lforw(curbp->b_linep);
/* start counting chars and lines */
numchars = 0;
numlines = 0;
@@ -91,7 +88,7 @@ int showcpos(int f, int n)
predlines = 0;
curchar = 0;
bytes = 1 ;
while (lp != curbp->b_linep) {
for( lp = lforw( curbp->b_linep) ; lp != curbp->b_linep ; lp = lforw( lp)) {
/* if we are on the current line, record it */
if (lp == curwp->w_dotp) {
int len ;
@@ -107,7 +104,6 @@ int showcpos(int f, int n)
/* on to the next line */
++numlines;
numchars += llength( lp) + ((curbp->b_mode & MDDOS) ? 2 : 1) ;
lp = lforw(lp);
}
/* if at end of file, record it */
@@ -195,7 +191,6 @@ int getccol(int bflg)
*/
int setccol(int pos)
{
int c; /* character being scanned */
int i; /* index into current line */
int col; /* current cursor column */
int llen; /* length of line in bytes */
@@ -205,6 +200,8 @@ int setccol(int pos)
/* scan the line until we are at or past the target column */
for (i = 0; i < llen; ++i) {
int c; /* character being scanned */
/* upon reaching the target, drop out */
if (col >= pos)
break;
@@ -222,7 +219,7 @@ int setccol(int pos)
/* set us at the new position */
curwp->w_doto = i;
/* and tell weather we made it */
/* and tell whether we made it */
return col >= pos;
}
@@ -233,27 +230,36 @@ int setccol(int pos)
* work. This fixes up a very common typo with a single stroke. Normally bound
* to "C-T". This always works within a line, so "WFEDIT" is good enough.
*/
int twiddle(int f, int n)
{
struct line *dotp;
int doto;
int cl;
int cr;
boolean twiddle( int f, int n) {
unicode_t c ;
int len ;
boolean eof_f = FALSE ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
dotp = curwp->w_dotp;
doto = curwp->w_doto;
if (doto == llength(dotp) && --doto < 0)
return FALSE;
cr = lgetc(dotp, doto);
if (--doto < 0)
return FALSE;
cl = lgetc(dotp, doto);
lputc(dotp, doto + 0, cr);
lputc(dotp, doto + 1, cl);
lchange(WFEDIT);
return TRUE;
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
len = llength( curwp->w_dotp) ;
if( len < 2 || curwp->w_doto == 0) /* at least 2 chars & not bol */
return FALSE ;
if( curwp->w_doto == len) { /* at end of line */
backchar( FALSE, 1) ;
eof_f = TRUE ;
}
len = lgetchar( &c) ; /* len => unicode or extended ASCII */
ldelchar( 1, FALSE) ;
backchar( FALSE, 1) ;
if( len == 1)
linsert_byte( 1, c) ;
else
linsert( 1, c) ;
if( eof_f == TRUE)
forwchar( FALSE, 1) ;
lchange( WFEDIT) ;
return TRUE ;
}
/*
@@ -264,7 +270,6 @@ int twiddle(int f, int n)
*/
int quote(int f, int n)
{
int s;
int c;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
@@ -275,6 +280,8 @@ int quote(int f, int n)
if (n == 0)
return TRUE;
if (c == '\n') {
int s ;
do {
s = lnewline();
} while (s == TRUE && --n);
@@ -331,22 +338,27 @@ int detab(int f, int n)
/* detab the entire current line */
while (curwp->w_doto < llength(curwp->w_dotp)) {
/* if we have a tab */
if (lgetc(curwp->w_dotp, curwp->w_doto) == '\t') {
ldelchar(1, FALSE);
insspace( TRUE, tabwidth - curwp->w_doto % tabwidth);
}
if( curwbyte() == '\t') {
int size ;
forwchar(FALSE, 1);
ldelchar( 1, FALSE) ;
size = tabwidth - curwp->w_doto % tabwidth ;
insspace( TRUE, size) ;
forwchar( TRUE, size) ;
} else
forwchar( FALSE, 1) ;
}
/* advance/or back to the next line */
forwline(TRUE, inc);
if( forwline( TRUE, inc) == FALSE)
break ;
n -= inc;
}
curwp->w_doto = 0; /* to the begining of the line */
thisflag &= ~CFCPCN; /* flag that this resets the goal column */
lchange(WFEDIT); /* yes, we have made at least an edit */
return TRUE;
return (n == 0) ? TRUE : FALSE ;
}
/*
@@ -359,9 +371,6 @@ int entab(int f, int n)
#define nextab(a) (a + tabwidth - a % tabwidth)
int inc; /* increment to next line [sgn(n)] */
int fspace; /* pointer to first space if in a run */
int ccol; /* current cursor column */
char cchar; /* current character */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
@@ -372,6 +381,9 @@ int entab(int f, int n)
/* loop thru entabbing n lines */
inc = ((n > 0) ? 1 : -1);
while (n) {
int fspace ; /* pointer to first space if in a run */
int ccol ; /* current cursor column */
curwp->w_doto = 0; /* start at the beginning */
/* entab the entire current line */
@@ -386,17 +398,14 @@ int entab(int f, int n)
/* there is a bug here dealing with mixed space/tabed
lines.......it will get fixed */
backchar(TRUE, ccol - fspace);
ldelete((long) (ccol - fspace),
FALSE);
ldelete( (long) (ccol - fspace), FALSE) ;
linsert(1, '\t');
fspace = -1;
}
}
/* get the current character */
cchar = lgetc(curwp->w_dotp, curwp->w_doto);
switch (cchar) {
switch( curwbyte()) {
case '\t': /* a tab...count em up */
ccol = nextab(ccol);
break;
@@ -410,19 +419,21 @@ int entab(int f, int n)
default: /* any other char...just count */
ccol++;
fspace = -1;
break;
}
forwchar(FALSE, 1);
}
/* advance/or back to the next line */
forwline(TRUE, inc);
if( forwline( TRUE, inc) == FALSE)
break ;
n -= inc;
}
curwp->w_doto = 0; /* to the begining of the line */
thisflag &= ~CFCPCN; /* flag that this resets the goal column */
lchange(WFEDIT); /* yes, we have made at least an edit */
return TRUE;
return (n == 0) ? TRUE : FALSE ;
}
/*
@@ -432,9 +443,6 @@ int entab(int f, int n)
*/
int trim(int f, int n)
{
struct line *lp; /* current line pointer */
int offset; /* original line offset position */
int length; /* current length */
int inc; /* increment to next line [sgn(n)] */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
@@ -446,26 +454,31 @@ int trim(int f, int n)
/* loop thru trimming n lines */
inc = ((n > 0) ? 1 : -1);
while (n) {
line_p lp ; /* current line pointer */
int offset ; /* original line offset position */
int length ; /* current length */
lp = curwp->w_dotp; /* find current line text */
offset = curwp->w_doto; /* save original offset */
length = lp->l_used; /* find current length */
/* trim the current line */
while (length > offset) {
if (lgetc(lp, length - 1) != ' ' &&
lgetc(lp, length - 1) != '\t')
break;
length--;
for( length = lp->l_used ; length > offset ; length--) {
char c = lgetc( lp, length - 1) ;
if( c != ' ' && c != '\t')
break ;
}
lp->l_used = length;
/* advance/or back to the next line */
forwline(TRUE, inc);
if( forwline( TRUE, inc) == FALSE)
break ;
n -= inc;
}
lchange(WFEDIT);
thisflag &= ~CFCPCN; /* flag that this resets the goal column */
return TRUE;
return (n == 0) ? TRUE : FALSE ;
}
#endif
@@ -671,18 +684,22 @@ int indent( int f, int n) {
* If any argument is present, it kills rather than deletes, to prevent loss
* of text if typed with a big argument. Normally bound to "C-D".
*/
int forwdel(int f, int n)
{
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return backdel(f, -n);
int forwdel( int f, int n) {
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
if( n == 0)
return TRUE ;
else if( n < 0)
return backdel( f, -n) ;
if (f != FALSE) { /* Really a kill. */
if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL;
}
return ldelchar((long) n, f);
return ldelchar( n, f != FALSE) ;
}
/*
@@ -691,22 +708,22 @@ int forwdel(int f, int n)
* forward, this actually does a kill if presented with an argument. Bound to
* both "RUBOUT" and "C-H".
*/
int backdel(int f, int n)
{
int s;
int backdel( int f, int n) {
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
if( n == 0)
return TRUE ;
else if( n < 0)
return forwdel( f, -n) ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return forwdel(f, -n);
if (f != FALSE) { /* Really a kill. */
if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL;
}
if ((s = backchar(f, n)) == TRUE)
s = ldelchar(n, f);
return s;
return backchar( f, n) && ldelchar( n, f != FALSE) ;
}
/*
@@ -968,7 +985,7 @@ int getfence(int f, int n)
/* if no eol */
if( curwp->w_doto != llength(curwp->w_dotp)) {
c = lgetc( curwp->w_dotp, curwp->w_doto) ;
c = curwbyte() ;
if( c == ch)
++count ;
else if( c == ofence)

View File

@@ -24,7 +24,7 @@ int showcpos( int f, int n) ;
int getcline( void) ;
int getccol( int bflg) ;
int setccol( int pos) ;
int twiddle( int f, int n) ;
boolean twiddle( int f, int n) ;
int quote( int f, int n) ;
int insert_tab( int f, int n) ;
#if AEDIT

View File

@@ -2,24 +2,19 @@
#define __RETCODE_H__
#ifdef FALSE
#error "FALSE shouldn't be defined"
#undef FALSE
#endif
#ifdef TRUE
#error "TRUE shouldn't be defined"
#undef TRUE
#endif
#if 0
#define FALSE 0 /* False, no, bad, etc. */
#define TRUE 1 /* True, yes, good, etc. */
#define ABORT 2 /* Death, ^G, abort, etc. */
#define FAILED 3 /* not-quite fatal false return */
#endif
typedef enum {
FALSE,
TRUE
FALSE, /* 0, false, no, bad, etc. */
TRUE /* 1, true, yes, good, etc. */
} boolean ;
#define ABORT 2
#define ABORT 2 /* 2, death, ^G, abort, etc. */
#endif

2
tcap.c
View File

@@ -370,6 +370,6 @@ static void tcapbeep(void)
static void putpad(char *str)
{
tputs(str, 1, ttputc);
tputs( str, 1, (int (*)( int)) ttputc) ;
}
#endif /* TERMCAP */

View File

@@ -4,6 +4,7 @@
#include "defines.h" /* COLOR, SCROLLCODE */
#include "retcode.h"
#include "utf8.h"
/*
* The editor communicates with the display using a high level interface. A
@@ -27,7 +28,7 @@ struct terminal {
void (*t_kopen)(void); /* Open keyboard */
void (*t_kclose)(void); /* close keyboard */
int (*t_getchar)(void); /* Get character from keyboard. */
int (*t_putchar)(int); /* Put character to display. */
int (*t_putchar)( unicode_t) ; /* Put character to display. */
void (*t_flush) (void); /* Flush output buffers. */
void (*t_move)(int, int);/* Move the cursor, origin 0. */
void (*t_eeol)(void); /* Erase to end of line. */

View File

@@ -281,7 +281,7 @@ void ttclose(void)
* On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
* MS-DOS (use the very very raw console output routine).
*/
int ttputc( int c) {
int ttputc( unicode_t c) {
#if VMS
if (nobuf >= NOBUF)
ttflush();

View File

@@ -1,6 +1,8 @@
#ifndef _TERMIO_H_
#define _TERMIO_H_
#include "utf8.h"
#define TYPEAH 1 /* type ahead causes update to be skipped */
#define HUGE 1000 /* Huge number (for row/col) */
@@ -10,7 +12,7 @@ extern int ttcol ; /* Column location of HW cursor */
void ttopen( void) ;
void ttclose( void) ;
int ttputc( int c) ;
int ttputc( unicode_t c) ;
void ttflush( void) ;
int ttgetc( void) ;
int typahead( void) ;

View File

@@ -12,6 +12,6 @@
# define PROGRAM_NAME_PFX "\xC2"
# define PROGRAM_NAME_LONG "\xB5""EMACS" /* UTF-8 µEMACS */
# define VERSION "4.2.2"
# define VERSION "4.2.3"
#endif /* VERSION_H_ */

View File

@@ -13,13 +13,13 @@
* the full blown redisplay is just too expensive to run for every input
* character.
*/
struct window {
typedef struct window {
struct window *w_wndp; /* Next window */
struct buffer *w_bufp; /* Buffer displayed in window */
struct line *w_linep; /* Top line in the window */
struct line *w_dotp; /* Line containing "." */
struct line *w_markp; /* Line containing "mark" */
int w_doto; /* Byte offset for "." */
line_p w_linep ; /* Top line in the window */
line_p w_dotp ; /* Line containing "." */
line_p w_markp ; /* Line containing "mark" */
int w_doto ; /* Byte offset for "." */
int w_marko; /* Byte offset for "mark" */
int w_toprow ; /* Origin 0 top row of window */
int w_ntrows ; /* # of rows of text in window */
@@ -29,10 +29,13 @@ struct window {
char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */
#endif
};
} *window_p ;
extern struct window *curwp ; /* Current window */
extern struct window *wheadp ; /* Head of list of windows */
extern window_p curwp ; /* Current window */
extern window_p wheadp ; /* Head of list of windows */
/* curwbyte return the byte after the dot in current window */
#define curwbyte() lgetc( curwp->w_dotp, curwp->w_doto)
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
@@ -66,6 +69,6 @@ int newsize( int f, int n) ;
int newwidth( int f, int n) ;
int getwpos( void) ;
void cknewwindow( void) ;
struct window *wpopup( void) ; /* Pop up window creation. */
window_p wpopup( void) ; /* Pop up window creation. */
#endif