diff --git a/Makefile b/Makefile index 58377ae..b1f3f6f 100644 --- a/Makefile +++ b/Makefile @@ -155,7 +155,7 @@ input.o: input.c input.h edef.h estruct.h line.h utf8.h bind.h bindable.h \ display.h exec.h names.h wrapper.h isearch.o: isearch.c isearch.h basic.h display.h estruct.h line.h utf8.h \ edef.h input.h search.h -line.o: line.c line.h utf8.h basic.h display.h estruct.h edef.h random.h +line.o: line.c line.h utf8.h display.h estruct.h edef.h lock.o: lock.c lock.h estruct.h line.h utf8.h display.h edef.h input.h main.o: main.c basic.h bind.h edef.h estruct.h line.h utf8.h bindable.h \ buffer.h display.h eval.h execute.h file.h input.h lock.h random.h \ diff --git a/basic.c b/basic.c index 3705fd7..73bc4c7 100644 --- a/basic.c +++ b/basic.c @@ -69,38 +69,6 @@ int gotobol(int f, int n) return TRUE; } -/* - * Move the cursor backwards by "n" characters. If "n" is less than zero call - * "forwchar" to actually do the move. Otherwise compute the new cursor - * 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) -{ - struct line *lp; - - if (n < 0) - return forwchar(f, -n); - while (n--) { - if (curwp->w_doto == 0) { - if ((lp = lback(curwp->w_dotp)) == curbp->b_linep) - return FALSE; - curwp->w_dotp = lp; - curwp->w_doto = llength(lp); - curwp->w_flag |= WFMOVE; - } else { - do { - unsigned char c; - curwp->w_doto--; - c = lgetc(curwp->w_dotp, curwp->w_doto); - if (is_beginning_utf8(c)) - break; - } while (curwp->w_doto); - } - } - return TRUE; -} - /* * Move the cursor to the end of the current line. Trivial. No errors. */ @@ -110,37 +78,6 @@ int gotoeol(int f, int n) return TRUE; } -/* - * Move the cursor forwards by "n" characters. If "n" is less than zero call - * "backchar" to actually do the move. Otherwise compute the new cursor - * 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; - } else { - do { - unsigned char c; - curwp->w_doto++; - c = lgetc(curwp->w_dotp, curwp->w_doto); - if (is_beginning_utf8(c)) - break; - } while (curwp->w_doto < len); - } - } - return TRUE; -} - /* * Move to a particular line. * diff --git a/basic.h b/basic.h index cea1767..8ebbeea 100644 --- a/basic.h +++ b/basic.h @@ -2,9 +2,7 @@ #define _BASIC_H_ int gotobol( int f, int n) ; -int backchar( int f, int n) ; int gotoeol( int f, int n) ; -int forwchar( int f, int n) ; int gotoline( int f, int n) ; int gotobob( int f, int n) ; int gotoeob( int f, int n) ; diff --git a/eval.c b/eval.c index 2beff5a..5aee669 100644 --- a/eval.c +++ b/eval.c @@ -229,6 +229,31 @@ static struct { /* User variables */ static struct user_variable uv[MAXVARS + 1]; + +/* + * putctext: + * replace the current line with the passed in text + * + * char *iline; contents of new line + */ +static int putctext( char *iline) +{ + int status; + + /* delete the current line */ + curwp->w_doto = 0; /* starting at the beginning of the line */ + if ((status = killtext(TRUE, 1)) != TRUE) + return status; + + /* insert the new line */ + if ((status = linstr(iline)) != TRUE) + return status; + status = lnewline(); + backline(TRUE, 1); + return status; +} + + /* Initialize the user variable list. */ void varinit(void) { diff --git a/line.c b/line.c index 04b0079..556f6f4 100644 --- a/line.c +++ b/line.c @@ -17,17 +17,78 @@ #include -#include "basic.h" #include "display.h" #include "estruct.h" #include "edef.h" -#include "random.h" #include "utf8.h" #define BLOCK_SIZE 16 /* Line block chunk size. */ static int ldelnewline( void) ; +/* + * Move the cursor backwards by "n" characters. If "n" is less than zero call + * "forwchar" to actually do the move. Otherwise compute the new cursor + * 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) +{ + struct line *lp; + + if (n < 0) + return forwchar(f, -n); + while (n--) { + if (curwp->w_doto == 0) { + if ((lp = lback(curwp->w_dotp)) == curbp->b_linep) + return FALSE; + curwp->w_dotp = lp; + curwp->w_doto = llength(lp); + curwp->w_flag |= WFMOVE; + } else { + do { + unsigned char c; + curwp->w_doto--; + c = lgetc(curwp->w_dotp, curwp->w_doto); + if (is_beginning_utf8(c)) + break; + } while (curwp->w_doto); + } + } + return TRUE; +} + +/* + * Move the cursor forwards by "n" characters. If "n" is less than zero call + * "backchar" to actually do the move. Otherwise compute the new cursor + * 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; + } else { + do { + unsigned char c; + curwp->w_doto++; + c = lgetc(curwp->w_dotp, curwp->w_doto); + if (is_beginning_utf8(c)) + break; + } while (curwp->w_doto < len); + } + } + return TRUE; +} + /* * This routine allocates a block of memory large enough to hold a struct line * containing "used" characters. The block is always rounded up a bit. Return @@ -485,29 +546,6 @@ char *getctext(void) return rline; } -/* - * putctext: - * replace the current line with the passed in text - * - * char *iline; contents of new line - */ -int putctext(char *iline) -{ - int status; - - /* delete the current line */ - curwp->w_doto = 0; /* starting at the beginning of the line */ - if ((status = killtext(TRUE, 1)) != TRUE) - return status; - - /* insert the new line */ - if ((status = linstr(iline)) != TRUE) - return status; - status = lnewline(); - backline(TRUE, 1); - return status; -} - /* * Delete a newline. Join the current line with the next line. If the next line * is the magic header line always return TRUE; merging the last line with the diff --git a/line.h b/line.h index d649ee7..248adb3 100644 --- a/line.h +++ b/line.h @@ -25,6 +25,9 @@ struct line { #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c)) #define llength(lp) ((lp)->l_used) +int backchar( int f, int n) ; +int forwchar( int f, int n) ; + void lfree( struct line *lp) ; void lchange( int flag) ; int insspace( int f, int n) ; @@ -36,7 +39,6 @@ int ldelete( long n, int kflag) ; int ldelchar( long n, int kflag) ; int lgetchar( unicode_t *) ; char *getctext( void) ; -int putctext( char *iline) ; void kdelete( void) ; int kinsert( int c) ; int yank( int f, int n) ;