diff options
-rw-r--r-- | usr.bin/mg/basic.c | 49 | ||||
-rw-r--r-- | usr.bin/mg/random.c | 20 | ||||
-rw-r--r-- | usr.bin/mg/util.c | 20 |
3 files changed, 51 insertions, 38 deletions
diff --git a/usr.bin/mg/basic.c b/usr.bin/mg/basic.c index 8c90f17054b..ca16df09b74 100644 --- a/usr.bin/mg/basic.c +++ b/usr.bin/mg/basic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: basic.c,v 1.13 2002/03/11 13:08:51 vincent Exp $ */ +/* $OpenBSD: basic.c,v 1.14 2003/05/16 19:28:59 vincent Exp $ */ /* * Basic cursor motion commands. @@ -11,7 +11,7 @@ */ #include "def.h" -void setgoal(void); +#include <ctype.h> /* * Go to beginning of line. @@ -142,7 +142,7 @@ forwline(int f, int n) if (n < 0) return backline(f | FFRAND, -n); - if ((lastflag & CFCPCN) == 0) /* Fix goal. */ + if ((lastflag & CFCPCN) == 0) /* Fix goal. */ setgoal(); thisflag |= CFCPCN; if (n == 0) @@ -188,7 +188,7 @@ backline(int f, int n) if (n < 0) return forwline(f | FFRAND, -n); - if ((lastflag & CFCPCN) == 0) /* Fix goal. */ + if ((lastflag & CFCPCN) == 0) /* Fix goal. */ setgoal(); thisflag |= CFCPCN; dlp = curwp->w_dotp; @@ -208,8 +208,7 @@ backline(int f, int n) void setgoal(void) { - - curgoal = getcolpos() - 1; /* Get the position. */ + curgoal = getcolpos(); /* Get the position. */ /* we can now display past end of display, don't chop! */ } @@ -223,31 +222,30 @@ setgoal(void) int getgoal(LINE *dlp) { - int c; - int col; - int newcol; - int dbo; - - col = 0; - dbo = 0; - while (dbo != llength(dlp)) { - c = lgetc(dlp, dbo); - newcol = col; + int c, i, col = 0; + + for (i = 0; i < llength(dlp); i++) { + c = lgetc(dlp, i); if (c == '\t' #ifdef NOTAB && !(curbp->b_flag & BFNOTAB) #endif - ) - newcol |= 0x07; - else if (ISCTRL(c) != FALSE) - ++newcol; - ++newcol; - if (newcol > curgoal) + ) { + col |= 0x07; + col++; + } else if (ISCTRL(c) != FALSE) { + col += 2; + } else if (isprint(c)) + col++; + else { + char tmp[5]; + col += snprintf(tmp, sizeof tmp, "\\%o", + c); + } + if (col > curgoal) break; - col = newcol; - ++dbo; } - return (dbo); + return (i); } /* @@ -379,7 +377,6 @@ pagenext(int f, int n) void isetmark(void) { - curwp->w_markp = curwp->w_dotp; curwp->w_marko = curwp->w_doto; } diff --git a/usr.bin/mg/random.c b/usr.bin/mg/random.c index 4f44e9cd8fe..cb9afd814fa 100644 --- a/usr.bin/mg/random.c +++ b/usr.bin/mg/random.c @@ -1,4 +1,4 @@ -/* $OpenBSD: random.c,v 1.8 2002/05/30 16:07:57 vincent Exp $ */ +/* $OpenBSD: random.c,v 1.9 2003/05/16 19:28:59 vincent Exp $ */ /* * Assorted commands. @@ -8,6 +8,7 @@ */ #include "def.h" +#include <ctype.h> /* * Display a bunch of useful information about the current location of dot. @@ -71,12 +72,12 @@ showcpos(f, n) } int -getcolpos() +getcolpos(void) { int col, i, c; /* determine column */ - col = 1; + col = 0; for (i = 0; i < curwp->w_doto; ++i) { c = lgetc(curwp->w_dotp, i); @@ -86,10 +87,17 @@ getcolpos() #endif /* NOTAB */ ) { col |= 0x07; - ++col; + col++; } else if (ISCTRL(c) != FALSE) - ++col; - ++col; + col += 2; + else if (isprint(c)) + col++; + else { + char tmp[5]; + snprintf(tmp, sizeof tmp, "\\%o", c); + col += strlen(tmp); + } + } return col; } diff --git a/usr.bin/mg/util.c b/usr.bin/mg/util.c index c4f5fdfdc03..ee5a872d0b1 100644 --- a/usr.bin/mg/util.c +++ b/usr.bin/mg/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.8 2002/05/30 16:07:57 vincent Exp $ */ +/* $OpenBSD: util.c,v 1.9 2003/05/16 19:28:59 vincent Exp $ */ /* * Assorted commands. @@ -8,6 +8,7 @@ */ #include "def.h" +#include <ctype.h> /* * Display a bunch of useful information about the current location of dot. @@ -71,12 +72,12 @@ showcpos(f, n) } int -getcolpos() +getcolpos(void) { int col, i, c; /* determine column */ - col = 1; + col = 0; for (i = 0; i < curwp->w_doto; ++i) { c = lgetc(curwp->w_dotp, i); @@ -86,10 +87,17 @@ getcolpos() #endif /* NOTAB */ ) { col |= 0x07; - ++col; + col++; } else if (ISCTRL(c) != FALSE) - ++col; - ++col; + col += 2; + else if (isprint(c)) + col++; + else { + char tmp[5]; + snprintf(tmp, sizeof tmp, "\\%o", c); + col += strlen(tmp); + } + } return col; } |