1*0a6a1f1dSLionel Sambuc /* $NetBSD: ex_equal.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc * Copyright (c) 1992, 1993, 1994
484d9c625SLionel Sambuc * The Regents of the University of California. All rights reserved.
584d9c625SLionel Sambuc * Copyright (c) 1992, 1993, 1994, 1995, 1996
684d9c625SLionel Sambuc * Keith Bostic. All rights reserved.
784d9c625SLionel Sambuc *
884d9c625SLionel Sambuc * See the LICENSE file for redistribution information.
984d9c625SLionel Sambuc */
1084d9c625SLionel Sambuc
1184d9c625SLionel Sambuc #include "config.h"
1284d9c625SLionel Sambuc
13*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
14*0a6a1f1dSLionel Sambuc #if 0
1584d9c625SLionel Sambuc #ifndef lint
1684d9c625SLionel Sambuc static const char sccsid[] = "Id: ex_equal.c,v 10.12 2001/06/25 15:19:15 skimo Exp (Berkeley) Date: 2001/06/25 15:19:15 ";
1784d9c625SLionel Sambuc #endif /* not lint */
18*0a6a1f1dSLionel Sambuc #else
19*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: ex_equal.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc
2284d9c625SLionel Sambuc #include <sys/types.h>
2384d9c625SLionel Sambuc #include <sys/queue.h>
2484d9c625SLionel Sambuc
2584d9c625SLionel Sambuc #include <bitstring.h>
2684d9c625SLionel Sambuc #include <limits.h>
2784d9c625SLionel Sambuc #include <stdio.h>
2884d9c625SLionel Sambuc
2984d9c625SLionel Sambuc #include "../common/common.h"
3084d9c625SLionel Sambuc
3184d9c625SLionel Sambuc /*
3284d9c625SLionel Sambuc * ex_equal -- :address =
3384d9c625SLionel Sambuc *
3484d9c625SLionel Sambuc * PUBLIC: int ex_equal __P((SCR *, EXCMD *));
3584d9c625SLionel Sambuc */
3684d9c625SLionel Sambuc int
ex_equal(SCR * sp,EXCMD * cmdp)3784d9c625SLionel Sambuc ex_equal(SCR *sp, EXCMD *cmdp)
3884d9c625SLionel Sambuc {
3984d9c625SLionel Sambuc db_recno_t lno;
4084d9c625SLionel Sambuc
4184d9c625SLionel Sambuc NEEDFILE(sp, cmdp);
4284d9c625SLionel Sambuc
4384d9c625SLionel Sambuc /*
4484d9c625SLionel Sambuc * Print out the line number matching the specified address,
4584d9c625SLionel Sambuc * or the number of the last line in the file if no address
4684d9c625SLionel Sambuc * specified.
4784d9c625SLionel Sambuc *
4884d9c625SLionel Sambuc * !!!
4984d9c625SLionel Sambuc * Historically, ":0=" displayed 0, and ":=" or ":1=" in an
5084d9c625SLionel Sambuc * empty file displayed 1. Until somebody complains loudly,
5184d9c625SLionel Sambuc * we're going to do it right. The tables in excmd.c permit
5284d9c625SLionel Sambuc * lno to get away with any address from 0 to the end of the
5384d9c625SLionel Sambuc * file, which, in an empty file, is 0.
5484d9c625SLionel Sambuc */
5584d9c625SLionel Sambuc if (F_ISSET(cmdp, E_ADDR_DEF)) {
5684d9c625SLionel Sambuc if (db_last(sp, &lno))
5784d9c625SLionel Sambuc return (1);
5884d9c625SLionel Sambuc } else
5984d9c625SLionel Sambuc lno = cmdp->addr1.lno;
6084d9c625SLionel Sambuc
6184d9c625SLionel Sambuc (void)ex_printf(sp, "%ld\n", (unsigned long)lno);
6284d9c625SLionel Sambuc return (0);
6384d9c625SLionel Sambuc }
64