some changes got lost somewhere, make it consistent
[nvi.git] / vi / v_status.c
blob2e1705a47bf8bfe2f25f4f84fc19588335504f4f
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: v_status.c,v 8.10 1993/11/20 10:05:56 bostic Exp $ (Berkeley) $Date: 1993/11/20 10:05:56 $";
10 #endif /* not lint */
12 #include <sys/param.h>
13 #include <sys/stat.h>
15 #include <unistd.h>
17 #include "vi.h"
18 #include "vcmd.h"
21 * v_status -- ^G
22 * Show the file status.
24 int
25 v_status(sp, ep, vp, fm, tm, rp)
26 SCR *sp;
27 EXF *ep;
28 VICMDARG *vp;
29 MARK *fm, *tm, *rp;
33 * ^G in historic vi reset the cursor column to the first
34 * non-blank character in the line. This doesn't seem of
35 * any usefulness whatsoever, so I don't bother.
37 return (status(sp, ep, fm->lno, 1));
40 int
41 status(sp, ep, lno, showlast)
42 SCR *sp;
43 EXF *ep;
44 recno_t lno;
45 int showlast;
47 recno_t last;
48 char *mo, *nc, *nf, *ro, *pid;
49 #ifdef DEBUG
50 char pbuf[50];
52 (void)snprintf(pbuf, sizeof(pbuf), " (pid %u)", getpid());
53 pid = pbuf;
54 #else
55 pid = "";
56 #endif
58 * See nvi/exf.c:file_init() for a description of how and
59 * when the read-only bit is set. Possible displays are:
61 * new file
62 * new file, readonly
63 * [un]modified
64 * [un]modified, readonly
65 * name changed, [un]modified
66 * name changed, [un]modified, readonly
68 * !!!
69 * The historic display for "name changed" was "[Not edited]".
71 if (F_ISSET(sp->frp, FR_NEWFILE)) {
72 F_CLR(sp->frp, FR_NEWFILE);
73 nf = "new file";
74 mo = nc = "";
75 } else {
76 nf = "";
77 if (sp->frp->cname != NULL) {
78 nc = "name changed";
79 mo = F_ISSET(ep, F_MODIFIED) ?
80 ", modified" : ", unmodified";
81 } else {
82 nc = "";
83 mo = F_ISSET(ep, F_MODIFIED) ?
84 "modified" : "unmodified";
87 ro = F_ISSET(sp->frp, FR_RDONLY) ? ", readonly" : "";
88 if (showlast) {
89 if (file_lline(sp, ep, &last))
90 return (1);
91 if (last >= 1)
92 msgq(sp, M_INFO,
93 "%s: %s%s%s%s: line %lu of %lu [%ld%%]%s",
94 FILENAME(sp->frp), nf, nc, mo, ro, lno,
95 last, (lno * 100) / last, pid);
96 else
97 msgq(sp, M_INFO, "%s: %s%s%s%s: empty file%s",
98 FILENAME(sp->frp), nf, nc, mo, ro, pid);
99 } else
100 msgq(sp, M_INFO, "%s: %s%s%s%s: line %lu%s",
101 FILENAME(sp->frp), nf, nc, mo, ro, lno, pid);
102 return (0);