xref: /original-bsd/contrib/ed/c.c (revision b806d041)
1 /*-
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rodney Ruddock of the University of Guelph.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)c.c	5.5 (Berkeley) 05/11/93";
13 #endif /* not lint */
14 
15 #include <sys/types.h>
16 
17 #include <regex.h>
18 #include <setjmp.h>
19 #include <stdio.h>
20 
21 #ifdef DBI
22 #include <db.h>
23 #endif
24 
25 #include "ed.h"
26 #include "extern.h"
27 
28 /*
29  * This deletes the range of lines specified and then sets up things
30  * for the central input routine.
31  */
32 
33 void
34 c(inputt, errnum)
35 	FILE *inputt;
36 	int *errnum;
37 {
38 	int l_flag=1;
39 
40 	if (Start_default && End_default)
41 		Start = End = current;
42 	else
43 		if (Start_default)
44 			Start = End;
45 	if (Start == NULL) {
46 		*errnum = -1;
47 		return;
48 	}
49 	Start_default = End_default = 0;
50 	if (End == bottom)
51 		l_flag = 0;
52 
53 	/* first delete the lines */
54 	d(inputt, errnum);
55 	if (*errnum < 0)
56 		return;
57 	*errnum = 0;
58 
59 	/*if ((current != NULL) && (current != bottom)) RMSR */
60 	if ((current != NULL) && l_flag)
61 		current = current->above;
62 	add_flag = 1;
63 	Start_default = End_default = 1;
64 	/* now get the "change" lines */
65 	input_lines(inputt, errnum);
66 	add_flag = 0;
67 }
68