xref: /csrg-svn/contrib/ed/line_number.c (revision 60663)
157693Sbostic /*-
2*60663Sbostic  * Copyright (c) 1992, 1993
3*60663Sbostic  *	The Regents of the University of California.  All rights reserved.
457693Sbostic  *
557693Sbostic  * This code is derived from software contributed to Berkeley by
657693Sbostic  * Rodney Ruddock of the University of Guelph.
757693Sbostic  *
857693Sbostic  * %sccs.include.redist.c%
957693Sbostic  */
1057693Sbostic 
1157693Sbostic #ifndef lint
12*60663Sbostic static char sccsid[] = "@(#)line_number.c	8.1 (Berkeley) 05/31/93";
1357693Sbostic #endif /* not lint */
1457693Sbostic 
1557710Sbostic #include <sys/types.h>
1657710Sbostic 
1757710Sbostic #include <regex.h>
1857710Sbostic #include <setjmp.h>
1957710Sbostic #include <stdio.h>
2057710Sbostic 
2158315Sbostic #ifdef DBI
2258315Sbostic #include <db.h>
2358315Sbostic #endif
2458315Sbostic 
2557693Sbostic #include "ed.h"
2657710Sbostic #include "extern.h"
2757693Sbostic 
2857693Sbostic /*
2957693Sbostic  * Converts a LINE to a line number (int) that can be printed to
3059558Sbostic  * the device the user is at. Used by n and =.
3157693Sbostic  */
3257693Sbostic int
line_number(line_addr)3357693Sbostic line_number(line_addr)
3457710Sbostic 	LINE *line_addr;
3557693Sbostic {
3657710Sbostic 	LINE *l_temp1;
3757710Sbostic 	int l_cnt = 1;		/* yes! =1 */
3857693Sbostic 
3957710Sbostic 	l_temp1 = top;
4057710Sbostic 	if ((line_addr == NULL) && (top == NULL))
4157710Sbostic 		return (0);
4257693Sbostic 
4357710Sbostic 	for (;;) {
4457710Sbostic 		if (line_addr == l_temp1)
4557710Sbostic 			break;
4657710Sbostic 		l_temp1 = l_temp1->below;
4757710Sbostic 		l_cnt++;
4857710Sbostic 	}
4957710Sbostic 	return (l_cnt);
5057710Sbostic }
51