aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Slaven <bpk@hoopajoo.net>2007-10-10 16:25:56 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2007-10-10 16:25:56 (GMT)
commit56fb3a3c0f63df83c276e345f1ec5fbc69f67390 (patch)
tree67687523b0cbaaad4b1bad5248517cab9d5a22c7
parent8467502c4dd8a4f8e807a41de17ca9bc52f42912 (diff)
downloadpowwow-56fb3a3c0f63df83c276e345f1ec5fbc69f67390.zip
powwow-56fb3a3c0f63df83c276e345f1ec5fbc69f67390.tar.gz
powwow-56fb3a3c0f63df83c276e345f1ec5fbc69f67390.tar.bz2
Switched to using pointers to save the last space because counters could be
off if there were ansi sequences
-rw-r--r--utils.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/utils.c b/utils.c
index 82a3e3c..06018d7 100644
--- a/utils.c
+++ b/utils.c
@@ -502,11 +502,12 @@ ptr ptraddmarks __P2 (ptr,dst, ptr,line)
*/
static void wrap_print __P1 (char *,s)
{
- char *p, c, follow = 1;
+ /* ls = last space in *s, lp = last space in *p */
+ char *ls, *lp, *p, c, follow = 1;
char buf[BUFSIZE]; /* ASSERT(cols<BUFSIZE) */
- /* l = left, m = current offset, ls = last space */
- int l, m, ls;
+ /* l = left, m = current offset */
+ int l, m;
enum { NORM, ESCAPE, BRACKET } state;
#ifdef BUG_ANSI
int ansibug = 0;
@@ -519,7 +520,8 @@ static void wrap_print __P1 (char *,s)
#endif
while (l >= cols_1 - col0) {
- p = buf; m = 0; state = NORM; ls = 0;
+ p = buf; m = 0; state = NORM;
+ lp = ls = NULL;
/* this scans over the remaining part of the line adding stuff to
* print to the buffer and tallying the length of displayed
@@ -529,7 +531,8 @@ static void wrap_print __P1 (char *,s)
switch (state) {
case NORM:
if (c == ' ') {
- ls = m;
+ ls = s;
+ lp = p;
}
if (c == '\033') {
@@ -538,7 +541,7 @@ static void wrap_print __P1 (char *,s)
/* if char is hi (128+) or printable */
m++, l--;
}else if (c == '\r') {
- ls = 0;
+ ls = lp = NULL;
m = 0;
}
@@ -556,10 +559,11 @@ static void wrap_print __P1 (char *,s)
}
/* Adjust offsets and stuff to last space */
- if( ls != m && ls > 0 ) {
- s -= (m - ls);
- s++;
- buf[ ls ] = 0;
+ if( ls != NULL && ls != s ) {
+ /* move s back to the last space */
+ s = ls;
+ /* null term buf[] at last space */
+ lp[ 0 ] = 0;
}
follow = *s;