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-2015 Antonio Diaz Diaz.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 static const line_t **active_list = 0; /* list of lines active in a global command */
29 static int active_size = 0; /* size (in bytes) of active_list */
30 static int active_len = 0; /* number of lines in active_list */
31 static int active_ptr = 0; /* active_list index ( non-decreasing ) */
32 static int active_ndx = 0; /* active_list index ( modulo active_last ) */
35 /* clear the global-active list */
36 void clear_active_list( void )
39 if( active_list ) free( active_list );
41 active_size = active_len = active_ptr = active_ndx = 0;
46 /* return the next global-active line node */
47 const line_t * next_active_node( void )
49 while( active_ptr < active_len && !active_list[active_ptr] )
51 return ( active_ptr < active_len ) ? active_list[active_ptr++] : 0;
55 /* add a line node to the global-active list */
56 bool set_active_node( const line_t * const lp )
59 if( !resize_line_buffer( &active_list, &active_size,
60 ( active_len + 1 ) * sizeof (line_t **) ) )
62 show_strerror( 0, errno );
63 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; }