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