summaryrefslogtreecommitdiffstats
path: root/usr.sbin/lpr
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2000-10-31 20:11:30 +0000
committergad <gad@FreeBSD.org>2000-10-31 20:11:30 +0000
commit39de4067ae4666c1ef59bfc488ef0c1eef1fa59e (patch)
treee20b4e720714558ef8f8c0bd277c3a1600204bff /usr.sbin/lpr
parentda976a02d2ed03bd2eb10e2c60ce21768ff9959f (diff)
downloadFreeBSD-src-39de4067ae4666c1ef59bfc488ef0c1eef1fa59e.zip
FreeBSD-src-39de4067ae4666c1ef59bfc488ef0c1eef1fa59e.tar.gz
Make the standard 'lpq' output a little more informative when listing jobs
which have long names. Instead of just listing '...', try to list some reasonable subset of the name (with a "..." to indicate something missing). Reviewed by: freebsd-print@bostonradio.org (only a little review)
Diffstat (limited to 'usr.sbin/lpr')
-rw-r--r--usr.sbin/lpr/common_source/displayq.c51
1 files changed, 39 insertions, 12 deletions
diff --git a/usr.sbin/lpr/common_source/displayq.c b/usr.sbin/lpr/common_source/displayq.c
index e5a80a8..7b1df2c 100644
--- a/usr.sbin/lpr/common_source/displayq.c
+++ b/usr.sbin/lpr/common_source/displayq.c
@@ -439,27 +439,54 @@ dump(nfile, file, copies)
char *nfile, *file;
int copies;
{
- register short n, fill;
struct stat lbuf;
+ const char etctmpl[] = ", ...";
+ char etc[sizeof(etctmpl)];
+ char *lastsep;
+ short fill, nlen;
+ short rem, remetc;
/*
- * Print as many files as will fit
- * (leaving room for the total size)
+ * Print as many filenames as will fit
+ * (leaving room for the 'total size' field)
*/
- fill = first ? 0 : 2; /* fill space for ``, '' */
- if (((n = strlen(nfile)) + col + fill) >= SIZCOL-4) {
- if (col < SIZCOL) {
- printf(" ..."), col += 4;
- blankfill(SIZCOL);
+ fill = first ? 0 : 2; /* fill space for ``, '' */
+ nlen = strlen(nfile);
+ rem = SIZCOL - 1 - col;
+ if (nlen + fill > rem) {
+ if (first) {
+ /* print the right-most part of the name */
+ printf("...%s ", &nfile[3+nlen-rem]);
+ col = SIZCOL;
+ } else if (rem > 0) {
+ /* fit as much of the etc-string as we can */
+ remetc = rem;
+ if (rem > strlen(etctmpl))
+ remetc = strlen(etctmpl);
+ etc[0] = '\0';
+ strncat(etc, etctmpl, remetc);
+ printf(etc);
+ col += remetc;
+ rem -= remetc;
+ /* room for the last segment of this filename? */
+ lastsep = strrchr(nfile, '/');
+ if ((lastsep != NULL) && (rem > strlen(lastsep))) {
+ /* print the right-most part of this name */
+ printf("%s", lastsep);
+ col += strlen(lastsep);
+ } else {
+ /* do not pack any more names in here */
+ blankfill(SIZCOL);
+ }
}
} else {
- if (first)
- first = 0;
- else
+ if (!first)
printf(", ");
printf("%s", nfile);
- col += n+fill;
+ col += nlen + fill;
}
+ first = 0;
+
seteuid(euid);
if (*file && !stat(file, &lbuf))
totsize += copies * lbuf.st_size;
OpenPOWER on IntegriCloud