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