-
Notifications
You must be signed in to change notification settings - Fork 0
/
varinit_constant.c
36 lines (29 loc) · 975 Bytes
/
varinit_constant.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-FileCopyrightText: 2024 KUSANAGI Mitsuhisa <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <gawkapi.h>
/* gawk_api_varinit_constant is taken from the gawkextlib project */
awk_bool_t
gawk_api_varinit_constant(const gawk_api_t *api,
awk_ext_id_t ext_id,
const char *name,
awk_value_t *initial_value,
awk_scalar_t *cookie_result)
{
awk_value_t val;
if (sym_lookup(name, AWK_UNDEFINED, &val)
|| ! sym_update(name, initial_value)) {
if (initial_value->val_type == AWK_STRING)
gawk_free(initial_value->str_value.str);
return awk_false;
}
if (sym_lookup(name, AWK_SCALAR, &val)) {
*cookie_result = val.scalar_cookie;
return awk_true;
}
return awk_false;
}