From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from math.gatech.edu (euclid.skiles.gatech.edu [130.207.146.50]) by werple.net.au (8.7/8.7.1) with SMTP id BAA13973 for ; Sun, 26 Nov 1995 01:15:21 +1100 (EST) Received: by math.gatech.edu (5.x/SMI-SVR4) id AA07746; Sat, 25 Nov 1995 08:56:28 -0500 Resent-Date: Sat, 25 Nov 1995 13:56:56 +0000 (GMT) Old-Return-Path: From: Zefram Message-Id: <1808.199511251356@stone.dcs.warwick.ac.uk> Subject: Re: patches to nice* To: zsh-workers@math.gatech.edu (Z Shell workers mailing list) Date: Sat, 25 Nov 1995 13:56:56 +0000 (GMT) X-Loop: zefram@dcs.warwick.ac.uk X-Stardate: [-31]6647.90 Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-Id: <"QYrgt.0.yu1.B2ojm"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/647 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----BEGIN PGP SIGNED MESSAGE----- Here's a comment patch for the nice* functions and stradd(), after my recent patch to them. -zefram *** 1.1.1.1 1995/11/25 05:12:26 --- utils.c 1995/11/25 13:35:54 *************** *** 135,140 **** --- 135,150 ---- return 0; } + /* Turn a character into a visible representation thereof. The visible * + * string is put together in a static buffer, and this function returns * + * a pointer to it. Printable characters stand for themselves, DEL is * + * represented as "^?", newline and tab are represented as "\n" and * + * "\t", and normal control characters are represented in "^C" form. * + * Characters with bit 7 set, if unprintable, are represented as "\M-" * + * followed by the visible representation of the character with bit 7 * + * stripped off. Tokens are interpreted, rather than being treated as * + * literal characters. */ + /**/ char * nicechar(int c) *** 1.2 1995/11/25 05:12:26 --- zle_misc.c 1995/11/25 13:52:34 *************** *** 639,668 **** --- 639,690 ---- static char *truncstr; static int dontcount, lensb, trunclen; + /* stradd() adds a string to the prompt, in a * + * visible representation, doing truncation. */ + /**/ void stradd(char *d) { + /* dlen is the full length of the string we want to add */ int dlen = nicestrlen(d); char *ps, *pd, *pc, *t; int tlen, maxlen; addbufspc(dlen); + /* This loop puts the nice representation of the string into the prompt * + * buffer. It might be modified later. Note that bp isn't changed. */ for(ps=d, pd=bp; *ps; ps++) for(pc=nicechar(STOUC(*ps)); *pc; pc++) *pd++=*pc; if(!trunclen || dlen <= trunclen) { + /* No truncation is needed, so update bp and return, * + * leaving the full string in the prompt. */ bp += dlen; return; } + /* We need to truncate. t points to the truncation string -- which is * + * inserted literally, without nice representation. tlen is its * + * length, and maxlen is the amout of the main string that we want to * + * keep. Note that if the truncation string is longer than the * + * truncation length (tlen > trunclen), the truncation string is used * + * in full. */ t = truncstr + 1; tlen = strlen(t); maxlen = tlen < trunclen ? trunclen - tlen : 0; addbufspc(tlen); if(*truncstr == '>') { + /* '>' means truncate at the right. We just move past the first * + * maxlen characters of the string, and write the truncation * + * string there. */ bp += maxlen; while(*t) pputc(*t++); } else { + /* Truncation at the left: ps is initialised to the start of the * + * part of the string that we want to keep. pc points to the * + * end of the string. The truncation string is added to the * + * prompt, then the desired part of the string is copied into * + * the right place. */ ps = bp + dlen - maxlen; pc = bp + dlen; while(*t) -----BEGIN PGP SIGNATURE----- Version: 2.6.i iQCVAgUBMLcgPXD/+HJTpU/hAQFV+wP/TaJcOxiebGwEdb6YeIw0zZMnvrxXvibF kYM9X/NQyEkNoY4SDqP41Na11P8eDaAzGb/6nnx08F/JyfRqZUCSzpYabHxG1mpX XSBPD1uG1uR+5pdFOYMOi4sYLAVq+7yKSIVBVelxDyVgbY5pXLR/wbFZBp5pViqk HWJyMN7irn8= =q9Ml -----END PGP SIGNATURE-----