xref: /freebsd/contrib/nvi/ex/ex_equal.c (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
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 #ifndef lint
13 static const char sccsid[] = "$Id: ex_equal.c,v 10.12 2001/06/25 15:19:15 skimo Exp $";
14 #endif /* not lint */
15 
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
19 
20 #include <bitstring.h>
21 #include <limits.h>
22 #include <stdio.h>
23 
24 #include "../common/common.h"
25 
26 /*
27  * ex_equal -- :address =
28  *
29  * PUBLIC: int ex_equal(SCR *, EXCMD *);
30  */
31 int
32 ex_equal(SCR *sp, EXCMD *cmdp)
33 {
34 	recno_t lno;
35 
36 	NEEDFILE(sp, cmdp);
37 
38 	/*
39 	 * Print out the line number matching the specified address,
40 	 * or the number of the last line in the file if no address
41 	 * specified.
42 	 *
43 	 * !!!
44 	 * Historically, ":0=" displayed 0, and ":=" or ":1=" in an
45 	 * empty file displayed 1.  Until somebody complains loudly,
46 	 * we're going to do it right.  The tables in excmd.c permit
47 	 * lno to get away with any address from 0 to the end of the
48 	 * file, which, in an empty file, is 0.
49 	 */
50 	if (F_ISSET(cmdp, E_ADDR_DEF)) {
51 		if (db_last(sp, &lno))
52 			return (1);
53 	} else
54 		lno = cmdp->addr1.lno;
55 
56 	(void)ex_printf(sp, "%ld\n", lno);
57 	return (0);
58 }
59