diff --git a/src/program.c b/src/program.c index 95c441369e7a80e0197869450e3bd28895d370dc..239e78d3304e299c7062d68075a325d9cfa26f60 100644 --- a/src/program.c +++ b/src/program.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: program.c,v 1.92 1998/05/25 15:22:23 grubba Exp $"); +RCSID("$Id: program.c,v 1.93 1998/05/25 16:40:05 grubba Exp $"); #include "program.h" #include "object.h" #include "dynamic_buffer.h" @@ -2043,6 +2043,45 @@ struct array *program_values(struct program *p) return(res); } +void program_index_no_free(struct svalue *to, struct program *p, + struct svalue *ind) +{ + int e; + struct pike_string *s; + + if (ind->type != T_STRING) { + error("Can't index a program with a %s (expected string)\n", + get_name_of_type(ind->type)); + } + s = ind->u.string; + for (e = p->num_identifier_references; e--; ) { + struct identifier *id; + if (p->identifier_references[e].id_flags & ID_HIDDEN) { + continue; + } + id = ID_FROM_INT(p, e); + if (id->name != s) { + continue; + } + if (IDENTIFIER_IS_CONSTANT(id->identifier_flags)) { + struct program *p2 = PROG_FROM_INT(p, e); + *to = *(p2->constants + id->func.offset); + return; + } else { + if (s->len < 1024) { + error("Index \"%s\" is not constant.", s->str); + } else { + error("Index is not constant."); + } + } + } + if (s->len < 1024) { + error("No such index \"%s\".", s->str); + } else { + error("No such index."); + } +} + /* * Line number support routines, now also tells what file we are in */ diff --git a/src/program.h b/src/program.h index 5b0b40dfbb9d3123bc0910b7d22d5185b1bcaf63..825519a10e2d1c808cd9910fbfc013882a36dd6b 100644 --- a/src/program.h +++ b/src/program.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: program.h,v 1.42 1998/05/25 15:22:53 grubba Exp $ + * $Id: program.h,v 1.43 1998/05/25 16:40:26 grubba Exp $ */ #ifndef PROGRAM_H #define PROGRAM_H @@ -345,6 +345,8 @@ int store_prog_string(struct pike_string *str); int store_constant(struct svalue *foo, int equal); struct array *program_indices(struct program *p); struct array *program_values(struct program *p); +void program_index_no_free(struct svalue *to, struct program *p, + struct svalue *ind); void start_line_numbering(void); void store_linenumber(INT32 current_line, struct pike_string *current_file); char *get_line(unsigned char *pc,struct program *prog,INT32 *linep);