From e43583e1cdd14c167ed56a3cf8db0ebae646f4ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Mon, 25 May 1998 18:40:26 +0200
Subject: [PATCH] Added program_index_no_free().

Rev: src/program.c:1.93
Rev: src/program.h:1.43
---
 src/program.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 src/program.h |  4 +++-
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/src/program.c b/src/program.c
index 95c441369e..239e78d330 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 5b0b40dfbb..825519a10e 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);
-- 
GitLab