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