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