glbl.c (81220) | glbl.c (90109) |
---|---|
1/* glob.c: This file contains the global command routines for the ed line 2 editor */ 3/*- 4 * Copyright (c) 1993 Andrew Moore, Talke Studio. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 14 unchanged lines hidden (view full) --- 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#ifndef lint 30static const char rcsid[] = | 1/* glob.c: This file contains the global command routines for the ed line 2 editor */ 3/*- 4 * Copyright (c) 1993 Andrew Moore, Talke Studio. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 14 unchanged lines hidden (view full) --- 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#ifndef lint 30static const char rcsid[] = |
31 "$FreeBSD: head/bin/ed/glbl.c 81220 2001-08-06 22:01:31Z mike $"; | 31 "$FreeBSD: head/bin/ed/glbl.c 90109 2002-02-02 06:36:49Z imp $"; |
32#endif /* not lint */ 33 34#include <sys/types.h> 35 36#include <sys/ioctl.h> 37#include <sys/wait.h> 38 39#include "ed.h" 40 41 42/* build_active_list: add line matching a pattern to the global-active list */ 43int | 32#endif /* not lint */ 33 34#include <sys/types.h> 35 36#include <sys/ioctl.h> 37#include <sys/wait.h> 38 39#include "ed.h" 40 41 42/* build_active_list: add line matching a pattern to the global-active list */ 43int |
44build_active_list(isgcmd) 45 int isgcmd; | 44build_active_list(int isgcmd) |
46{ 47 pattern_t *pat; 48 line_t *lp; 49 long n; 50 char *s; 51 char delimiter; 52 53 if ((delimiter = *ibufp) == ' ' || delimiter == '\n') { --- 16 unchanged lines hidden (view full) --- 70 } 71 return 0; 72} 73 74 75/* exec_global: apply command list in the command buffer to the active 76 lines in a range; return command status */ 77long | 45{ 46 pattern_t *pat; 47 line_t *lp; 48 long n; 49 char *s; 50 char delimiter; 51 52 if ((delimiter = *ibufp) == ' ' || delimiter == '\n') { --- 16 unchanged lines hidden (view full) --- 69 } 70 return 0; 71} 72 73 74/* exec_global: apply command list in the command buffer to the active 75 lines in a range; return command status */ 76long |
78exec_global(interact, gflag) 79 int interact; 80 int gflag; | 77exec_global(int interact, int gflag) |
81{ 82 static char *ocmd = NULL; 83 static int ocmdsz = 0; 84 85 line_t *lp = NULL; 86 int status; 87 int n; 88 char *cmd = NULL; --- 55 unchanged lines hidden (view full) --- 144line_t **active_list; /* list of lines active in a global command */ 145long active_last; /* index of last active line in active_list */ 146long active_size; /* size of active_list */ 147long active_ptr; /* active_list index (non-decreasing) */ 148long active_ndx; /* active_list index (modulo active_last) */ 149 150/* set_active_node: add a line node to the global-active list */ 151int | 78{ 79 static char *ocmd = NULL; 80 static int ocmdsz = 0; 81 82 line_t *lp = NULL; 83 int status; 84 int n; 85 char *cmd = NULL; --- 55 unchanged lines hidden (view full) --- 141line_t **active_list; /* list of lines active in a global command */ 142long active_last; /* index of last active line in active_list */ 143long active_size; /* size of active_list */ 144long active_ptr; /* active_list index (non-decreasing) */ 145long active_ndx; /* active_list index (modulo active_last) */ 146 147/* set_active_node: add a line node to the global-active list */ 148int |
152set_active_node(lp) 153 line_t *lp; | 149set_active_node(line_t *lp) |
154{ 155 if (active_last + 1 > active_size) { 156 int ti = active_size; 157 line_t **ts; 158 SPL1(); 159#if defined(sun) || defined(NO_REALLOC_NULL) 160 if (active_list != NULL) { 161#endif --- 21 unchanged lines hidden (view full) --- 183 } 184 active_list[active_last++] = lp; 185 return 0; 186} 187 188 189/* unset_active_nodes: remove a range of lines from the global-active list */ 190void | 150{ 151 if (active_last + 1 > active_size) { 152 int ti = active_size; 153 line_t **ts; 154 SPL1(); 155#if defined(sun) || defined(NO_REALLOC_NULL) 156 if (active_list != NULL) { 157#endif --- 21 unchanged lines hidden (view full) --- 179 } 180 active_list[active_last++] = lp; 181 return 0; 182} 183 184 185/* unset_active_nodes: remove a range of lines from the global-active list */ 186void |
191unset_active_nodes(np, mp) 192 line_t *np, *mp; | 187unset_active_nodes(line_t *np, line_t *mp) |
193{ 194 line_t *lp; 195 long i; 196 197 for (lp = np; lp != mp; lp = lp->q_forw) 198 for (i = 0; i < active_last; i++) 199 if (active_list[active_ndx] == lp) { 200 active_list[active_ndx] = NULL; 201 active_ndx = INC_MOD(active_ndx, active_last - 1); 202 break; 203 } else active_ndx = INC_MOD(active_ndx, active_last - 1); 204} 205 206 207/* next_active_node: return the next global-active line node */ 208line_t * | 188{ 189 line_t *lp; 190 long i; 191 192 for (lp = np; lp != mp; lp = lp->q_forw) 193 for (i = 0; i < active_last; i++) 194 if (active_list[active_ndx] == lp) { 195 active_list[active_ndx] = NULL; 196 active_ndx = INC_MOD(active_ndx, active_last - 1); 197 break; 198 } else active_ndx = INC_MOD(active_ndx, active_last - 1); 199} 200 201 202/* next_active_node: return the next global-active line node */ 203line_t * |
209next_active_node() | 204next_active_node(void) |
210{ 211 while (active_ptr < active_last && active_list[active_ptr] == NULL) 212 active_ptr++; 213 return (active_ptr < active_last) ? active_list[active_ptr++] : NULL; 214} 215 216 217/* clear_active_list: clear the global-active list */ 218void | 205{ 206 while (active_ptr < active_last && active_list[active_ptr] == NULL) 207 active_ptr++; 208 return (active_ptr < active_last) ? active_list[active_ptr++] : NULL; 209} 210 211 212/* clear_active_list: clear the global-active list */ 213void |
219clear_active_list() | 214clear_active_list(void) |
220{ 221 SPL1(); 222 active_size = active_last = active_ptr = active_ndx = 0; 223 free(active_list); 224 active_list = NULL; 225 SPL0(); 226} | 215{ 216 SPL1(); 217 active_size = active_last = active_ptr = active_ndx = 0; 218 free(active_list); 219 active_list = NULL; 220 SPL0(); 221} |