1 /* global.c: global command routines for the ed line editor */
2 /* GNU ed - The GNU line editor.
3 Copyright (C) 1993, 1994 Andrew Moore, Talke Studio
4 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012
5 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 static const line_t **active_list = 0; /* list of lines active in a global command */
30 static int active_size = 0; /* size (in bytes) of active_list */
31 static int active_len = 0; /* number of lines in active_list */
32 static int active_ptr = 0; /* active_list index ( non-decreasing ) */
33 static int active_ndx = 0; /* active_list index ( modulo active_last ) */
36 /* clear the global-active list */
37 void clear_active_list( void )
40 if( active_list ) free( active_list );
42 active_size = active_len = active_ptr = active_ndx = 0;
47 /* return the next global-active line node */
48 const line_t * next_active_node( void )
50 while( active_ptr < active_len && !active_list[active_ptr] )
52 return ( active_ptr < active_len ) ? active_list[active_ptr++] : 0;
56 /* add a line node to the global-active list */
57 bool set_active_node( const line_t * const lp )
60 if( !resize_line_buffer( &active_list, &active_size,
61 ( active_len + 1 ) * sizeof (line_t **) ) )
63 show_strerror( 0, errno ); set_error_msg( "Memory exhausted" );
68 active_list[active_len++] = lp;
73 /* remove a range of lines from the global-active list */
74 void unset_active_nodes( const line_t * bp, const line_t * const ep )
79 for( i = 0; i < active_len; ++i )
81 if( ++active_ndx >= active_len ) active_ndx = 0;
82 if( active_list[active_ndx] == bp )
83 { active_list[active_ndx] = 0; break; }