OpenVAS Scanner  7.0.1~git
nasl_lex_ctxt.c
Go to the documentation of this file.
1 /* Based on work Copyright (C) 2002 - 2004 Tenable Network Security
2  *
3  * SPDX-License-Identifier: GPL-2.0-only
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 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 St, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include "nasl_lex_ctxt.h"
20 
21 #include "nasl_func.h"
22 #include "nasl_global_ctxt.h"
23 #include "nasl_tree.h"
24 #include "nasl_var.h"
25 
26 #include <glib.h> /* for g_free() */
27 
28 void
30 
31 lex_ctxt *
33 {
34  lex_ctxt *c = g_malloc0 (sizeof (lex_ctxt));
35 
36  c->ctx_vars.hash_elt = g_malloc0 (sizeof (named_nasl_var *) * VAR_NAME_HASH);
37  c->ctx_vars.num_elt = NULL;
38  c->ctx_vars.max_idx = 0;
39  c->functions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
40  (GDestroyNotify) free_func);
41  c->oid = NULL;
42  c->ret_val = NULL;
43  c->fct_ctxt = 0;
44 
50 
51  return c;
52 }
53 
54 void
56 {
57  deref_cell (c->ret_val);
58  free_array (&c->ctx_vars);
59  g_hash_table_destroy (c->functions);
60  g_free (c);
61 }
62 
63 void
65 {
66  int i;
67  named_nasl_var *v;
68 
69  printf ("--------<CTXT>--------\n");
70  if (c->fct_ctxt)
71  printf ("Is a function context\n");
72  if (c->up_ctxt == NULL)
73  printf ("Is the top level context\n");
74  if (c->ret_val)
75  {
76  printf ("Return value\n");
78  }
79 
80  printf ("Variables:\n");
81  for (i = 0; i < VAR_NAME_HASH; i++)
82  for (v = c->ctx_vars.hash_elt[i]; v != NULL; v = v->next_var)
83  printf ("%s\t", v->var_name);
84  putchar ('\n');
85 
86  printf ("----------------------\n");
87 }
nasl_array ctx_vars
Definition: nasl_lex_ctxt.h:46
struct st_n_nasl_var * next_var
Definition: nasl_var.h:73
char * var_name
Definition: nasl_var.h:69
void nasl_dump_tree(const tree_cell *c)
Definition: nasl_tree.c:377
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:192
void free_lex_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:55
void init_nasl_library(lex_ctxt *)
Adds "built-in" variable and function definitions to a context.
Definition: nasl_init.c:446
lex_ctxt * init_empty_lex_ctxt()
Definition: nasl_lex_ctxt.c:32
#define VAR_NAME_HASH
Definition: nasl_var.h:33
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:46
unsigned fct_ctxt
Definition: nasl_lex_ctxt.h:37
void free_func(nasl_func *f)
Definition: nasl_func.c:269
GHashTable * functions
Definition: nasl_lex_ctxt.h:48
tree_cell * ret_val
Definition: nasl_lex_ctxt.h:36
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:47
const char * oid
Definition: nasl_lex_ctxt.h:42
void free_array(nasl_array *a)
Definition: nasl_var.c:354
void dump_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:64
struct struct_lex_ctxt * up_ctxt
Definition: nasl_lex_ctxt.h:35