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