Debian Codegraph @

modules/lsp-runtime-lib/src/main/expr/EnvResolver.cpp

raw
1 /*
2 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2023 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-plugins-sampler
6 * Created on: 25 янв. 2023 г.
7 *
8 * lsp-plugins-sampler is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-plugins-sampler is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-plugins-sampler. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <lsp-plug.in/expr/EnvResolver.h>
23 #include <lsp-plug.in/expr/types.h>
24 #include <lsp-plug.in/runtime/system.h>
25
26 namespace lsp
27 {
28 namespace expr
29 {
30 EnvResolver::EnvResolver()
31 {
32 }
33
34 EnvResolver::~EnvResolver()
35 {
36 }
37
38 status_t EnvResolver::resolve(value_t *value, const char *name, size_t num_indexes, const ssize_t *indexes)
39 {
40 if (num_indexes > 0)
41 {
42 expr::set_value_null(value);
43 return STATUS_OK;
44 }
45
46 LSPString var;
47 status_t res = system::get_env_var(name, &var);
48 if (res != STATUS_OK)
49 {
50 if (res == STATUS_NOT_FOUND)
51 {
52 expr::set_value_null(value);
53 return STATUS_OK;
54 }
55 return res;
56 }
57
58 return expr::set_value_string(value, &var);
59 }
60
61 status_t EnvResolver::resolve(value_t *value, const LSPString *name, size_t num_indexes, const ssize_t *indexes)
62 {
63 if (num_indexes > 0)
64 {
65 expr::set_value_null(value);
66 return STATUS_OK;
67 }
68
69 LSPString var;
70 status_t res = system::get_env_var(name, &var);
71 if (res != STATUS_OK)
72 {
73 if (res == STATUS_NOT_FOUND)
74 {
75 expr::set_value_null(value);
76 return STATUS_OK;
77 }
78 return res;
79 }
80
81 return expr::set_value_string(value, &var);
82 }
83
84 } /* namespace expr */
85 } /* namespace lsp */
86
87