OpenVAS Libraries  9.0.3
nasl_lex_ctxt.c
Go to the documentation of this file.
1 /* Nessus Attack Scripting Language
2  *
3  * Copyright (C) 2002 - 2004 Tenable Network Security
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2,
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  */
19 
20 #include <glib.h> /* for g_free() */
21 
22 #include "nasl_func.h"
23 #include "nasl_tree.h"
24 #include "nasl_var.h"
25 #include "nasl_global_ctxt.h"
26 #include "nasl_lex_ctxt.h"
27 
28 lex_ctxt *
30 {
31  lex_ctxt *c = g_malloc0 (sizeof (lex_ctxt));
32  int i;
33 
34  c->ctx_vars.hash_elt = g_malloc0 (sizeof (named_nasl_var) * VAR_NAME_HASH);
35  c->ctx_vars.num_elt = NULL;
36  c->ctx_vars.max_idx = 0;
37  for (i = 0; i < FUNC_NAME_HASH; i++)
38  c->functions[i] = NULL;
39  c->oid = NULL;
40  c->ret_val = NULL;
41  c->fct_ctxt = 0;
42  return c;
43 }
44 
45 void
47 {
48  int i;
49 
50 #if 0
51  if (c->exit_flag && c->up_ctxt != NULL)
52  ((lex_ctxt *) c->up_ctxt)->exit_flag = 1;
53 #endif
54  deref_cell (c->ret_val);
55  free_array (&c->ctx_vars);
56  for (i = 0; i < FUNC_NAME_HASH; i++)
57  {
58  free_func_chain (c->functions[i]);
59  }
60  g_free (c);
61 }
62 
63 void
65 {
66  int i;
67  named_nasl_var *v;
68  nasl_func *f;
69 
70  printf ("--------<CTXT>--------\n");
71  if (c->fct_ctxt)
72  printf ("Is a function context\n");
73  if (c->up_ctxt == NULL)
74  printf ("Is the top level context\n");
75  if (c->ret_val)
76  {
77  printf ("Return value\n");
79  }
80 
81  printf ("Variables:\n");
82  for (i = 0; i < VAR_NAME_HASH; i++)
83  for (v = c->ctx_vars.hash_elt[i]; v != NULL; v = v->next_var)
84  printf ("%s\t", v->var_name);
85  putchar ('\n');
86 
87  printf ("Functions:\n");
88  for (i = 0; i < FUNC_NAME_HASH; i++)
89  for (f = c->functions[i]; f != NULL; f = f->next_func)
90  printf ("%s\t", f->func_name);
91  putchar ('\n');
92 
93  printf ("----------------------\n");
94 }
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:44
struct st_n_nasl_var * next_var
Definition: nasl_var.h:74
char * var_name
Definition: nasl_var.h:70
void nasl_dump_tree(const tree_cell *c)
Definition: nasl_tree.c:439
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:202
#define FUNC_NAME_HASH
Definition: nasl_func.h:22
char * func_name
Definition: nasl_func.h:32
struct st_nasl_func * next_func
Definition: nasl_func.h:38
void free_lex_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:46
nasl_func * functions[FUNC_NAME_HASH]
Definition: nasl_lex_ctxt.h:46
lex_ctxt * init_empty_lex_ctxt()
Definition: nasl_lex_ctxt.c:29
#define VAR_NAME_HASH
Definition: nasl_var.h:31
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:44
unsigned fct_ctxt
Definition: nasl_lex_ctxt.h:35
void free_func_chain(nasl_func *f)
Definition: nasl_func.c:375
tree_cell * ret_val
Definition: nasl_lex_ctxt.h:34
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:45
const char * oid
Definition: nasl_lex_ctxt.h:40
void free_array(nasl_array *a)
Definition: nasl_var.c:366
void dump_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:64
struct struct_lex_ctxt * up_ctxt
Definition: nasl_lex_ctxt.h:33