Blender  V2.93
text_format_pov_ini.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14  */
15 
20 #include <string.h>
21 
22 #include "BLI_blenlib.h"
23 
24 #include "DNA_space_types.h"
25 #include "DNA_text_types.h"
26 
27 #include "BKE_text.h"
28 
29 #include "text_format.h"
30 
31 /* *** POV INI Keywords (for format_line) *** */
32 
44 static int txtfmt_ini_find_keyword(const char *string)
45 {
46  int i, len;
47 
48  /* Keep aligned args for readability. */
49  /* clang-format off */
50 
51  /* Language Directives */
52  if (STR_LITERAL_STARTSWITH(string, "deprecated", len)) { i = len;
53  } else if (STR_LITERAL_STARTSWITH(string, "statistics", len)) { i = len;
54  } else if (STR_LITERAL_STARTSWITH(string, "declare", len)) { i = len;
55  } else if (STR_LITERAL_STARTSWITH(string, "default", len)) { i = len;
56  } else if (STR_LITERAL_STARTSWITH(string, "version", len)) { i = len;
57  } else if (STR_LITERAL_STARTSWITH(string, "warning", len)) { i = len;
58  } else if (STR_LITERAL_STARTSWITH(string, "include", len)) { i = len;
59  } else if (STR_LITERAL_STARTSWITH(string, "fclose", len)) { i = len;
60  } else if (STR_LITERAL_STARTSWITH(string, "ifndef", len)) { i = len;
61  } else if (STR_LITERAL_STARTSWITH(string, "append", len)) { i = len;
62  } else if (STR_LITERAL_STARTSWITH(string, "elseif", len)) { i = len;
63  } else if (STR_LITERAL_STARTSWITH(string, "debug", len)) { i = len;
64  } else if (STR_LITERAL_STARTSWITH(string, "error", len)) { i = len;
65  } else if (STR_LITERAL_STARTSWITH(string, "fopen", len)) { i = len;
66  } else if (STR_LITERAL_STARTSWITH(string, "ifdef", len)) { i = len;
67  } else if (STR_LITERAL_STARTSWITH(string, "local", len)) { i = len;
68  } else if (STR_LITERAL_STARTSWITH(string, "macro", len)) { i = len;
69  } else if (STR_LITERAL_STARTSWITH(string, "range", len)) { i = len;
70  } else if (STR_LITERAL_STARTSWITH(string, "render", len)) { i = len;
71  } else if (STR_LITERAL_STARTSWITH(string, "break", len)) { i = len;
72  } else if (STR_LITERAL_STARTSWITH(string, "switch", len)) { i = len;
73  } else if (STR_LITERAL_STARTSWITH(string, "undef", len)) { i = len;
74  } else if (STR_LITERAL_STARTSWITH(string, "while", len)) { i = len;
75  } else if (STR_LITERAL_STARTSWITH(string, "write", len)) { i = len;
76  } else if (STR_LITERAL_STARTSWITH(string, "case", len)) { i = len;
77  } else if (STR_LITERAL_STARTSWITH(string, "else", len)) { i = len;
78  } else if (STR_LITERAL_STARTSWITH(string, "read", len)) { i = len;
79  } else if (STR_LITERAL_STARTSWITH(string, "end", len)) { i = len;
80  } else if (STR_LITERAL_STARTSWITH(string, "for", len)) { i = len;
81  } else if (STR_LITERAL_STARTSWITH(string, "if", len)) { i = len;
82 
83  } else if (STR_LITERAL_STARTSWITH(string, "I", len)) { i = len;
84  } else if (STR_LITERAL_STARTSWITH(string, "S", len)) { i = len;
85  } else if (STR_LITERAL_STARTSWITH(string, "A", len)) { i = len;
86  } else if (STR_LITERAL_STARTSWITH(string, "Q", len)) { i = len;
87  } else if (STR_LITERAL_STARTSWITH(string, "U", len)) { i = len;
88  } else if (STR_LITERAL_STARTSWITH(string, "F", len)) { i = len;
89  } else if (STR_LITERAL_STARTSWITH(string, "C", len)) { i = len;
90  } else if (STR_LITERAL_STARTSWITH(string, "N", len)) { i = len;
91  } else if (STR_LITERAL_STARTSWITH(string, "P", len)) { i = len;
92  } else if (STR_LITERAL_STARTSWITH(string, "T", len)) { i = len;
93 
94  } else { i = 0;
95  }
96 
97  /* clang-format on */
98 
99  /* If next source char is an identifier (eg. 'i' in "definite") no match */
100  return (i == 0 || text_check_identifier(string[i])) ? -1 : i;
101 }
102 
103 static int txtfmt_ini_find_reserved(const char *string)
104 {
105  int i, len;
106 
107  /* Keep aligned args for readability. */
108  /* clang-format off */
109 
110  /* POV-Ray Built-in INI Variables
111  * list is from...
112  * http://www.povray.org/documentation/view/3.7.0/212/
113  */
114  if (STR_LITERAL_STARTSWITH(string, "RenderCompleteSoundEnabled", len)) { i = len;
115  } else if (STR_LITERAL_STARTSWITH(string, "Create_Continue_Trace_Log", len)) { i = len;
116  } else if (STR_LITERAL_STARTSWITH(string, "ParseErrorSoundEnabled", len)) { i = len;
117  } else if (STR_LITERAL_STARTSWITH(string, "RenderErrorSoundEnabled", len)) { i = len;
118  } else if (STR_LITERAL_STARTSWITH(string, "HideWhenMainMinimized", len)) { i = len;
119  } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Confidence", len)) { i = len;
120  } else if (STR_LITERAL_STARTSWITH(string, "RenderCompleteSound", len)) { i = len;
121  } else if (STR_LITERAL_STARTSWITH(string, "ParseErrorSound", len)) { i = len;
122  } else if (STR_LITERAL_STARTSWITH(string, "RenderErrorSound", len)) { i = len;
123  } else if (STR_LITERAL_STARTSWITH(string, "UseExtensions", len)) { i = len;
124  } else if (STR_LITERAL_STARTSWITH(string, "ReadWriteSourceDir", len)) { i = len;
125  } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionLeft", len)) { i = len;
126  } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionTop", len)) { i = len;
127  } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionRight", len)) { i = len;
128  } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionBottom", len)) { i = len;
129  } else if (STR_LITERAL_STARTSWITH(string, "Pre_Scene_Command", len)) { i = len;
130  } else if (STR_LITERAL_STARTSWITH(string, "Pre_Frame_Command", len)) { i = len;
131  } else if (STR_LITERAL_STARTSWITH(string, "Post_Scene_Command", len)) { i = len;
132  } else if (STR_LITERAL_STARTSWITH(string, "Post_Frame_Command", len)) { i = len;
133  } else if (STR_LITERAL_STARTSWITH(string, "User_Abort_Command", len)) { i = len;
134  } else if (STR_LITERAL_STARTSWITH(string, "Fatal_Error_Command", len)) { i = len;
135  } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionX", len)) { i = len;
136  } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionY", len)) { i = len;
137  } else if (STR_LITERAL_STARTSWITH(string, "Pre_Scene_Return", len)) { i = len;
138  } else if (STR_LITERAL_STARTSWITH(string, "Pre_Frame_Return", len)) { i = len;
139  } else if (STR_LITERAL_STARTSWITH(string, "Post_Scene_Return", len)) { i = len;
140  } else if (STR_LITERAL_STARTSWITH(string, "Post_Frame_Return", len)) { i = len;
141  } else if (STR_LITERAL_STARTSWITH(string, "User_Abort_Return", len)) { i = len;
142  } else if (STR_LITERAL_STARTSWITH(string, "Fatal_Error_Return", len)) { i = len;
143  } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Threshold", len)) { i = len;
144  } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Gamma", len)) { i = len;
145  } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Depth", len)) { i = len;
146  } else if (STR_LITERAL_STARTSWITH(string, "input_file_name", len)) { i = len;
147  } else if (STR_LITERAL_STARTSWITH(string, "Subset_Start_Frame", len)) { i = len;
148  } else if (STR_LITERAL_STARTSWITH(string, "Subset_End_Frame", len)) { i = len;
149  } else if (STR_LITERAL_STARTSWITH(string, "UseToolbar", len)) { i = len;
150  } else if (STR_LITERAL_STARTSWITH(string, "UseTooltips", len)) { i = len;
151  } else if (STR_LITERAL_STARTSWITH(string, "Frame_Step", len)) { i = len;
152  } else if (STR_LITERAL_STARTSWITH(string, "Cyclic_Animation", len)) { i = len;
153  } else if (STR_LITERAL_STARTSWITH(string, "Field_Render", len)) { i = len;
154  } else if (STR_LITERAL_STARTSWITH(string, "Odd_Field", len)) { i = len;
155  } else if (STR_LITERAL_STARTSWITH(string, "final_clock", len)) { i = len;
156  } else if (STR_LITERAL_STARTSWITH(string, "final_frame", len)) { i = len;
157  } else if (STR_LITERAL_STARTSWITH(string, "frame_number", len)) { i = len;
158  } else if (STR_LITERAL_STARTSWITH(string, "initial_clock", len)) { i = len;
159  } else if (STR_LITERAL_STARTSWITH(string, "initial_frame", len)) { i = len;
160  } else if (STR_LITERAL_STARTSWITH(string, "image_height", len)) { i = len;
161  } else if (STR_LITERAL_STARTSWITH(string, "image_width", len)) { i = len;
162  } else if (STR_LITERAL_STARTSWITH(string, "Start_Column", len)) { i = len;
163  } else if (STR_LITERAL_STARTSWITH(string, "Start_Row", len)) { i = len;
164  } else if (STR_LITERAL_STARTSWITH(string, "End_Column", len)) { i = len;
165  } else if (STR_LITERAL_STARTSWITH(string, "End_Row", len)) { i = len;
166  } else if (STR_LITERAL_STARTSWITH(string, "Test_Abort_Count", len)) { i = len;
167  } else if (STR_LITERAL_STARTSWITH(string, "Test_Abort", len)) { i = len;
168  } else if (STR_LITERAL_STARTSWITH(string, "Continue_Trace", len)) { i = len;
169  } else if (STR_LITERAL_STARTSWITH(string, "Bounding_Method", len)) { i = len;
170  } else if (STR_LITERAL_STARTSWITH(string, "Create_Ini", len)) { i = len;
171  } else if (STR_LITERAL_STARTSWITH(string, "Display_Gamma", len)) { i = len;
172  } else if (STR_LITERAL_STARTSWITH(string, "Display", len)) { i = len;
173  } else if (STR_LITERAL_STARTSWITH(string, "Version", len)) { i = len;
174  } else if (STR_LITERAL_STARTSWITH(string, "Pause_When_Done", len)) { i = len;
175  } else if (STR_LITERAL_STARTSWITH(string, "Verbose", len)) { i = len;
176  } else if (STR_LITERAL_STARTSWITH(string, "Preview_Start_Size", len)) { i = len;
177  } else if (STR_LITERAL_STARTSWITH(string, "Preview_End_Size", len)) { i = len;
178  } else if (STR_LITERAL_STARTSWITH(string, "Output_to_File", len)) { i = len;
179  } else if (STR_LITERAL_STARTSWITH(string, "Input_File_Name", len)) { i = len;
180  } else if (STR_LITERAL_STARTSWITH(string, "Output_File_Name", len)) { i = len;
181  } else if (STR_LITERAL_STARTSWITH(string, "Output_File_Type", len)) { i = len;
182  } else if (STR_LITERAL_STARTSWITH(string, "Output_Alpha", len)) { i = len;
183  } else if (STR_LITERAL_STARTSWITH(string, "Bits_Per_Color", len)) { i = len;
184  } else if (STR_LITERAL_STARTSWITH(string, "Compression", len)) { i = len;
185  } else if (STR_LITERAL_STARTSWITH(string, "Dither_Method", len)) { i = len;
186  } else if (STR_LITERAL_STARTSWITH(string, "Include_Header", len)) { i = len;
187  } else if (STR_LITERAL_STARTSWITH(string, "Library_Path", len)) { i = len;
188  } else if (STR_LITERAL_STARTSWITH(string, "Debug_Console", len)) { i = len;
189  } else if (STR_LITERAL_STARTSWITH(string, "Fatal_Console", len)) { i = len;
190  } else if (STR_LITERAL_STARTSWITH(string, "Render_Console", len)) { i = len;
191  } else if (STR_LITERAL_STARTSWITH(string, "Statistic_Console", len)) { i = len;
192  } else if (STR_LITERAL_STARTSWITH(string, "Warning_Console", len)) { i = len;
193  } else if (STR_LITERAL_STARTSWITH(string, "Warning_Level", len)) { i = len;
194  } else if (STR_LITERAL_STARTSWITH(string, "All_Console", len)) { i = len;
195  } else if (STR_LITERAL_STARTSWITH(string, "Debug_File", len)) { i = len;
196  } else if (STR_LITERAL_STARTSWITH(string, "Fatal_File", len)) { i = len;
197  } else if (STR_LITERAL_STARTSWITH(string, "Render_File", len)) { i = len;
198  } else if (STR_LITERAL_STARTSWITH(string, "Statistic_File", len)) { i = len;
199  } else if (STR_LITERAL_STARTSWITH(string, "Warning_File", len)) { i = len;
200  } else if (STR_LITERAL_STARTSWITH(string, "All_File", len)) { i = len;
201  } else if (STR_LITERAL_STARTSWITH(string, "Quality", len)) { i = len;
202  } else if (STR_LITERAL_STARTSWITH(string, "Bounding_Threshold", len)) { i = len;
203  } else if (STR_LITERAL_STARTSWITH(string, "Bounding", len)) { i = len;
204  } else if (STR_LITERAL_STARTSWITH(string, "Light_Buffer", len)) { i = len;
205  } else if (STR_LITERAL_STARTSWITH(string, "Vista_Buffer", len)) { i = len;
206  } else if (STR_LITERAL_STARTSWITH(string, "Remove_Bounds", len)) { i = len;
207  } else if (STR_LITERAL_STARTSWITH(string, "Split_Unions", len)) { i = len;
208  } else if (STR_LITERAL_STARTSWITH(string, "Antialias", len)) { i = len;
209  } else if (STR_LITERAL_STARTSWITH(string, "Glare_Desaturation", len)) { i = len;
210  } else if (STR_LITERAL_STARTSWITH(string, "Sampling_Method", len)) { i = len;
211  } else if (STR_LITERAL_STARTSWITH(string, "Stochastic_Seed", len)) { i = len;
212  } else if (STR_LITERAL_STARTSWITH(string, "Jitter_Amount", len)) { i = len;
213  } else if (STR_LITERAL_STARTSWITH(string, "Jitter", len)) { i = len;
214  } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Depth", len)) { i = len;
215  } else if (STR_LITERAL_STARTSWITH(string, "CheckNewVersion", len)) { i = len;
216  } else if (STR_LITERAL_STARTSWITH(string, "RunCount", len)) { i = len;
217  } else if (STR_LITERAL_STARTSWITH(string, "CommandLine", len)) { i = len;
218  } else if (STR_LITERAL_STARTSWITH(string, "TextColour", len)) { i = len;
219  } else if (STR_LITERAL_STARTSWITH(string, "WarningColour", len)) { i = len;
220  } else if (STR_LITERAL_STARTSWITH(string, "ErrorColour", len)) { i = len;
221  } else if (STR_LITERAL_STARTSWITH(string, "BackgroundColour", len)) { i = len;
222  } else if (STR_LITERAL_STARTSWITH(string, "DropToEditor", len)) { i = len;
223  } else if (STR_LITERAL_STARTSWITH(string, "LastRenderName", len)) { i = len;
224  } else if (STR_LITERAL_STARTSWITH(string, "LastRenderPath", len)) { i = len;
225  } else if (STR_LITERAL_STARTSWITH(string, "LastQueuePath", len)) { i = len;
226  } else if (STR_LITERAL_STARTSWITH(string, "SecondaryINISection", len)) { i = len;
227  } else if (STR_LITERAL_STARTSWITH(string, "BetaVersionNo64", len)) { i = len;
228  } else if (STR_LITERAL_STARTSWITH(string, "LastBitmapName", len)) { i = len;
229  } else if (STR_LITERAL_STARTSWITH(string, "LastBitmapPath", len)) { i = len;
230  } else if (STR_LITERAL_STARTSWITH(string, "LastINIPath", len)) { i = len;
231  } else if (STR_LITERAL_STARTSWITH(string, "SecondaryINIFile", len)) { i = len;
232  } else if (STR_LITERAL_STARTSWITH(string, "BackgroundFile", len)) { i = len;
233  } else if (STR_LITERAL_STARTSWITH(string, "SaveSettingsOnExit", len)) { i = len;
234  } else if (STR_LITERAL_STARTSWITH(string, "TileBackground", len)) { i = len;
235  } else if (STR_LITERAL_STARTSWITH(string, "HideNewUserHelp", len)) { i = len;
236  } else if (STR_LITERAL_STARTSWITH(string, "SendSystemInfo", len)) { i = len;
237  } else if (STR_LITERAL_STARTSWITH(string, "ItsAboutTime", len)) { i = len;
238  } else if (STR_LITERAL_STARTSWITH(string, "LastPath", len)) { i = len;
239  } else if (STR_LITERAL_STARTSWITH(string, "Band0Width", len)) { i = len;
240  } else if (STR_LITERAL_STARTSWITH(string, "Band1Width", len)) { i = len;
241  } else if (STR_LITERAL_STARTSWITH(string, "Band2Width", len)) { i = len;
242  } else if (STR_LITERAL_STARTSWITH(string, "Band3Width", len)) { i = len;
243  } else if (STR_LITERAL_STARTSWITH(string, "Band4Width", len)) { i = len;
244  } else if (STR_LITERAL_STARTSWITH(string, "ShowCmd", len)) { i = len;
245  } else if (STR_LITERAL_STARTSWITH(string, "Transparency", len)) { i = len;
246  } else if (STR_LITERAL_STARTSWITH(string, "Use8BitMode", len)) { i = len;
247  } else if (STR_LITERAL_STARTSWITH(string, "MakeActive", len)) { i = len;
248  } else if (STR_LITERAL_STARTSWITH(string, "KeepAboveMain", len)) { i = len;
249  } else if (STR_LITERAL_STARTSWITH(string, "AutoClose", len)) { i = len;
250  } else if (STR_LITERAL_STARTSWITH(string, "PreserveBitmap", len)) { i = len;
251  } else if (STR_LITERAL_STARTSWITH(string, "FontSize", len)) { i = len;
252  } else if (STR_LITERAL_STARTSWITH(string, "FontWeight", len)) { i = len;
253  } else if (STR_LITERAL_STARTSWITH(string, "KeepMessages", len)) { i = len;
254  } else if (STR_LITERAL_STARTSWITH(string, "AlertSound", len)) { i = len;
255  } else if (STR_LITERAL_STARTSWITH(string, "Completion", len)) { i = len;
256  } else if (STR_LITERAL_STARTSWITH(string, "Priority", len)) { i = len;
257  } else if (STR_LITERAL_STARTSWITH(string, "DutyCycle", len)) { i = len;
258  } else if (STR_LITERAL_STARTSWITH(string, "AlertOnCompletion", len)) { i = len;
259  } else if (STR_LITERAL_STARTSWITH(string, "AutoRender", len)) { i = len;
260  } else if (STR_LITERAL_STARTSWITH(string, "PreventSleep", len)) { i = len;
261  } else if (STR_LITERAL_STARTSWITH(string, "NoShelloutWait", len)) { i = len;
262  } else if (STR_LITERAL_STARTSWITH(string, "SystemNoActive", len)) { i = len;
263  } else if (STR_LITERAL_STARTSWITH(string, "NoShellOuts", len)) { i = len;
264  } else if (STR_LITERAL_STARTSWITH(string, "VideoSource", len)) { i = len;
265  } else if (STR_LITERAL_STARTSWITH(string, "SceneFile", len)) { i = len;
266  } else if (STR_LITERAL_STARTSWITH(string, "OutputFile", len)) { i = len;
267  } else if (STR_LITERAL_STARTSWITH(string, "IniOutputFile", len)) { i = len;
268  } else if (STR_LITERAL_STARTSWITH(string, "CurrentDirectory", len)) { i = len;
269  } else if (STR_LITERAL_STARTSWITH(string, "SourceFile", len)) { i = len;
270  } else if (STR_LITERAL_STARTSWITH(string, "Rendering", len)) { i = len;
271  } else if (STR_LITERAL_STARTSWITH(string, "RenderwinClose", len)) { i = len;
272  } else if (STR_LITERAL_STARTSWITH(string, "Append_File", len)) { i = len;
273  } else if (STR_LITERAL_STARTSWITH(string, "Warning Level", len)) { i = len;
274  } else if (STR_LITERAL_STARTSWITH(string, "clock_delta", len)) { i = len;
275  } else if (STR_LITERAL_STARTSWITH(string, "clock_on", len)) { i = len;
276  } else if (STR_LITERAL_STARTSWITH(string, "clock", len)) { i = len;
277  } else if (STR_LITERAL_STARTSWITH(string, "Height", len)) { i = len;
278  } else if (STR_LITERAL_STARTSWITH(string, "Width", len)) { i = len;
279  } else if (STR_LITERAL_STARTSWITH(string, "Dither", len)) { i = len;
280  } else if (STR_LITERAL_STARTSWITH(string, "Flags", len)) { i = len;
281  } else if (STR_LITERAL_STARTSWITH(string, "Font", len)) { i = len;
282  /* Filetypes */
283  } else if (STR_LITERAL_STARTSWITH(string, "df3", len)) { i = len;
284  } else if (STR_LITERAL_STARTSWITH(string, "exr", len)) { i = len;
285  } else if (STR_LITERAL_STARTSWITH(string, "gif", len)) { i = len;
286  } else if (STR_LITERAL_STARTSWITH(string, "hdr", len)) { i = len;
287  } else if (STR_LITERAL_STARTSWITH(string, "iff", len)) { i = len;
288  } else if (STR_LITERAL_STARTSWITH(string, "jpeg", len)) { i = len;
289  } else if (STR_LITERAL_STARTSWITH(string, "pgm", len)) { i = len;
290  } else if (STR_LITERAL_STARTSWITH(string, "png", len)) { i = len;
291  } else if (STR_LITERAL_STARTSWITH(string, "ppm", len)) { i = len;
292  } else if (STR_LITERAL_STARTSWITH(string, "sys", len)) { i = len;
293  } else if (STR_LITERAL_STARTSWITH(string, "tga", len)) { i = len;
294  } else if (STR_LITERAL_STARTSWITH(string, "tiff", len)) { i = len;
295  /* Encodings */
296  } else if (STR_LITERAL_STARTSWITH(string, "ascii", len)) { i = len;
297  } else if (STR_LITERAL_STARTSWITH(string, "utf8", len)) { i = len;
298  } else if (STR_LITERAL_STARTSWITH(string, "uint8", len)) { i = len;
299  } else if (STR_LITERAL_STARTSWITH(string, "uint16be", len)) { i = len;
300  } else if (STR_LITERAL_STARTSWITH(string, "uint16le", len)) { i = len;
301  } else if (STR_LITERAL_STARTSWITH(string, "sint8", len)) { i = len;
302  } else if (STR_LITERAL_STARTSWITH(string, "sint16be", len)) { i = len;
303  } else if (STR_LITERAL_STARTSWITH(string, "sint16le", len)) { i = len;
304  } else if (STR_LITERAL_STARTSWITH(string, "sint32be", len)) { i = len;
305  } else if (STR_LITERAL_STARTSWITH(string, "sint32le", len)) { i = len;
306 
307  } else { i = 0;
308  }
309 
310  /* clang-format on */
311 
312  /* If next source char is an identifier (eg. 'i' in "definite") no match */
313  return (i == 0 || text_check_identifier(string[i])) ? -1 : i;
314 }
315 
316 static int txtfmt_ini_find_bool(const char *string)
317 {
318  int i, len;
319 
320  /* Keep aligned args for readability. */
321  /* clang-format off */
322 
323  /* Built-in Constants */
324  if (STR_LITERAL_STARTSWITH(string, "false", len)) { i = len;
325  } else if (STR_LITERAL_STARTSWITH(string, "no", len)) { i = len;
326  } else if (STR_LITERAL_STARTSWITH(string, "off", len)) { i = len;
327  } else if (STR_LITERAL_STARTSWITH(string, "true", len)) { i = len;
328  } else if (STR_LITERAL_STARTSWITH(string, "yes", len)) { i = len;
329  } else if (STR_LITERAL_STARTSWITH(string, "on", len)) { i = len;
330  } else if (STR_LITERAL_STARTSWITH(string, "pi", len)) { i = len;
331  } else if (STR_LITERAL_STARTSWITH(string, "tau", len)) { i = len;
332  } else if (STR_LITERAL_STARTSWITH(string, "%o", len)) { i = len;
333  } else if (STR_LITERAL_STARTSWITH(string, "%s", len)) { i = len;
334  } else if (STR_LITERAL_STARTSWITH(string, "%n", len)) { i = len;
335  } else if (STR_LITERAL_STARTSWITH(string, "%k", len)) { i = len;
336  } else if (STR_LITERAL_STARTSWITH(string, "%h", len)) { i = len;
337  } else if (STR_LITERAL_STARTSWITH(string, "%w", len)) { i = len;
338  } else { i = 0;
339  }
340 
341  /* clang-format on */
342 
343  /* If next source char is an identifier (eg. 'i' in "Nonetheless") no match */
344  return (i == 0 || text_check_identifier(string[i])) ? -1 : i;
345 }
346 
347 static char txtfmt_pov_ini_format_identifier(const char *str)
348 {
349  char fmt;
350  if ((txtfmt_ini_find_keyword(str)) != -1) {
351  fmt = FMT_TYPE_KEYWORD;
352  }
353  else if ((txtfmt_ini_find_reserved(str)) != -1) {
354  fmt = FMT_TYPE_RESERVED;
355  }
356  else {
357  fmt = FMT_TYPE_DEFAULT;
358  }
359  return fmt;
360 }
361 
362 static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool do_next)
363 {
364  FlattenString fs;
365  const char *str;
366  char *fmt;
367  char cont_orig, cont, find, prev = ' ';
368  int len, i;
369 
370  /* Get continuation from previous line */
371  if (line->prev && line->prev->format != NULL) {
372  fmt = line->prev->format;
373  cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
374  BLI_assert((FMT_CONT_ALL & cont) == cont);
375  }
376  else {
377  cont = FMT_CONT_NOP;
378  }
379 
380  /* Get original continuation from this line */
381  if (line->format != NULL) {
382  fmt = line->format;
383  cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
384  BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
385  }
386  else {
387  cont_orig = 0xFF;
388  }
389 
390  len = flatten_string(st, &fs, line->line);
391  str = fs.buf;
392  if (!text_check_format_len(line, len)) {
393  flatten_string_free(&fs);
394  return;
395  }
396  fmt = line->format;
397 
398  while (*str) {
399  /* Handle escape sequences by skipping both \ and next char */
400  if (*str == '\\') {
401  *fmt = prev;
402  fmt++;
403  str++;
404  if (*str == '\0') {
405  break;
406  }
407  *fmt = prev;
408  fmt++;
410  continue;
411  }
412  /* Handle continuations */
413  if (cont) {
414  /* Multi-line comments */
415  if (cont & FMT_CONT_COMMENT_C) {
416  if (*str == ']' && *(str + 1) == ']') {
417  *fmt = FMT_TYPE_COMMENT;
418  fmt++;
419  str++;
420  *fmt = FMT_TYPE_COMMENT;
421  cont = FMT_CONT_NOP;
422  }
423  else {
424  *fmt = FMT_TYPE_COMMENT;
425  }
426  /* Handle other comments */
427  }
428  else {
429  find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\'';
430  if (*str == find) {
431  cont = 0;
432  }
433  *fmt = FMT_TYPE_STRING;
434  }
435 
437  }
438  /* Not in a string... */
439  else {
440  /* Multi-line comments not supported */
441  /* Single line comment */
442  if (*str == ';') {
443  text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
444  }
445  else if (ELEM(*str, '"', '\'')) {
446  /* Strings */
447  find = *str;
448  cont = (*str == '"') ? FMT_CONT_QUOTEDOUBLE : FMT_CONT_QUOTESINGLE;
449  *fmt = FMT_TYPE_STRING;
450  }
451  /* Whitespace (all ws. has been converted to spaces) */
452  else if (*str == ' ') {
453  *fmt = FMT_TYPE_WHITESPACE;
454  }
455  /* Numbers (digits not part of an identifier and periods followed by digits) */
456  else if ((prev != FMT_TYPE_DEFAULT && text_check_digit(*str)) ||
457  (*str == '.' && text_check_digit(*(str + 1)))) {
458  *fmt = FMT_TYPE_NUMERAL;
459  }
460  /* Booleans */
461  else if (prev != FMT_TYPE_DEFAULT && (i = txtfmt_ini_find_bool(str)) != -1) {
462  if (i > 0) {
464  }
465  else {
467  *fmt = FMT_TYPE_DEFAULT;
468  }
469  }
470  /* Punctuation */
471  else if ((*str != '#') && text_check_delim(*str)) {
472  *fmt = FMT_TYPE_SYMBOL;
473  }
474  /* Identifiers and other text (no previous ws. or delims. so text continues) */
475  else if (prev == FMT_TYPE_DEFAULT) {
477  *fmt = FMT_TYPE_DEFAULT;
478  }
479  /* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
480  else {
481  /* Keep aligned args for readability. */
482  /* clang-format off */
483 
484  /* Special vars(v) or built-in keywords(b) */
485  /* keep in sync with 'txtfmt_ini_format_identifier()' */
486  if ((i = txtfmt_ini_find_keyword(str)) != -1) { prev = FMT_TYPE_KEYWORD;
487  } else if ((i = txtfmt_ini_find_reserved(str)) != -1) { prev = FMT_TYPE_RESERVED;
488 }
489 
490  /* clang-format on */
491 
492  if (i > 0) {
493  text_format_fill_ascii(&str, &fmt, prev, i);
494  }
495  else {
497  *fmt = FMT_TYPE_DEFAULT;
498  }
499  }
500  }
501  prev = *fmt;
502  fmt++;
503  str++;
504  }
505 
506  /* Terminate and add continuation char */
507  *fmt = '\0';
508  fmt++;
509  *fmt = cont;
510 
511  /* If continuation has changed and we're allowed, process the next line */
512  if (cont != cont_orig && do_next && line->next) {
513  txtfmt_pov_ini_format_line(st, line->next, do_next);
514  }
515 
516  flatten_string_free(&fs);
517 }
518 
520 {
521  static TextFormatType tft = {NULL};
522  static const char *ext[] = {"ini", NULL};
523 
526  tft.ext = ext;
527 
529 }
bool text_check_identifier(const char ch)
Definition: text.c:2426
bool text_check_digit(const char ch)
Definition: text.c:2415
bool text_check_delim(const char ch)
Definition: text.c:2402
#define BLI_assert(a)
Definition: BLI_assert.h:58
int BLI_str_utf8_size_safe(const char *p) ATTR_NONNULL()
Definition: string_utf8.c:508
#define ELEM(...)
#define str(s)
void(* format_line)(SpaceText *st, TextLine *line, const bool do_next)
Definition: text_format.h:72
char(* format_identifier)(const char *string)
Definition: text_format.h:61
const char ** ext
Definition: text_format.h:74
char * format
char * line
struct TextLine * prev
struct TextLine * next
int flatten_string(const SpaceText *st, FlattenString *fs, const char *in)
Definition: text_format.c:71
void text_format_fill(const char **str_p, char **fmt_p, const char type, const int len)
Definition: text_format.c:151
void flatten_string_free(FlattenString *fs)
Definition: text_format.c:104
void text_format_fill_ascii(const char **str_p, char **fmt_p, const char type, const int len)
Definition: text_format.c:177
void ED_text_format_register(TextFormatType *tft)
Definition: text_format.c:195
int text_check_format_len(TextLine *line, uint len)
Definition: text_format.c:124
#define STR_LITERAL_STARTSWITH(str, str_literal, len_var)
Definition: text_format.h:110
@ FMT_TYPE_STRING
Definition: text_format.h:87
@ FMT_TYPE_COMMENT
Definition: text_format.h:81
@ FMT_TYPE_DEFAULT
Definition: text_format.h:97
@ FMT_TYPE_KEYWORD
Definition: text_format.h:95
@ FMT_TYPE_WHITESPACE
Definition: text_format.h:79
@ FMT_TYPE_NUMERAL
Definition: text_format.h:85
@ FMT_TYPE_RESERVED
Definition: text_format.h:93
@ FMT_TYPE_SYMBOL
Definition: text_format.h:83
@ FMT_CONT_QUOTEDOUBLE
Definition: text_format.h:40
@ FMT_CONT_QUOTESINGLE
Definition: text_format.h:39
@ FMT_CONT_NOP
Definition: text_format.h:38
@ FMT_CONT_COMMENT_C
Definition: text_format.h:44
#define FMT_CONT_ALL
Definition: text_format.h:46
static int txtfmt_ini_find_reserved(const char *string)
static int txtfmt_ini_find_keyword(const char *string)
static int txtfmt_ini_find_bool(const char *string)
void ED_text_format_register_pov_ini(void)
static char txtfmt_pov_ini_format_identifier(const char *str)
static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool do_next)
uint len