xref: /dragonfly/contrib/nvi2/ex/ex_equal.c (revision 07bc39c2f4bbca56f12568e06d89da17f2eeb965)
1 /*-
2  * Copyright (c) 1992, 1993, 1994
3  *        The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1992, 1993, 1994, 1995, 1996
5  *        Keith Bostic.  All rights reserved.
6  *
7  * See the LICENSE file for redistribution information.
8  */
9 
10 #include "config.h"
11 
12 #include <sys/types.h>
13 #include <sys/queue.h>
14 #include <sys/time.h>
15 
16 #include <bitstring.h>
17 #include <limits.h>
18 #include <stdio.h>
19 
20 #include "../common/common.h"
21 
22 /*
23  * ex_equal -- :address =
24  *
25  * PUBLIC: int ex_equal(SCR *, EXCMD *);
26  */
27 int
ex_equal(SCR * sp,EXCMD * cmdp)28 ex_equal(SCR *sp, EXCMD *cmdp)
29 {
30           recno_t lno;
31 
32           NEEDFILE(sp, cmdp);
33 
34           /*
35            * Print out the line number matching the specified address,
36            * or the number of the last line in the file if no address
37            * specified.
38            *
39            * !!!
40            * Historically, ":0=" displayed 0, and ":=" or ":1=" in an
41            * empty file displayed 1.  Until somebody complains loudly,
42            * we're going to do it right.  The tables in excmd.c permit
43            * lno to get away with any address from 0 to the end of the
44            * file, which, in an empty file, is 0.
45            */
46           if (F_ISSET(cmdp, E_ADDR_DEF)) {
47                     if (db_last(sp, &lno))
48                               return (1);
49           } else
50                     lno = cmdp->addr1.lno;
51 
52           (void)ex_printf(sp, "%ld\n", lno);
53           return (0);
54 }
55