1 | #ifndef SASS_C_CONTEXT_H |
2 | #define SASS_C_CONTEXT_H |
3 | |
4 | #include <stddef.h> |
5 | #include <stdbool.h> |
6 | #include <sass/base.h> |
7 | #include <sass/values.h> |
8 | #include <sass/functions.h> |
9 | |
10 | #ifdef __cplusplus |
11 | extern "C" { |
12 | #endif |
13 | |
14 | |
15 | // Forward declaration |
16 | struct Sass_Compiler; |
17 | |
18 | // Forward declaration |
19 | struct Sass_Options; // base struct |
20 | struct Sass_Context; // : Sass_Options |
21 | struct Sass_File_Context; // : Sass_Context |
22 | struct Sass_Data_Context; // : Sass_Context |
23 | |
24 | // Compiler states |
25 | enum Sass_Compiler_State { |
26 | SASS_COMPILER_CREATED, |
27 | SASS_COMPILER_PARSED, |
28 | SASS_COMPILER_EXECUTED |
29 | }; |
30 | |
31 | // Create and initialize an option struct |
32 | ADDAPI struct Sass_Options* ADDCALL sass_make_options (void); |
33 | // Create and initialize a specific context |
34 | ADDAPI struct Sass_File_Context* ADDCALL sass_make_file_context (const char* input_path); |
35 | ADDAPI struct Sass_Data_Context* ADDCALL sass_make_data_context (char* source_string); |
36 | |
37 | // Call the compilation step for the specific context |
38 | ADDAPI int ADDCALL sass_compile_file_context (struct Sass_File_Context* ctx); |
39 | ADDAPI int ADDCALL sass_compile_data_context (struct Sass_Data_Context* ctx); |
40 | |
41 | // Create a sass compiler instance for more control |
42 | ADDAPI struct Sass_Compiler* ADDCALL sass_make_file_compiler (struct Sass_File_Context* file_ctx); |
43 | ADDAPI struct Sass_Compiler* ADDCALL sass_make_data_compiler (struct Sass_Data_Context* data_ctx); |
44 | |
45 | // Execute the different compilation steps individually |
46 | // Useful if you only want to query the included files |
47 | ADDAPI int ADDCALL sass_compiler_parse(struct Sass_Compiler* compiler); |
48 | ADDAPI int ADDCALL sass_compiler_execute(struct Sass_Compiler* compiler); |
49 | |
50 | // Release all memory allocated with the compiler |
51 | // This does _not_ include any contexts or options |
52 | ADDAPI void ADDCALL sass_delete_compiler(struct Sass_Compiler* compiler); |
53 | ADDAPI void ADDCALL sass_delete_options(struct Sass_Options* options); |
54 | |
55 | // Release all memory allocated and also ourself |
56 | ADDAPI void ADDCALL sass_delete_file_context (struct Sass_File_Context* ctx); |
57 | ADDAPI void ADDCALL sass_delete_data_context (struct Sass_Data_Context* ctx); |
58 | |
59 | // Getters for context from specific implementation |
60 | ADDAPI struct Sass_Context* ADDCALL sass_file_context_get_context (struct Sass_File_Context* file_ctx); |
61 | ADDAPI struct Sass_Context* ADDCALL sass_data_context_get_context (struct Sass_Data_Context* data_ctx); |
62 | |
63 | // Getters for Context_Options from Sass_Context |
64 | ADDAPI struct Sass_Options* ADDCALL sass_context_get_options (struct Sass_Context* ctx); |
65 | ADDAPI struct Sass_Options* ADDCALL sass_file_context_get_options (struct Sass_File_Context* file_ctx); |
66 | ADDAPI struct Sass_Options* ADDCALL sass_data_context_get_options (struct Sass_Data_Context* data_ctx); |
67 | ADDAPI void ADDCALL sass_file_context_set_options (struct Sass_File_Context* file_ctx, struct Sass_Options* opt); |
68 | ADDAPI void ADDCALL sass_data_context_set_options (struct Sass_Data_Context* data_ctx, struct Sass_Options* opt); |
69 | |
70 | |
71 | // Getters for Context_Option values |
72 | ADDAPI int ADDCALL sass_option_get_precision (struct Sass_Options* options); |
73 | ADDAPI enum Sass_Output_Style ADDCALL sass_option_get_output_style (struct Sass_Options* options); |
74 | ADDAPI bool ADDCALL (struct Sass_Options* options); |
75 | ADDAPI bool ADDCALL sass_option_get_source_map_embed (struct Sass_Options* options); |
76 | ADDAPI bool ADDCALL sass_option_get_source_map_contents (struct Sass_Options* options); |
77 | ADDAPI bool ADDCALL sass_option_get_source_map_file_urls (struct Sass_Options* options); |
78 | ADDAPI bool ADDCALL sass_option_get_omit_source_map_url (struct Sass_Options* options); |
79 | ADDAPI bool ADDCALL sass_option_get_is_indented_syntax_src (struct Sass_Options* options); |
80 | ADDAPI const char* ADDCALL sass_option_get_indent (struct Sass_Options* options); |
81 | ADDAPI const char* ADDCALL sass_option_get_linefeed (struct Sass_Options* options); |
82 | ADDAPI const char* ADDCALL sass_option_get_input_path (struct Sass_Options* options); |
83 | ADDAPI const char* ADDCALL sass_option_get_output_path (struct Sass_Options* options); |
84 | ADDAPI const char* ADDCALL sass_option_get_source_map_file (struct Sass_Options* options); |
85 | ADDAPI const char* ADDCALL sass_option_get_source_map_root (struct Sass_Options* options); |
86 | ADDAPI Sass_Importer_List ADDCALL (struct Sass_Options* options); |
87 | ADDAPI Sass_Importer_List ADDCALL sass_option_get_c_importers (struct Sass_Options* options); |
88 | ADDAPI Sass_Function_List ADDCALL sass_option_get_c_functions (struct Sass_Options* options); |
89 | |
90 | // Setters for Context_Option values |
91 | ADDAPI void ADDCALL sass_option_set_precision (struct Sass_Options* options, int precision); |
92 | ADDAPI void ADDCALL sass_option_set_output_style (struct Sass_Options* options, enum Sass_Output_Style output_style); |
93 | ADDAPI void ADDCALL (struct Sass_Options* options, bool ); |
94 | ADDAPI void ADDCALL sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed); |
95 | ADDAPI void ADDCALL sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents); |
96 | ADDAPI void ADDCALL sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls); |
97 | ADDAPI void ADDCALL sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url); |
98 | ADDAPI void ADDCALL sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src); |
99 | ADDAPI void ADDCALL sass_option_set_indent (struct Sass_Options* options, const char* indent); |
100 | ADDAPI void ADDCALL sass_option_set_linefeed (struct Sass_Options* options, const char* linefeed); |
101 | ADDAPI void ADDCALL sass_option_set_input_path (struct Sass_Options* options, const char* input_path); |
102 | ADDAPI void ADDCALL sass_option_set_output_path (struct Sass_Options* options, const char* output_path); |
103 | ADDAPI void ADDCALL sass_option_set_plugin_path (struct Sass_Options* options, const char* plugin_path); |
104 | ADDAPI void ADDCALL sass_option_set_include_path (struct Sass_Options* options, const char* include_path); |
105 | ADDAPI void ADDCALL sass_option_set_source_map_file (struct Sass_Options* options, const char* source_map_file); |
106 | ADDAPI void ADDCALL sass_option_set_source_map_root (struct Sass_Options* options, const char* source_map_root); |
107 | ADDAPI void ADDCALL (struct Sass_Options* options, Sass_Importer_List ); |
108 | ADDAPI void ADDCALL sass_option_set_c_importers (struct Sass_Options* options, Sass_Importer_List c_importers); |
109 | ADDAPI void ADDCALL sass_option_set_c_functions (struct Sass_Options* options, Sass_Function_List c_functions); |
110 | |
111 | |
112 | // Getters for Sass_Context values |
113 | ADDAPI const char* ADDCALL sass_context_get_output_string (struct Sass_Context* ctx); |
114 | ADDAPI int ADDCALL sass_context_get_error_status (struct Sass_Context* ctx); |
115 | ADDAPI const char* ADDCALL sass_context_get_error_json (struct Sass_Context* ctx); |
116 | ADDAPI const char* ADDCALL sass_context_get_error_text (struct Sass_Context* ctx); |
117 | ADDAPI const char* ADDCALL sass_context_get_error_message (struct Sass_Context* ctx); |
118 | ADDAPI const char* ADDCALL sass_context_get_error_file (struct Sass_Context* ctx); |
119 | ADDAPI const char* ADDCALL sass_context_get_error_src (struct Sass_Context* ctx); |
120 | ADDAPI size_t ADDCALL sass_context_get_error_line (struct Sass_Context* ctx); |
121 | ADDAPI size_t ADDCALL sass_context_get_error_column (struct Sass_Context* ctx); |
122 | ADDAPI const char* ADDCALL sass_context_get_source_map_string (struct Sass_Context* ctx); |
123 | ADDAPI char** ADDCALL sass_context_get_included_files (struct Sass_Context* ctx); |
124 | |
125 | // Getters for options include path array |
126 | ADDAPI size_t ADDCALL sass_option_get_include_path_size(struct Sass_Options* options); |
127 | ADDAPI const char* ADDCALL sass_option_get_include_path(struct Sass_Options* options, size_t i); |
128 | // Plugin paths to load dynamic libraries work the same |
129 | ADDAPI size_t ADDCALL sass_option_get_plugin_path_size(struct Sass_Options* options); |
130 | ADDAPI const char* ADDCALL sass_option_get_plugin_path(struct Sass_Options* options, size_t i); |
131 | |
132 | // Calculate the size of the stored null terminated array |
133 | ADDAPI size_t ADDCALL sass_context_get_included_files_size (struct Sass_Context* ctx); |
134 | |
135 | // Take ownership of memory (value on context is set to 0) |
136 | ADDAPI char* ADDCALL sass_context_take_error_json (struct Sass_Context* ctx); |
137 | ADDAPI char* ADDCALL sass_context_take_error_text (struct Sass_Context* ctx); |
138 | ADDAPI char* ADDCALL sass_context_take_error_message (struct Sass_Context* ctx); |
139 | ADDAPI char* ADDCALL sass_context_take_error_file (struct Sass_Context* ctx); |
140 | ADDAPI char* ADDCALL sass_context_take_error_src (struct Sass_Context* ctx); |
141 | ADDAPI char* ADDCALL sass_context_take_output_string (struct Sass_Context* ctx); |
142 | ADDAPI char* ADDCALL sass_context_take_source_map_string (struct Sass_Context* ctx); |
143 | ADDAPI char** ADDCALL sass_context_take_included_files (struct Sass_Context* ctx); |
144 | |
145 | // Getters for Sass_Compiler options |
146 | ADDAPI enum Sass_Compiler_State ADDCALL sass_compiler_get_state(struct Sass_Compiler* compiler); |
147 | ADDAPI struct Sass_Context* ADDCALL sass_compiler_get_context(struct Sass_Compiler* compiler); |
148 | ADDAPI struct Sass_Options* ADDCALL sass_compiler_get_options(struct Sass_Compiler* compiler); |
149 | ADDAPI size_t ADDCALL sass_compiler_get_import_stack_size(struct Sass_Compiler* compiler); |
150 | ADDAPI Sass_Import_Entry ADDCALL sass_compiler_get_last_import(struct Sass_Compiler* compiler); |
151 | ADDAPI Sass_Import_Entry ADDCALL sass_compiler_get_import_entry(struct Sass_Compiler* compiler, size_t idx); |
152 | ADDAPI size_t ADDCALL sass_compiler_get_callee_stack_size(struct Sass_Compiler* compiler); |
153 | ADDAPI Sass_Callee_Entry ADDCALL sass_compiler_get_last_callee(struct Sass_Compiler* compiler); |
154 | ADDAPI Sass_Callee_Entry ADDCALL sass_compiler_get_callee_entry(struct Sass_Compiler* compiler, size_t idx); |
155 | |
156 | // Push function for paths (no manipulation support for now) |
157 | ADDAPI void ADDCALL sass_option_push_plugin_path (struct Sass_Options* options, const char* path); |
158 | ADDAPI void ADDCALL sass_option_push_include_path (struct Sass_Options* options, const char* path); |
159 | |
160 | // Resolve a file via the given include paths in the sass option struct |
161 | // find_file looks for the exact file name while find_include does a regular sass include |
162 | ADDAPI char* ADDCALL sass_find_file (const char* path, struct Sass_Options* opt); |
163 | ADDAPI char* ADDCALL sass_find_include (const char* path, struct Sass_Options* opt); |
164 | |
165 | // Resolve a file relative to last import or include paths in the sass option struct |
166 | // find_file looks for the exact file name while find_include does a regular sass include |
167 | ADDAPI char* ADDCALL sass_compiler_find_file (const char* path, struct Sass_Compiler* compiler); |
168 | ADDAPI char* ADDCALL sass_compiler_find_include (const char* path, struct Sass_Compiler* compiler); |
169 | |
170 | #ifdef __cplusplus |
171 | } // __cplusplus defined. |
172 | #endif |
173 | |
174 | #endif |
175 | |