diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2001-05-23 15:50:28 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2001-05-23 15:50:28 +0000 |
commit | 9fc9a4c5b1362421e02277bc418447dce05c82c2 (patch) | |
tree | e07dd7a85daf70d2baf7b2a20aaebaf0d5a0f439 | |
parent | df0c95cfe406c80e777fe9008cfb404cdb8343ba (diff) |
Creatively use addlinef when listing buffers (C-X-C-B).
This also fixes the strange formatting that showed up when the maximal buffer
name grew. Now the "Size" column starts in the middle of the visible window
instead of far outside.
-rw-r--r-- | usr.bin/mg/buffer.c | 93 |
1 files changed, 19 insertions, 74 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index 3459ff9e380..c80da333497 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.10 2001/05/23 15:46:25 art Exp $ */ +/* $OpenBSD: buffer.c,v 1.11 2001/05/23 15:50:27 art Exp $ */ /* * Buffer handling. @@ -8,7 +8,6 @@ #include "kbd.h" /* needed for modes */ #include <stdarg.h> -static RSIZE itor __P((char *, int, RSIZE)); static BUFFER *makelist __P((void)); /* @@ -207,15 +206,9 @@ listbuffers(f, n) static BUFFER * makelist() { - char *cp1; - char *cp2; - int c; - BUFFER *bp; + int w = ncol / 2; + BUFFER *bp, *blp; LINE *lp; - RSIZE nbytes; - BUFFER *blp; - char b[6 + 1]; - char line[NBUFN+128]; if ((blp = bfind("*Buffer List*", TRUE)) == NULL) return NULL; @@ -223,32 +216,13 @@ makelist() return NULL; blp->b_flag &= ~BFCHG; /* Blow away old. */ - (VOID) strcpy(line, " MR Buffer"); - cp1 = line + 10; - while (cp1 < line + 4 + NBUFN + 1) - *cp1++ = ' '; - (VOID) strcpy(cp1, "Size File"); - if (addline(blp, line) == FALSE) - return NULL; - (VOID) strcpy(line, " -- ------"); - cp1 = line + 10; - while (cp1 < line + 4 + NBUFN + 1) - *cp1++ = ' '; - (VOID) strcpy(cp1, "---- ----"); - if (addline(blp, line) == FALSE) + if (addlinef(blp, "%-*s%s", w, " MR Buffer", "Size File") == FALSE || + addlinef(blp, "%-*s%s", w, " -- ------", "---- ----") == FALSE) return NULL; - bp = bheadp; /* For all buffers */ - while (bp != NULL) { - cp1 = &line[0]; /* Start at left edge */ - *cp1++ = (bp == curbp) ? '.' : ' '; - *cp1++ = ((bp->b_flag & BFCHG) != 0) ? '*' : ' '; - *cp1++ = ' '; /* Gap. */ - *cp1++ = ' '; - cp2 = &bp->b_bname[0]; /* Buffer name */ - while ((c = *cp2++) != 0) - *cp1++ = c; - while (cp1 < &line[4 + NBUFN + 1]) - *cp1++ = ' '; + + for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { + RSIZE nbytes; + nbytes = 0; /* Count bytes in buf. */ if (bp != blp) { lp = lforw(bp->b_linep); @@ -259,22 +233,17 @@ makelist() if (nbytes) nbytes--; /* no bonus newline */ } - (VOID) itor(b, 6, nbytes); /* 6 digit buffer size. */ - cp2 = &b[0]; - while ((c = *cp2++) != 0) - *cp1++ = c; - *cp1++ = ' '; /* Gap.. */ - cp2 = &bp->b_fname[0]; /* File name */ - if (*cp2 != 0) { - while ((c = *cp2++) != 0) { - if (cp1 < &line[128 - 1]) - *cp1++ = c; - } - } - *cp1 = 0; /* Add to the buffer. */ - if (addline(blp, line) == FALSE) + + if (addlinef(blp, "%c%c%c %-*s%-6d %-*s", + (bp == curbp) ? '.' : ' ', /* current buffer ? */ + ((bp->b_flag & BFCHG) != 0) ? '*' : ' ', /* changed ? */ + ' ', /* no readonly buffers yet */ + w - 4, /* four chars already written */ + bp->b_bname, /* buffer name */ + nbytes, /* buffer size */ + w - 7, /* seven chars already written */ + bp->b_fname) == FALSE) return NULL; - bp = bp->b_bufp; } blp->b_dotp = lforw(blp->b_linep); /* put dot at beginning of * buffer */ @@ -283,30 +252,6 @@ makelist() } /* - * Used above. - */ -static RSIZE -itor(buf, width, num) - char *buf; - int width; - RSIZE num; -{ - RSIZE r; - - if (num / 10 == 0) { - buf[0] = (num % 10) + '0'; - for (r = 1; r < width; buf[r++] = ' '); - buf[width] = '\0'; - return 1; - } else { - buf[r = itor(buf, width, num / (RSIZE) 10)] = - (num % (RSIZE) 10) + '0'; - return r + 1; - } - /* NOTREACHED */ -} - -/* * The argument "text" points to a format string. Append this line to the * buffer. Handcraft the EOL on the end. Return TRUE if it worked and * FALSE if you ran out of room. |