enhancement to rn = index command
Andrew Tannenbaum
trb at haddock.ISC.COM
Sat Mar 19 06:08:52 AEST 1988
System: rn version 4.3
Priority: LOW
Subject: enhancement to rn = index command
>From: trb at ima.isc.com (Andrew Tannenbaum)
Description:
This patch lets you use printf-style formatting in rn strings,
most usefully, the SUBJLINE variable.
This is a patch to rn patch level 40. I sent it to Larry Wall
back in Dec 1987, and he said to post it myself. I didn't add
new RCS IDs, as I figured it could cause confusion since I don't
control rn. I've been running the code for four months on two
different types of UNIX systems, without incident.
A sample of the output is just below. The format used is
-ESUBJLINE="%:-50.50s %:.24t"
This work was done by me and Karl Heuer. Karl points out that
%+ has special meaning to printf, and %: is used by terminfo to
disambiguate %wid.prec in a similar manner (see terminfo(4):
Parameterized strings). This hack only distinguished + and -
for justification, it doesn't do %# or fancy %+. It's all
#ifdef PADTRUNC.
I also fixed the /foo/= bug (it wasn't checking SUBJLINE). I
notice that the %s fields have all the Re's stripped off, which
isn't quite right, but I haven't dealt with that. (That's an
existing bug, or at least the doc for = says that it uses %s by
default).
Fix: To fix rn, install the following patches and recompile.
From rn, say "| patch -d DIR", where DIR is your rn source directory.
Outside of rn, say "cd DIR; patch <thisarticle". If you don't have
the patch program, apply the following by hand, or get patch.
Andrew Tannenbaum Interactive Boston, MA +1 617 247 1155
<<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>
Sample output:
What next? [^Nnpq] =
...
5584 Ultrix uucp problems - Help! steph at alberta.UUCP
5585 Ksh question. lenny at quincy.UUCP
5586 POSIX execlfd and execvfd proposal karl at tut.cis.ohio-state.
5588 suggest solutions for "rm *" jsb at dasys1.UUCP
5589 3b5 inode problem with news KEN%ORION.BITNET at CUNYVM.
5590 The whole prompt string thing (was: PS1 and t marcos at caus-dp.UUCP
5592 setpgrp() bug? chapman at sco.COM
5593 more rm insanity chris at mimsy.UUCP
5595 //host vs "mount point" matt at oddjob.UChicago.EDU
...
What next? [^Nnpq]
Type h for help.
What next? [^Nnpq] /gwyn/h=
Searching...
5576 The whole prompt string thing (was: PS1 and t gwyn at brl.arpa
5578 Bug in Ultrix2.0? gwyn at brl.arpa
5611 The whole prompt string thing (was: PS1 and t gwyn at brl.arpa
5612 globbing in the shell (Was Re: more rm insani gwyn at brl.arpa
5659 Help! How 2 get info from C to Unix script gwyn at brl.arpa
5662 globbing in the shell gwyn at brl.arpa
5676 shell globbing universal ????? gwyn at brl.arpa
5690 more rm insanity gwyn at brl.arpa
5692 globbing in the shell (Was Re: more rm insani gwyn at brl.arpa
5695 ACCESS TO SHARED TAPEDRIVES gwyn at brl.arpa
What next? [^Nnpq]
<<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>
*** common.h.ok Thu Dec 3 16:26:44 1987
--- common.h Thu Dec 3 16:24:38 1987
***************
*** 166,171 ****
--- 166,174 ----
* pattern that had brackets. %0 matches the last bracket
* matched, in case you had alternatives.
*
+ * (#ifdef PADTRUNC) Put : in the middle for printf-style formatting:
+ * -ESUBJLINE="%:-50.50s %:.24t"
+ *
* Put ^ in the middle to capitalize the first letter: %^C = Net.jokes
* Put _ in the middle to capitalize last component: %_c = net/Jokes
*
***************
*** 293,298 ****
--- 296,302 ----
#define KILLFILES /* automatic article killer files */
#define ARTSEARCH /* pattern searches among articles */
/* /, ?, ^N, ^P, k, K */
+ #define PADTRUNC /* printf-style command modifiers */
/* some dependencies among options */
*** intrp.c.ok Tue Dec 1 18:36:38 1987
--- intrp.c Wed Dec 2 13:31:21 1987
***************
*** 397,402 ****
--- 397,406 ----
bool upper = FALSE;
bool lastcomp = FALSE;
int metabit = 0;
+ #ifdef PADTRUNC
+ int wid;
+ int prec;
+ #endif
while (*pattern && (!stoppers || !index(stoppers,*pattern))) {
#ifdef DEBUGGING
***************
*** 406,413 ****
--- 410,436 ----
if (*pattern == '%' && pattern[1]) {
upper = FALSE;
lastcomp = FALSE;
+ #ifdef PADTRUNC
+ wid = 0;
+ prec = 1000;
+ #endif
for (s=Nullch; !s; ) {
switch (*++pattern) {
+ #ifdef PADTRUNC
+ case ':':
+ if (isdigit(*++pattern) || *pattern == '-') {
+ wid = atol(pattern);
+ while (isdigit(*++pattern) || *pattern == '-')
+ ;
+ }
+ if (*pattern == '.') {
+ prec = atol(++pattern);
+ while (isdigit(*pattern))
+ pattern++;
+ }
+ pattern--;
+ break;
+ #endif
case '^':
upper = TRUE;
break;
***************
*** 831,836 ****
--- 854,867 ----
if (islower(*t))
*t = toupper(*t);
}
+ #ifdef PADTRUNC
+ if (s != scrbuf) {
+ safecpy(scrbuf,s,(sizeof scrbuf));
+ s = scrbuf;
+ }
+ sprintf(dest, "%*.*s", wid, prec, s);
+ s = dest;
+ #endif
i = metabit; /* maybe get into register */
if (s == dest) {
while (*dest) {
*** ngstuff.c.ok Thu Dec 3 14:35:26 1987
--- ngstuff.c Thu Dec 3 15:22:10 1987
***************
*** 222,228 ****
--- 222,232 ----
register int ch;
if (toplevel) {
+ #ifdef PADTRUNC
+ printf("%5ld ",art);
+ #else
printf("%-6ld",art);
+ #endif
fflush(stdout);
}
for (; ch = *cmdlst; cmdlst++) {
***************
*** 259,265 ****
--- 263,281 ----
#endif
}
else if (ch == '=') {
+ #ifdef PADTRUNC
+ char tmpbuf[256];
+ char *subjline = getval("SUBJLINE",Nullch);
+
+ if (subjline) { /* probably fetches it again! */
+ /* art = i; */
+ interp(tmpbuf, (sizeof tmpbuf), subjline);
+ printf(tmpbuf);
+ } else
+ printf(fetchsubj(art,FALSE,FALSE));
+ #else
printf("\t%s",fetchsubj(art,FALSE,FALSE));
+ #endif
#ifdef VERBOSE
IF(verbose)
;
*** rn.1.ok Thu Dec 3 16:41:16 1987
--- rn.1 Thu Dec 3 16:53:17 1987
***************
*** 1247,1252 ****
--- 1247,1260 ----
\*(L"%^C\*(R" produces something like \*(L"Net.jokes\*(R".
Inserting \*(L'_\*(R' causes the first letter following the last
\&\*(L'/\*(R' to be capitalized: \*(L"%_c\*(R" produces \*(L"net/Jokes\*(R".
+ Inserting \*(L':\*(R' causes the substitution value to be printed with
+ printf-style formatting. If you want your indices to have up to 50
+ characters of subject followed by 24 characters of author,
+ you can define the following environment variable with \-E:
+ .Sp
+ .nf
+ SUBJLINE=\*(L%:"\-50.50s %:.24t\*(R".
+ .fi
.SH ENVIRONMENT
The following environment variables are paid attention to by
.IR rn .
More information about the Comp.sources.bugs
mailing list