mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-19 07:46:24 -05:00
Review ldelchar and ldelete.
This commit is contained in:
parent
a7c34c747d
commit
d4b2a4c1aa
10
line.c
10
line.c
@ -532,8 +532,8 @@ int lgetchar(unicode_t *c)
|
|||||||
*
|
*
|
||||||
* If you want to delete characters, use ldelchar().
|
* 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) {
|
while (n-- > 0) {
|
||||||
unicode_t c;
|
unicode_t c;
|
||||||
if (!ldelete(lgetchar(&c), kflag))
|
if (!ldelete(lgetchar(&c), kflag))
|
||||||
@ -551,8 +551,7 @@ int ldelchar(long n, int kflag)
|
|||||||
* long n; # of chars to delete
|
* long n; # of chars to delete
|
||||||
* int kflag; put killed text in kill buffer flag
|
* int kflag; put killed text in kill buffer flag
|
||||||
*/
|
*/
|
||||||
int ldelete(long n, int kflag)
|
boolean ldelete( long n, boolean kflag) {
|
||||||
{
|
|
||||||
char *cp1;
|
char *cp1;
|
||||||
char *cp2;
|
char *cp2;
|
||||||
struct line *dotp;
|
struct line *dotp;
|
||||||
@ -562,7 +561,8 @@ int ldelete(long n, int kflag)
|
|||||||
|
|
||||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||||
return rdonly(); /* we are in read only mode */
|
return rdonly(); /* we are in read only mode */
|
||||||
while (n != 0) {
|
|
||||||
|
while( n > 0) {
|
||||||
dotp = curwp->w_dotp;
|
dotp = curwp->w_dotp;
|
||||||
doto = curwp->w_doto;
|
doto = curwp->w_doto;
|
||||||
if (dotp == curbp->b_linep) /* Hit end of buffer. */
|
if (dotp == curbp->b_linep) /* Hit end of buffer. */
|
||||||
|
4
line.h
4
line.h
@ -40,8 +40,8 @@ int linstr( char *instr) ;
|
|||||||
int linsert( int n, unicode_t c) ;
|
int linsert( int n, unicode_t c) ;
|
||||||
int lover( char *ostr) ;
|
int lover( char *ostr) ;
|
||||||
int lnewline( void) ;
|
int lnewline( void) ;
|
||||||
int ldelete( long n, int kflag) ;
|
boolean ldelete( long n, boolean kflag) ;
|
||||||
int ldelchar( long n, int kflag) ;
|
boolean ldelchar( long n, boolean kflag) ;
|
||||||
int lgetchar( unicode_t *) ;
|
int lgetchar( unicode_t *) ;
|
||||||
char *getctext( void) ;
|
char *getctext( void) ;
|
||||||
void kdelete( void) ;
|
void kdelete( void) ;
|
||||||
|
65
random.c
65
random.c
@ -191,7 +191,6 @@ int getccol(int bflg)
|
|||||||
*/
|
*/
|
||||||
int setccol(int pos)
|
int setccol(int pos)
|
||||||
{
|
{
|
||||||
int c; /* character being scanned */
|
|
||||||
int i; /* index into current line */
|
int i; /* index into current line */
|
||||||
int col; /* current cursor column */
|
int col; /* current cursor column */
|
||||||
int llen; /* length of line in bytes */
|
int llen; /* length of line in bytes */
|
||||||
@ -201,6 +200,8 @@ int setccol(int pos)
|
|||||||
|
|
||||||
/* scan the line until we are at or past the target column */
|
/* scan the line until we are at or past the target column */
|
||||||
for (i = 0; i < llen; ++i) {
|
for (i = 0; i < llen; ++i) {
|
||||||
|
int c; /* character being scanned */
|
||||||
|
|
||||||
/* upon reaching the target, drop out */
|
/* upon reaching the target, drop out */
|
||||||
if (col >= pos)
|
if (col >= pos)
|
||||||
break;
|
break;
|
||||||
@ -260,7 +261,6 @@ int twiddle(int f, int n)
|
|||||||
*/
|
*/
|
||||||
int quote(int f, int n)
|
int quote(int f, int n)
|
||||||
{
|
{
|
||||||
int s;
|
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||||
@ -271,6 +271,8 @@ int quote(int f, int n)
|
|||||||
if (n == 0)
|
if (n == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
|
int s ;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
s = lnewline();
|
s = lnewline();
|
||||||
} while (s == TRUE && --n);
|
} while (s == TRUE && --n);
|
||||||
@ -355,9 +357,6 @@ int entab(int f, int n)
|
|||||||
#define nextab(a) (a + tabwidth - a % tabwidth)
|
#define nextab(a) (a + tabwidth - a % tabwidth)
|
||||||
|
|
||||||
int inc; /* increment to next line [sgn(n)] */
|
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 */
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||||
return rdonly(); /* we are in read only mode */
|
return rdonly(); /* we are in read only mode */
|
||||||
@ -368,6 +367,9 @@ int entab(int f, int n)
|
|||||||
/* loop thru entabbing n lines */
|
/* loop thru entabbing n lines */
|
||||||
inc = ((n > 0) ? 1 : -1);
|
inc = ((n > 0) ? 1 : -1);
|
||||||
while (n) {
|
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 */
|
curwp->w_doto = 0; /* start at the beginning */
|
||||||
|
|
||||||
/* entab the entire current line */
|
/* entab the entire current line */
|
||||||
@ -382,17 +384,14 @@ int entab(int f, int n)
|
|||||||
/* there is a bug here dealing with mixed space/tabed
|
/* there is a bug here dealing with mixed space/tabed
|
||||||
lines.......it will get fixed */
|
lines.......it will get fixed */
|
||||||
backchar(TRUE, ccol - fspace);
|
backchar(TRUE, ccol - fspace);
|
||||||
ldelete((long) (ccol - fspace),
|
ldelete( (long) (ccol - fspace), FALSE) ;
|
||||||
FALSE);
|
|
||||||
linsert(1, '\t');
|
linsert(1, '\t');
|
||||||
fspace = -1;
|
fspace = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the current character */
|
/* get the current character */
|
||||||
cchar = lgetc(curwp->w_dotp, curwp->w_doto);
|
switch( lgetc( curwp->w_dotp, curwp->w_doto)) {
|
||||||
|
|
||||||
switch (cchar) {
|
|
||||||
case '\t': /* a tab...count em up */
|
case '\t': /* a tab...count em up */
|
||||||
ccol = nextab(ccol);
|
ccol = nextab(ccol);
|
||||||
break;
|
break;
|
||||||
@ -406,8 +405,8 @@ int entab(int f, int n)
|
|||||||
default: /* any other char...just count */
|
default: /* any other char...just count */
|
||||||
ccol++;
|
ccol++;
|
||||||
fspace = -1;
|
fspace = -1;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
forwchar(FALSE, 1);
|
forwchar(FALSE, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,9 +427,6 @@ int entab(int f, int n)
|
|||||||
*/
|
*/
|
||||||
int trim(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)] */
|
int inc; /* increment to next line [sgn(n)] */
|
||||||
|
|
||||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||||
@ -442,17 +438,20 @@ int trim(int f, int n)
|
|||||||
/* loop thru trimming n lines */
|
/* loop thru trimming n lines */
|
||||||
inc = ((n > 0) ? 1 : -1);
|
inc = ((n > 0) ? 1 : -1);
|
||||||
while (n) {
|
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 */
|
lp = curwp->w_dotp; /* find current line text */
|
||||||
offset = curwp->w_doto; /* save original offset */
|
offset = curwp->w_doto; /* save original offset */
|
||||||
length = lp->l_used; /* find current length */
|
|
||||||
|
|
||||||
/* trim the current line */
|
/* trim the current line */
|
||||||
while (length > offset) {
|
for( length = lp->l_used ; length > offset ; length--) {
|
||||||
if (lgetc(lp, length - 1) != ' ' &&
|
char c = lgetc( lp, length - 1) ;
|
||||||
lgetc(lp, length - 1) != '\t')
|
if( c != ' ' && c != '\t')
|
||||||
break ;
|
break ;
|
||||||
length--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lp->l_used = length;
|
lp->l_used = length;
|
||||||
|
|
||||||
/* advance/or back to the next line */
|
/* advance/or back to the next line */
|
||||||
@ -667,18 +666,22 @@ int indent( int f, int n) {
|
|||||||
* If any argument is present, it kills rather than deletes, to prevent loss
|
* 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".
|
* of text if typed with a big argument. Normally bound to "C-D".
|
||||||
*/
|
*/
|
||||||
int forwdel(int f, int n)
|
int forwdel( int f, int n) {
|
||||||
{
|
|
||||||
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||||
return rdonly() ; /* we are in read only mode */
|
return rdonly() ; /* we are in read only mode */
|
||||||
if (n < 0)
|
|
||||||
|
if( n == 0)
|
||||||
|
return TRUE ;
|
||||||
|
else if( n < 0)
|
||||||
return backdel( f, -n) ;
|
return backdel( f, -n) ;
|
||||||
|
|
||||||
if (f != FALSE) { /* Really a kill. */
|
if (f != FALSE) { /* Really a kill. */
|
||||||
if ((lastflag & CFKILL) == 0)
|
if ((lastflag & CFKILL) == 0)
|
||||||
kdelete();
|
kdelete();
|
||||||
thisflag |= CFKILL;
|
thisflag |= CFKILL;
|
||||||
}
|
}
|
||||||
return ldelchar((long) n, f);
|
|
||||||
|
return ldelchar( n, f != FALSE) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -687,22 +690,22 @@ int forwdel(int f, int n)
|
|||||||
* forward, this actually does a kill if presented with an argument. Bound to
|
* forward, this actually does a kill if presented with an argument. Bound to
|
||||||
* both "RUBOUT" and "C-H".
|
* both "RUBOUT" and "C-H".
|
||||||
*/
|
*/
|
||||||
int backdel(int f, int n)
|
int backdel( int f, int n) {
|
||||||
{
|
|
||||||
int s;
|
|
||||||
|
|
||||||
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||||
return rdonly() ; /* we are in read only mode */
|
return rdonly() ; /* we are in read only mode */
|
||||||
if (n < 0)
|
|
||||||
|
if( n == 0)
|
||||||
|
return TRUE ;
|
||||||
|
else if( n < 0)
|
||||||
return forwdel( f, -n) ;
|
return forwdel( f, -n) ;
|
||||||
|
|
||||||
if (f != FALSE) { /* Really a kill. */
|
if (f != FALSE) { /* Really a kill. */
|
||||||
if ((lastflag & CFKILL) == 0)
|
if ((lastflag & CFKILL) == 0)
|
||||||
kdelete();
|
kdelete();
|
||||||
thisflag |= CFKILL;
|
thisflag |= CFKILL;
|
||||||
}
|
}
|
||||||
if ((s = backchar(f, n)) == TRUE)
|
|
||||||
s = ldelchar(n, f);
|
return (backchar( f, n) == TRUE) && ldelchar( n, f != FALSE) ;
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
15
retcode.h
15
retcode.h
@ -2,24 +2,19 @@
|
|||||||
#define __RETCODE_H__
|
#define __RETCODE_H__
|
||||||
|
|
||||||
#ifdef FALSE
|
#ifdef FALSE
|
||||||
|
#error "FALSE shouldn't be defined"
|
||||||
#undef FALSE
|
#undef FALSE
|
||||||
#endif
|
#endif
|
||||||
#ifdef TRUE
|
#ifdef TRUE
|
||||||
|
#error "TRUE shouldn't be defined"
|
||||||
#undef TRUE
|
#undef TRUE
|
||||||
#endif
|
#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 {
|
typedef enum {
|
||||||
FALSE,
|
FALSE, /* 0, false, no, bad, etc. */
|
||||||
TRUE
|
TRUE /* 1, true, yes, good, etc. */
|
||||||
} boolean ;
|
} boolean ;
|
||||||
|
|
||||||
#define ABORT 2
|
#define ABORT 2 /* 2, death, ^G, abort, etc. */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user