diff --git a/src/array.c b/src/array.c index 60edff825a20c74177d0089d51255723339eb435..57a3289ec4fb7675f1dd5a2c5bdd17e8cc72cdec 100644 --- a/src/array.c +++ b/src/array.c @@ -20,7 +20,7 @@ #include "main.h" #include "security.h" -RCSID("$Id: array.c,v 1.44 1999/03/05 02:14:31 hubbe Exp $"); +RCSID("$Id: array.c,v 1.45 1999/03/19 11:40:12 hubbe Exp $"); struct array empty_array= { @@ -168,10 +168,13 @@ void simple_array_index_no_free(struct svalue *s, i=ind->u.integer; if(i<0) i+=a->size; if(i<0 || i>=a->size) { + struct svalue tmp; + tmp.type=T_ARRAY; + tmp.u.array=a; if (a->size) { - error("Index %d is out of range 0 - %d.\n", i, a->size-1); + index_error(0,0,0,&tmp,ind,"Index %d is out of range 0 - %d.\n", i, a->size-1); } else { - error("Attempt to index the empty array with %d.\n", i); + index_error(0,0,0,&tmp,ind,"Attempt to index the empty array with %d.\n", i); } } array_index_no_free(s,a,i); @@ -187,7 +190,12 @@ void simple_array_index_no_free(struct svalue *s, break; default: - error("Index is not an integer.\n"); + { + struct svalue tmp; + tmp.type=T_ARRAY; + tmp.u.array=a; + index_error(0,0,0,&tmp,ind,"Index is not an integer.\n"); + } } } diff --git a/src/builtin_functions.c b/src/builtin_functions.c index d97ed4fc7d0dc4a9b65a46c61a9f8b301052fdd3..943ede14ec677935e05567a2c2156a265fd659ce 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: builtin_functions.c,v 1.155 1999/03/17 21:49:22 hubbe Exp $"); +RCSID("$Id: builtin_functions.c,v 1.156 1999/03/19 11:40:14 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "pike_macros.h" @@ -91,9 +91,9 @@ void f_hash(INT32 args) { INT32 i; if(!args) - PIKE_ERROR("hash", "Too few arguments.\n", sp, 0); + SIMPLE_TOO_FEW_ARGS_ERROR("hash",1); if(sp[-args].type != T_STRING) - PIKE_ERROR("hash", "Bad argument 1.\n", sp, args); + SIMPLE_BAD_ARG_ERROR("hash", 1, "string"); switch(sp[-args].u.string->size_shift) { @@ -120,7 +120,7 @@ void f_hash(INT32 args) if(args > 1) { if(sp[1-args].type != T_INT) - PIKE_ERROR("hash", "Bad argument 2.\n", sp, args); + SIMPLE_BAD_ARG_ERROR("hash",2,"int"); if(!sp[1-args].u.integer) PIKE_ERROR("hash", "Modulo by zero.\n", sp, args); @@ -134,7 +134,7 @@ void f_hash(INT32 args) void f_copy_value(INT32 args) { if(!args) - PIKE_ERROR("copy_value", "Too few arguments.\n", sp, 0); + SIMPLE_TOO_FEW_ARGS_ERROR("copy_value",1); pop_n_elems(args-1); copy_svalues_recursively_no_free(sp,sp-1,1,0); @@ -145,11 +145,9 @@ void f_copy_value(INT32 args) void f_ctime(INT32 args) { time_t i; - if(!args) - PIKE_ERROR("ctime", "Too few arguments.\n", sp, args); - if(sp[-args].type != T_INT) - PIKE_ERROR("ctime", "Bad argument 1.\n", sp, args); - i=(time_t)sp[-args].u.integer; + INT_TYPE x; + get_all_args("ctime",args,"%i",&x); + i=(time_t)x; pop_n_elems(args); push_string(make_shared_string(ctime(&i))); } @@ -159,10 +157,7 @@ void f_lower_case(INT32 args) { INT32 i; struct pike_string *ret; - if(!args) - PIKE_ERROR("lower_case", "Too few arguments.\n", sp, 0); - if(sp[-args].type != T_STRING) - PIKE_ERROR("lower_case", "Bad argument 1.\n", sp, args); + get_all_args("lower_case",args,"%s",&ret); ret=begin_shared_string(sp[-args].u.string->len); MEMCPY(ret->str, sp[-args].u.string->str,sp[-args].u.string->len); @@ -180,10 +175,7 @@ void f_upper_case(INT32 args) { INT32 i; struct pike_string *ret; - if(!args) - PIKE_ERROR("upper_case", "Too few arguments.\n", sp, 0); - if(sp[-args].type != T_STRING) - PIKE_ERROR("upper_case", "Bad argument 1.\n", sp, args); + get_all_args("upper_case",args,"%s",&ret); ret=begin_shared_string(sp[-args].u.string->len); MEMCPY(ret->str, sp[-args].u.string->str,sp[-args].u.string->len); @@ -198,28 +190,23 @@ void f_upper_case(INT32 args) void f_random(INT32 args) { - if(!args) - PIKE_ERROR("random", "Too few arguments.\n", sp, 0); - if(sp[-args].type != T_INT) - PIKE_ERROR("random", "Bad argument 1.\n", sp, args); + INT_TYPE i; + get_all_args("random",args,"%i",&i); - if(sp[-args].u.integer <= 0) + if(i <= 0) { sp[-args].u.integer = 0; }else{ - sp[-args].u.integer = my_rand() % sp[-args].u.integer; + sp[-args].u.integer = my_rand() % i; } pop_n_elems(args-1); } void f_random_seed(INT32 args) { - if(!args) - PIKE_ERROR("random_seed", "Too few arguments.\n", sp, 0); - if(sp[-args].type != T_INT) - PIKE_ERROR("random_seed", "Bad argument 1.\n", sp, args); - - my_srand(sp[-args].u.integer); + INT_TYPE i; + get_all_args("random_seed",args,"%i",&i); + my_srand(i); pop_n_elems(args); } @@ -555,9 +542,9 @@ void f_combine_path(INT32 args) void f_function_object(INT32 args) { if(args < 1) - PIKE_ERROR("function_object", "Too few arguments.\n", sp, args); + SIMPLE_TOO_FEW_ARGS_ERROR("function_object",1); if(sp[-args].type != T_FUNCTION) - PIKE_ERROR("function_object", "Bad argument 1.\n", sp, args); + SIMPLE_BAD_ARG_ERROR("function_object",1,"function"); if(sp[-args].subtype == FUNCTION_BUILTIN) { @@ -573,9 +560,9 @@ void f_function_name(INT32 args) { struct pike_string *s; if(args < 1) - PIKE_ERROR("function_name", "Too few arguments.\n", sp, args); + SIMPLE_TOO_FEW_ARGS_ERROR("function_name",1); if(sp[-args].type != T_FUNCTION) - PIKE_ERROR("function_name", "Bad argument 1.\n", sp, args); + SIMPLE_BAD_ARG_ERROR("function_name",1,"function"); if(sp[-args].subtype == FUNCTION_BUILTIN) { @@ -598,7 +585,8 @@ void f_function_name(INT32 args) void f_zero_type(INT32 args) { if(args < 1) - PIKE_ERROR("zero_type", "Too few arguments.\n", sp, args); + SIMPLE_TOO_FEW_ARGS_ERROR("zero_type",1); + if(sp[-args].type != T_INT) { pop_n_elems(args); @@ -1039,11 +1027,10 @@ void f_allocate(INT32 args) struct array *a; if(args < 1) - PIKE_ERROR("allocate", "Too few arguments.\n", sp, args); + SIMPLE_TOO_FEW_ARGS_ERROR("allocate",1); if(sp[-args].type!=T_INT) - PIKE_ERROR("allocate", "Bad argument 1.\n", sp, args); - + SIMPLE_BAD_ARG_ERROR("allocate",1,"int"); size=sp[-args].u.integer; if(size < 0) diff --git a/src/module_support.c b/src/module_support.c index 3fcdb65fccecfe8b17947ebf0c0aeb6971fd2f43..2b9d66afe47c90a38e0998386ede1926efe02184 100644 --- a/src/module_support.c +++ b/src/module_support.c @@ -6,7 +6,7 @@ #include "pike_types.h" #include "error.h" -RCSID("$Id: module_support.c,v 1.20 1999/02/12 04:26:17 per Exp $"); +RCSID("$Id: module_support.c,v 1.21 1999/03/19 11:40:15 hubbe Exp $"); /* Checks that args_to_check arguments are OK. * Returns 1 if everything worked ok, zero otherwise. @@ -160,7 +160,7 @@ int va_get_args(struct svalue *s, break; case 'i': if(s->type != T_INT) return ret; - *va_arg(ap, INT32 *)=s->u.integer; + *va_arg(ap, INT_TYPE *)=s->u.integer; break; case 'D': if(s->type == T_INT) @@ -178,15 +178,15 @@ int va_get_args(struct svalue *s, break; case 'I': if(s->type == T_INT) - *va_arg(ap, INT32 *)=s->u.integer; + *va_arg(ap, INT_TYPE *)=s->u.integer; else if(s->type == T_FLOAT) - *va_arg(ap, INT32 *)=(int)s->u.float_number; + *va_arg(ap, INT_TYPE *)=(int)s->u.float_number; else { push_svalue( s ); push_text( "int" ); f_cast( ); - *va_arg(ap, INT32 *)=sp[-1].u.integer; + *va_arg(ap, INT_TYPE *)=sp[-1].u.integer; pop_stack(); } break; @@ -303,10 +303,20 @@ void get_all_args(char *fname, INT32 args, char *format, ... ) default: expected_type = "Unknown"; break; } if (ret <= args) { - error("Bad argument %d to %s(). Expected %s\n", - ret+1, fname, expected_type); + bad_arg_error( + fname, sp-args, args, + ret+1, + expected_type, + sp+ret-args, + "Bad argument %d to %s(). Expected %s\n", + ret+1, fname, expected_type); } else if ((long)(args*2) < (long)strlen(format)) { - error("Too few arguments to %s(). Expected %d arguments, got %d.\n" + bad_arg_error( + fname, sp-args, args, + ret+1, + expected_type, + 0, + "Too few arguments to %s(). Expected %d arguments, got %d.\n" "The type of the next argument is expected to be %s\n", fname, strlen(format)/2, args, expected_type); }