diff options
Diffstat (limited to 'bc/storage.c')
-rw-r--r-- | bc/storage.c | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/bc/storage.c b/bc/storage.c index 10ebf5c..699729a 100644 --- a/bc/storage.c +++ b/bc/storage.c @@ -1,7 +1,6 @@ -/* storage.c: Code and data storage manipulations. This includes labels. */ - /* This file is part of GNU bc. - Copyright (C) 1991-1994, 1997, 2000 Free Software Foundation, Inc. + + Copyright (C) 1991-1994, 1997, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,10 +13,10 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to + along with this program; see the file COPYING. If not, write to: The Free Software Foundation, Inc. - 59 Temple Place, Suite 330 - Boston, MA 02111 USA + Foundation, Inc. 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301 USA You may contact the author by: e-mail: philnelson@acm.org @@ -28,8 +27,9 @@ *************************************************************************/ +/* storage.c: Code and data storage manipulations. This includes labels. */ + #include "bcdefs.h" -#include "global.h" #include "proto.h" @@ -42,7 +42,7 @@ init_storage () /* Functions: we start with none and ask for more. */ f_count = 0; more_functions (); - f_names[0] = "(main)"; + f_names[0] = (char *)"(main)"; /* Variables. */ v_count = 0; @@ -135,7 +135,10 @@ more_variables () /* Copy the old variables. */ for (indx = 3; indx < old_count; indx++) - variables[indx] = old_var[indx]; + { + variables[indx] = old_var[indx]; + v_names[indx] = old_names[indx]; + } /* Initialize the new elements. */ for (; indx < v_count; indx++) @@ -169,7 +172,10 @@ more_arrays () /* Copy the old arrays. */ for (indx = 1; indx < old_count; indx++) - arrays[indx] = old_ary[indx]; + { + arrays[indx] = old_ary[indx]; + a_names[indx] = old_names[indx]; + } /* Initialize the new elements. */ @@ -358,9 +364,9 @@ get_var (var_name) the index into the bc array. */ bc_num * -get_array_num (var_index, index) +get_array_num (var_index, idx) int var_index; - long index; + long idx; { bc_var_array *ary_ptr; bc_array *a_var; @@ -387,8 +393,8 @@ get_array_num (var_index, index) } /* Get the index variable. */ - sub[0] = index & NODE_MASK; - ix = index >> NODE_SHIFT; + sub[0] = idx & NODE_MASK; + ix = idx >> NODE_SHIFT; log = 1; while (ix > 0 || log < a_var->a_depth) { @@ -574,16 +580,16 @@ store_array (var_name) int var_name; { bc_num *num_ptr; - long index; + long idx; if (!check_stack(2)) return; - index = bc_num2long (ex_stack->s_next->s_num); - if (index < 0 || index > BC_DIM_MAX || - (index == 0 && !bc_is_zero(ex_stack->s_next->s_num))) + idx = bc_num2long (ex_stack->s_next->s_num); + if (idx < 0 || idx > BC_DIM_MAX || + (idx == 0 && !bc_is_zero(ex_stack->s_next->s_num))) rt_error ("Array %s subscript out of bounds.", a_names[var_name]); else { - num_ptr = get_array_num (var_name, index); + num_ptr = get_array_num (var_name, idx); if (num_ptr != NULL) { bc_free_num (num_ptr); @@ -654,16 +660,16 @@ load_array (var_name) int var_name; { bc_num *num_ptr; - long index; + long idx; if (!check_stack(1)) return; - index = bc_num2long (ex_stack->s_num); - if (index < 0 || index > BC_DIM_MAX || - (index == 0 && !bc_is_zero(ex_stack->s_num))) + idx = bc_num2long (ex_stack->s_num); + if (idx < 0 || idx > BC_DIM_MAX || + (idx == 0 && !bc_is_zero(ex_stack->s_num))) rt_error ("Array %s subscript out of bounds.", a_names[var_name]); else { - num_ptr = get_array_num (var_name, index); + num_ptr = get_array_num (var_name, idx); if (num_ptr != NULL) { pop(); @@ -735,17 +741,17 @@ decr_array (var_name) int var_name; { bc_num *num_ptr; - long index; + long idx; /* It is an array variable. */ if (!check_stack (1)) return; - index = bc_num2long (ex_stack->s_num); - if (index < 0 || index > BC_DIM_MAX || - (index == 0 && !bc_is_zero (ex_stack->s_num))) + idx = bc_num2long (ex_stack->s_num); + if (idx < 0 || idx > BC_DIM_MAX || + (idx == 0 && !bc_is_zero (ex_stack->s_num))) rt_error ("Array %s subscript out of bounds.", a_names[var_name]); else { - num_ptr = get_array_num (var_name, index); + num_ptr = get_array_num (var_name, idx); if (num_ptr != NULL) { pop (); @@ -818,16 +824,16 @@ incr_array (var_name) int var_name; { bc_num *num_ptr; - long index; + long idx; if (!check_stack (1)) return; - index = bc_num2long (ex_stack->s_num); - if (index < 0 || index > BC_DIM_MAX || - (index == 0 && !bc_is_zero (ex_stack->s_num))) + idx = bc_num2long (ex_stack->s_num); + if (idx < 0 || idx > BC_DIM_MAX || + (idx == 0 && !bc_is_zero (ex_stack->s_num))) rt_error ("Array %s subscript out of bounds.", a_names[var_name]); else { - num_ptr = get_array_num (var_name, index); + num_ptr = get_array_num (var_name, idx); if (num_ptr != NULL) { pop (); @@ -985,8 +991,8 @@ copy_array (ary) variable. */ void -process_params (pc, func) - program_counter *pc; +process_params (progctr, func) + program_counter *progctr; int func; { char ch; @@ -999,7 +1005,7 @@ process_params (pc, func) /* Get the parameter names from the function. */ params = functions[func].f_params; - while ((ch = byte(pc)) != ':') + while ((ch = byte(progctr)) != ':') { if (params != NULL) { |