xref: /aosp_15_r20/external/sandboxed-api/contrib/jsonnet/jsonnet_helper.h (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef CONTRIB_JSONNET_JSONNET_HELPER_H_
16 #define CONTRIB_JSONNET_JSONNET_HELPER_H_
17 
18 extern "C" {
19 #include <libjsonnet.h>
20 #include <libjsonnet_fmt.h>
21 }
22 
23 #include "jsonnet/cmd/utils.h"  // NOLINT(build/include)
24 
25 extern "C" {
26 
27 struct JsonnetVm* c_jsonnet_make(void);
28 
29 void c_jsonnet_destroy(struct JsonnetVm* vm);
30 
31 char* c_jsonnet_evaluate_snippet(struct JsonnetVm* vm, const char* filename,
32                                  char* snippet, int* error);
33 
34 char* c_jsonnet_evaluate_snippet_multi(struct JsonnetVm* vm,
35                                        const char* filename,
36                                        const char* snippet, int* error);
37 
38 char* c_jsonnet_evaluate_snippet_stream(struct JsonnetVm* vm,
39                                         const char* filename,
40                                         const char* snippet, int* error);
41 
42 char* c_read_input(bool filename_is_code, const char* filename);
43 
44 void c_free_input(char* input);
45 
46 bool c_write_output_file(const char* output, const char* output_file);
47 
48 char* c_jsonnet_realloc(struct JsonnetVm* vm, char* str, size_t sz);
49 
50 bool c_write_multi_output_files(char* output, char* output_dir,
51                                 bool show_output_file_names);
52 
53 bool write_multi_output_files(char* output, const std::string& output_dir,
54                               bool show_output_file_names);
55 
56 bool c_write_output_stream(char* output, char* output_file);
57 
58 bool write_output_stream(char* output, const std::string& output_file);
59 
60 char* c_jsonnet_fmt_snippet(struct JsonnetVm* vm, const char* filename,
61                             const char* snippet, int* error);
62 }
63 
64 #endif  // CONTRIB_JSONNET_JSONNET_HELPER_H_
65