1 /* sswf.h V1.0 -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2009 */
2 #ifndef SSWF_H
3 #define SSWF_H
4
5 /*
6
7 Copyright (c) 2002-2009 Made to Order Software Corp.
8
9 Permission is hereby granted, free of charge, to any
10 person obtaining a copy of this software and
11 associated documentation files (the "Software"), to
12 deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify,
14 merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom
16 the Software is furnished to do so, subject to the
17 following conditions:
18
19 The above copyright notice and this permission notice
20 shall be included in all copies or substantial
21 portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
24 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
26 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
27 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
29 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
31 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 SOFTWARE.
33
34 */
35
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <stdarg.h>
41 #include <stddef.h>
42 #include <limits.h>
43 #include <ctype.h>
44 #include <math.h>
45 #include <errno.h>
46
47 #ifndef __MINGW32__
48 #ifndef _MSVC
49 #include <sys/time.h>
50 #include <sys/resource.h>
51 #endif
52 #endif
53
54
55 #include "sswf/libsswf-config.h"
56
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62
63
64 #ifndef M_PI
65 #define M_PI 3.14159265358979323846
66 #endif
67
68 extern int yylex(void);
69 extern FILE * yyin;
70 extern int yyparse(void *result);
71
72
73
74 #if DEBUG
75 extern void assert(int cond, const char *format, ...)
76 #ifdef __GNUC__
77 __attribute__ ((format (printf, 2, 3)))
78 #endif
79 ;
80 #else
81 #ifdef SSWF_NEED_ASSERT
assert(int cond,const char * format,...)82 static void assert(int cond, const char *format, ...) {}
83 #endif
84 #endif
85
86
87 #ifdef _MSVC
88 #ifndef strcasecmp
89 #define strcasecmp stricmp
90 #endif
91 #ifndef strncasecmp
92 #define strncasecmp strnicmp
93 #endif
94 #ifndef rint
95 #define rint(x) ((double) (long) floor(x + 0.5))
96 #endif
97 #ifndef snprintf
98 #define snprintf _snprintf
99 #endif
100 #endif
101
102
103
104 #define ADJUST_STRINGS 1
105
106
107
108 enum node_type_t {
109 NODE_TYPE_UNKNOWN = 0,
110 NODE_SUBTYPE_UNKNOWN,
111 NODE_TYPE_IDENTIFIER,
112 NODE_TYPE_INTEGER,
113 NODE_TYPE_FLOAT,
114 NODE_TYPE_RANGE_INTEGER,
115 NODE_TYPE_RANGE_FLOAT,
116 NODE_TYPE_STRING,
117 NODE_TYPE_DATA, /* an object data structure - uses object sub-types */
118 NODE_SUBTYPE_DEFINITION, /* to seperate multiple definitions within the same list */
119 NODE_TYPE_DEFINITION,
120 NODE_TYPE_OPERATOR,
121 NODE_SUBTYPE_ADD,
122 NODE_SUBTYPE_AND,
123 NODE_SUBTYPE_DIVIDE,
124 NODE_SUBTYPE_EQUAL,
125 NODE_SUBTYPE_EXPAND,
126 NODE_SUBTYPE_FIELD,
127 NODE_SUBTYPE_FUNCTION,
128 NODE_SUBTYPE_GREATER,
129 NODE_SUBTYPE_GREATER_EQUAL,
130 NODE_SUBTYPE_GROUP,
131 NODE_SUBTYPE_IDENTITY,
132 NODE_SUBTYPE_LESS,
133 NODE_SUBTYPE_LESS_EQUAL,
134 NODE_SUBTYPE_LET,
135 NODE_SUBTYPE_LOGICAL_AND,
136 NODE_SUBTYPE_LOGICAL_NOT,
137 NODE_SUBTYPE_LOGICAL_OR,
138 NODE_SUBTYPE_LOGICAL_XOR,
139 NODE_SUBTYPE_MAXIMUM,
140 NODE_SUBTYPE_MINIMUM,
141 NODE_SUBTYPE_MODULO,
142 NODE_SUBTYPE_MULTIPLY,
143 NODE_SUBTYPE_NEGATE,
144 NODE_SUBTYPE_NOT,
145 NODE_SUBTYPE_NOT_EQUAL,
146 NODE_SUBTYPE_OR,
147 NODE_SUBTYPE_POWER,
148 NODE_SUBTYPE_RANGE,
149 NODE_SUBTYPE_ROTATE_LEFT,
150 NODE_SUBTYPE_ROTATE_RIGHT,
151 NODE_SUBTYPE_SELECT,
152 NODE_SUBTYPE_SHIFT_LEFT,
153 NODE_SUBTYPE_SHIFT_RIGHT,
154 NODE_SUBTYPE_SHIFT_RIGHT_UNSIGNED,
155 NODE_SUBTYPE_SUBSCRIPT,
156 NODE_SUBTYPE_SUBTRACT,
157 NODE_SUBTYPE_XOR,
158 NODE_TYPE_UNIT,
159 NODE_SUBTYPE_BC, /* byte 0 to 255 (color) */
160 NODE_SUBTYPE_CM, /* centimeter (size) */
161 NODE_SUBTYPE_DEG, /* degree 0 to 360 (angle) */
162 NODE_SUBTYPE_FC, /* float 0.0 to 1.0 (color) */
163 NODE_SUBTYPE_FPF, /* frames per field?! (speed) */
164 NODE_SUBTYPE_FPS, /* frame per seconds (speed) */
165 NODE_SUBTYPE_FRM, /* frame per minute (speed) */
166 NODE_SUBTYPE_GRAD, /* grade 0 to 400 (angle) */
167 NODE_SUBTYPE_IN, /* inch (size) */
168 NODE_SUBTYPE_MIN, /* minute (time) */
169 NODE_SUBTYPE_PR, /* percent 0 to 100 (ratio) */
170 NODE_SUBTYPE_PX, /* pixels (size) */
171 NODE_SUBTYPE_RAD, /* radian (angle) */
172 NODE_SUBTYPE_RT, /* scale 0.0 to 1.0 (ratio) */
173 NODE_SUBTYPE_SEC, /* second (time) */
174 NODE_SUBTYPE_TW, /* twips (size) */
175 NODE_SUBTYPE_OTHER, /* boolean, version #, etc. */
176 NODE_TYPE_OBJECT,
177 NODE_SUBTYPE_ACTION,
178 NODE_SUBTYPE_ACTION_SCRIPT,
179 NODE_SUBTYPE_BLOCK,
180 NODE_SUBTYPE_BUTTON,
181 NODE_SUBTYPE_CATCH,
182 NODE_SUBTYPE_COLOR,
183 NODE_SUBTYPE_COLOR_TRANSFORM,
184 NODE_SUBTYPE_DO_ACTION,
185 NODE_SUBTYPE_EDGES,
186 NODE_SUBTYPE_EDIT_TEXT,
187 NODE_SUBTYPE_END,
188 NODE_SUBTYPE_ENVELOPE,
189 NODE_SUBTYPE_EXPORT,
190 NODE_SUBTYPE_FILL_STYLE,
191 NODE_SUBTYPE_FINALLY,
192 NODE_SUBTYPE_FONT,
193 NODE_SUBTYPE_FOR,
194 NODE_SUBTYPE_FRAME_LABEL,
195 /* NODE_SUBTYPE_FUNCTION -- already defined in the operators, we can still reuse it for objects! */
196 NODE_SUBTYPE_GLYPH,
197 NODE_SUBTYPE_GRADIENT,
198 NODE_SUBTYPE_IF,
199 NODE_SUBTYPE_IMAGE,
200 NODE_SUBTYPE_IMPORT,
201 NODE_SUBTYPE_LABEL,
202 NODE_SUBTYPE_LINE_STYLE,
203 NODE_SUBTYPE_LIST,
204 NODE_SUBTYPE_MATRIX,
205 NODE_SUBTYPE_METADATA,
206 NODE_SUBTYPE_ON_EVENT,
207 NODE_SUBTYPE_PLACE_OBJECT,
208 NODE_SUBTYPE_POINTS,
209 NODE_SUBTYPE_RECT,
210 NODE_SUBTYPE_REFERENCE,
211 NODE_SUBTYPE_REMOVE,
212 NODE_SUBTYPE_REMOVE_ALL,
213 NODE_SUBTYPE_REPLACE_OBJECT,
214 NODE_SUBTYPE_SCENE_FRAME_DATA,
215 NODE_SUBTYPE_SCRIPT_LIMITS,
216 NODE_SUBTYPE_SEQUENCE,
217 NODE_SUBTYPE_SET_BACKGROUND_COLOR,
218 NODE_SUBTYPE_SET_TAB_INDEX,
219 NODE_SUBTYPE_SHAPE,
220 NODE_SUBTYPE_SHOW_FRAME,
221 NODE_SUBTYPE_SOUND,
222 NODE_SUBTYPE_SOUND_INFO,
223 NODE_SUBTYPE_SPRITE,
224 NODE_SUBTYPE_STATE,
225 NODE_SUBTYPE_TEXT,
226 NODE_SUBTYPE_TEXT_SETUP,
227 NODE_SUBTYPE_TRY,
228 NODE_SUBTYPE_VARIABLE,
229 NODE_SUBTYPE_WITH,
230
231 NODE_TYPE_max
232 };
233 struct node_type_names_t {
234 #if DEBUG
235 enum node_type_t type;
236 #endif
237 const char * name;
238 };
239 extern const struct node_type_names_t node_type_names[NODE_TYPE_max];
240
241
242
243 /* different types of units */
244 enum node_unit_t {
245 NODE_UNIT_UNKNOWN = -1,
246 NODE_UNIT_ANGLE = 0,
247 NODE_UNIT_BOOLEAN,
248 NODE_UNIT_COLOR,
249 NODE_UNIT_RATIO,
250 NODE_UNIT_SIZE,
251 NODE_UNIT_SPEED,
252 NODE_UNIT_TIME,
253
254 NODE_UNIT_MAX
255 };
256
257
258
259 /*
260 * The data structures are specific to each object
261 * some objects, like the LIST, SEQUENCE, etc. will
262 * keep information about each included object.
263 *
264 * A referenced object is not considered a child object
265 * and therefore it can't be referenced as the child of
266 * another object later.
267 */
268 #define SSWF_MEM_ALIGN_SIZE sizeof(double) /* must be a power of 2 -- minimum memory alignment for any structure */
269 #define SSWF_MEM_ALIGN(size) (((size) + SSWF_MEM_ALIGN_SIZE - 1) & (- (long) SSWF_MEM_ALIGN_SIZE))
270
271 /* VARIABLE SIZE */
272 #ifdef _MSVC
273 #pragma warning(disable: 4200)
274 #endif
275 struct data_common_t {
276 size_t length; /* total length of this data block (to ease duplication) */
277 enum node_type_t type; /* the object sub_type or NODE_TYPE_STRING */
278 const char * label; /* at times an object is named using the label {} instruction */
279 struct node_t * node; /* the node which generated this object */
280 long pad; /* unused at this time - ensures that the sizeof(data_common_t) is a multiple of 8 */
281 size_t name_len; /* length of the name rounded up to 8 bytes to be able to skip it at once */
282 char name[0]; /* variable size null terminated string representing the name of this object */
283 };
284 #ifdef _MSVC
285 #pragma warning(default: 4200)
286 #endif
287
288 /* to avoid typing all the cast each time... */
289 #define dc_color(d) ((struct data_color_t *) dc_data(d))
290 #define dc_color_transform(d) ((struct data_color_transform_t *) dc_data(d))
291 #define dc_common(d) ((struct data_common_t *) dc_data(d))
292 #define dc_data(d) ((char *) ((d) + 1) + (d)->name_len)
293 #define dc_edges(d) ((struct data_edges_t *) dc_data(d))
294 #define dc_gradient(d) ((struct data_gradient_t *) dc_data(d))
295 #define dc_image(d) ((struct data_image_t *) dc_data(d))
296 #define dc_item(l, i) ((struct data_common_t *) ((char *) (l) + labs((l)->offset[i])))
297 #define dc_item_color(l, i) ((struct data_color_t *) ((char *) (l) + labs((l)->offset[i])))
298 #define dc_item_edges(l, i) ((struct data_edges_t *) ((char *) (l) + labs((l)->offset[i])))
299 #define dc_item_points(l, i) ((struct data_points_t *) ((char *) (l) + labs((l)->offset[i])))
300 #define dc_line_style(d) ((struct data_line_style_t *) dc_data(d))
301 #define dc_list(d) ((struct data_list_t *) dc_data(d))
302 #define dc_matrix(d) ((struct data_matrix_t *) dc_data(d))
303 #define dc_place_object(d) ((struct data_place_object_t *) dc_data(d))
304 #define dc_points(d) ((struct data_points_t *) dc_data(d))
305 #define dc_rect(d) ((struct data_rect_t *) dc_data(d))
306 #define dc_remove(d) ((struct data_remove_t *) dc_data(d))
307 #define dc_move(d) ((struct data_move_t *) dc_data(d))
308 #define dc_script_limits(d) ((struct data_script_limits_t *) dc_data(d))
309 #define dc_show_frame(d) ((struct data_show_frame_t *) dc_data(d))
310 #define dc_set_tab_index(d) ((struct data_set_tab_index_t *) dc_data(d))
311 #define dc_text_setup(d) ((struct data_text_setup_t *) dc_data(d))
312
313
314
315 /* VARIABLE SIZE -- structure used for BLOCK, EDGES, FILL STYLE, GRADIENT, LIST, SEQUENCE, SHAPE, SPRITE */
316 #ifdef _MSVC
317 #pragma warning(disable: 4200)
318 #endif
319 struct data_list_t {
320 size_t count; /* number of items in this list */
321 long offset[0]; /* an array of offsets to access any object quickly (especially to search a named object) */
322 /* NOTE: the offset can be negative! */
323 /* char data[count][length]; -- an array of data entries each with a variable length */
324 };
325 #ifdef _MSVC
326 #pragma warning(default: 4200)
327 #endif
328
329 /*
330 * Shapes use the same structure as the LIST.
331 * The MOVE is defined with a MATRIX (only the tx and ty fields are used)
332 * The other objects are inserted as objects of their own type (as expected in other words!).
333 */
334
335
336
337
338
339 /* structure used for BUTTON, BUTTON2 */
340 struct data_button_flag_t { // button menu flag
341 double menu;
342 };
343
344 struct data_button_t { // button states
345 double state;
346 double layer;
347 };
348
349
350 /* structure used for COLOR, SET BACKGROUND COLOR */
351 struct data_color_t {
352 double red;
353 double green;
354 double blue;
355 double alpha;
356 };
357
358
359 /* structure used for COLOR TRANSFORM */
360 struct data_color_transform_t {
361 double add_red;
362 double add_green;
363 double add_blue;
364 double add_alpha;
365 double mult_red;
366 double mult_green;
367 double mult_blue;
368 double mult_alpha;
369 };
370
371 /* VARIABLE SIZE -- structure used for EDGES (can be repeated, starts with a data_list_t) */
372 struct data_edges_t {
373 long type; /* closure or not */
374 double delta_x1;
375 double delta_y1;
376 double delta_x2; /* if NAN, only (x, y) defined thus we have a LINE edge */
377 double delta_y2; /* if NAN, only (x, y) defined thus we have a LINE edge */
378 };
379
380 #define EDGE_TYPE_INTERMEDIATE 0
381 #define EDGE_TYPE_CLOSE 1 /* back to the starting point */
382 #define EDGE_TYPE_ROTATE 2
383
384
385
386 /* FIXED SIZE -- structure used for IMPORT */
387 struct data_import_t {
388 long type;
389 };
390
391 #define IMPORT_TYPE_NAME 0 /* name of the object to import */
392 #define IMPORT_TYPE_URL 1 /* URL of the source movie */
393 #define IMPORT_TYPE_FILENAME 2 /* name of the file including the exported items */
394
395
396 /* FIXED SIZE -- structure used for METADATA */
397 struct data_metadata_t {
398 long type;
399 };
400
401 #define METADATA_TYPE_FILENAME 0 /* name of the XML file containing the metadata */
402 #define METADATA_TYPE_METADATA 1 /* the XML metadata itself */
403 /* for auto-generated XML */
404 #define METADATA_TYPE_TITLE 2 /* title */
405 #define METADATA_TYPE_DESCRIPTION 3 /* description */
406 #define METADATA_TYPE_AUTHOR 4 /* author/creator/investor... */
407 #define METADATA_TYPE_PUBLISHER 5 /* publisher */
408 #define METADATA_TYPE_COPYRIGHT 6 /* copyright or license information */
409 #define METADATA_TYPE_URL 7 /* a URL in link with this animation */
410
411
412 /* VARIABLE SIZE -- structure used for POINTS (can be repeated, starts with a data_list_t) */
413 struct data_points_t {
414 long type; /* closure or not */
415 double x1;
416 double y1;
417 double x2; /* if NAN, only (x, y) defined thus we have a LINE edge */
418 double y2; /* if NAN, only (x, y) defined thus we have a LINE edge */
419 };
420
421 /* whether we are defining the FILL0 or FILL1 */
422 struct data_fill_style_t {
423 long select; /* 0 - fill0, 1 - fill1 */
424 };
425
426 /* VARIABLE SIZE -- structure used for GRADIENT (is repeated 2 to 15 times with a data_list_t) */
427 struct data_gradient_t {
428 long type; /* POSITION or FOCAL */
429 double position; /* 0.0 to 1.0 */
430 double to_pos; /* for morph only; NAN otherwise */
431 };
432
433 #define GRADIENT_TYPE_POSITION 1
434 #define GRADIENT_TYPE_FOCAL 2
435
436 /* the ascent, descent and leading height font definition */
437 struct data_font_t {
438 long type; /* LAYOUT */
439 double ascent;
440 double descent;
441 double leading_height;
442 double advance;
443 double space;
444 };
445
446 struct data_font_advance_t {
447 long type; /* ADVANCE (only) */
448 double x; /* advance of that many pixels to next char */
449 };
450
451 struct data_font_kerning_t {
452 long type; /* KERNING */
453 double x; /* specific kerning advance */
454 };
455
456 struct data_font_name_t {
457 long type; /* NAME/DISPLAY NAME/COPYRIGHT/TYPE/LANGUAGE -- used to distinguish different types */
458 };
459
460 #define FONT_TYPE_LAYOUT 0
461 #define FONT_TYPE_ADVANCE 1
462 #define FONT_TYPE_KERNING 2
463 #define FONT_TYPE_NAME 3
464 #define FONT_TYPE_TYPE 4
465 #define FONT_TYPE_LANGUAGE 5
466 #define FONT_TYPE_DISPLAY_NAME 6
467 #define FONT_TYPE_COPYRIGHT 7
468
469
470 /* VARIABLE SIZE -- structure used for IMAGE (followed by one string) */
471 enum image_format_t {
472 IMAGE_FORMAT_LOSSLESS = 0,
473 IMAGE_FORMAT_LOSSLESS_8,
474 IMAGE_FORMAT_LOSSLESS_16,
475 IMAGE_FORMAT_LOSSLESS_32,
476 IMAGE_FORMAT_JPEG
477 };
478 struct data_image_t {
479 /* enum image_format_t format; -- does not work in big endian 64bit */
480 long format; /* 0 - LOSSLESS, 1 - JPEG */
481 double quality; /* 0.0 to 1.0 */
482 };
483
484
485 /* structure used for STORE REGISTER */
486 struct data_register_t {
487 double reg;
488 };
489
490
491 /* structure used for SOUND */
492 struct data_sound_t {
493 long type;
494 double mono;
495 double set_8bits;
496 };
497
498 #define SOUND_TYPE_SETUP 0
499 #define SOUND_TYPE_FILENAME 1
500 #define SOUND_TYPE_FORMAT 2
501
502 /* structure used for SOUND INFO */
503 struct data_sound_info_t {
504 double stop;
505 double no_multiple;
506 double start;
507 double end;
508 double loop;
509 };
510
511 struct data_envelope_t {
512 double position;
513 double left;
514 double right;
515 };
516
517
518 /* structure used for SHOW FRAME */
519 struct data_show_frame_t {
520 double wait;
521 };
522
523 /* structure used for PUSH DATA actions */
524 enum push_data_t {
525 PUSHDATA_INTEGER = 20,
526 PUSHDATA_STRING,
527 PUSHDATA_DOUBLE,
528 PUSHDATA_FLOAT,
529 PUSHDATA_BOOLEAN,
530 PUSHDATA_LOOKUP,
531 PUSHDATA_REGISTER,
532 PUSHDATA_NULL,
533 PUSHDATA_UNDEFINED,
534 PUSHDATA_PROPERTY
535 };
536 struct data_push_data_t {
537 /* enum push_data_t type; -- does not work in big endian 64bit */
538 long type;
539 double value;
540 };
541
542 /* structure used for GOTO actions */
543 struct data_goto_play_t {
544 double play;
545 };
546
547 /* VARIABLE SIZE -- structure used for LINE STYLE */
548 struct data_line_style_t {
549 double width;
550 double to_width; /* for morph only; -1.0 otherwise */
551 double cap_start;
552 double cap_end;
553 double join;
554 double miter;
555 double hscale;
556 double vscale;
557 double pixel_hinting;
558 double no_close;
559 /* followed by one or two colors */
560 };
561
562
563
564 /* structure used for MATRIX */
565 struct data_matrix_t {
566 double sx; /* scale - 1.0 = default */
567 double sy;
568 double tx; /* translate - 0.0 = default */
569 double ty;
570 double skew0; /* skew - 0.0 = default; use only if angle + scale not defined */
571 double skew1;
572 double angle; /* rotate - 0.0 = default */
573 };
574
575 /* VARIABLE SIZE -- structure used for PLACE OBJECT (followed by color transform, matrix, name, etc.) */
576 enum {
577 PLACE_OBJECT_TYPE_VALUE = 0, /* default value */
578 PLACE_OBJECT_TYPE_NAME, /* default value */
579 PLACE_OBJECT_TYPE_BLEND_MODE /* blend mode name */
580 };
581 struct data_place_object_t {
582 long type; /* we now need to support multiple strings! */
583 double position; /* when used for a MorphShape object, NAN otherwise */
584 double depth; /* depth at which object is placed, if -1, last object depth + 1 */
585 double clip; /* depth + clip to which object clips */
586 double tab_index; /* the tab order for the object at this depth */
587 double bitmap_caching; /* whether to cache the bitmap */
588 };
589
590 /* structure used for ON EVENT */
591 struct data_on_event_t {
592 long type;
593 };
594
595 #define ON_EVENT_TYPE_EVENT 1
596 #define ON_EVENT_TYPE_KEY 2
597
598
599 /* structure used for RECT */
600 struct data_rect_t {
601 double min_x;
602 double min_y;
603 double max_x;
604 double max_y;
605 };
606
607 /* VARIABLE SIZE -- structure used for REMOVE, REMOVE ALL */
608 struct data_remove_t {
609 double depth; /* if -1, use name instead */
610 };
611 /* if depth == -1 && there isn't a name, then we have a REMOVE ALL */
612
613
614 /* the script limits */
615 struct data_script_limits_t {
616 double max_recursion_depth; /* if 0, use default */
617 double timeout_seconds; /* if 0, use default */
618 };
619
620 /* the set tab index */
621 struct data_set_tab_index_t {
622 double depth; /* the depth of an object */
623 double index; /* the tab order for that object */
624 };
625
626 /* structure used for the shape MOVE */
627 struct data_move_t {
628 long type; /* 3 */
629 double tx;
630 double ty;
631 };
632
633
634 /* structure used for the shape MORPH */
635 struct data_morph_t {
636 long type; /* 5 */
637 double mode; /* 0 - shape0, 1 - shape1, 2 - both shapes */
638 };
639
640
641 /* structure used for the shape SHOWBOUNDS */
642 struct data_shape_t {
643 long type; /* 2 - show bounds, 3 - show origin */
644 double show;
645 };
646
647 /* structure used for the advance between characters in a text object */
648 enum {
649 TEXT_TYPE_INFO = 0, /* default value */
650 TEXT_TYPE_ADVANCE
651 };
652 struct data_text_t {
653 long type;
654 double advance; /* defined when EDIT_TEXT_TYPE_ADVANCE */
655 double thickness;
656 double sharpness;
657 double renderer;
658 double grid_fit;
659 };
660
661 /* structure used for the edit text entries */
662 enum {
663 EDIT_TEXT_TYPE_LAYOUT = 0, /* default value */
664 EDIT_TEXT_TYPE_VARIABLE,
665 EDIT_TEXT_TYPE_ALIGNMENT,
666 EDIT_TEXT_TYPE_INITIAL_TEXT,
667 EDIT_TEXT_TYPE_USED_GLYPHS,
668 EDIT_TEXT_TYPE_USED_STRING,
669 EDIT_TEXT_TYPE_RENDERER,
670 EDIT_TEXT_TYPE_GRID_FIT
671 };
672 struct data_edit_text_t {
673 long type;
674 double margin_left;
675 double margin_right;
676 double indent;
677 double leading;
678 double max_length;
679 double word_wrap;
680 double multiline;
681 double password;
682 double readonly;
683 double no_select;
684 double border;
685 double outline;
686 double html;
687 double auto_size;
688 double thickness;
689 double sharpness;
690 double renderer;
691 double grid_fit;
692 };
693
694 /* structure used when the text setup is changed */
695 struct data_text_setup_t {
696 double x;
697 double y;
698 double height;
699 };
700
701
702 #define PIXEL_TO_TWIPS(x) ((long) ((x) * 20.0))
703 #define CLAMPED_BYTE_COLOR(c) ((unsigned char) ((c) >= 1.0 ? 255.0 : ((c) <= 0.0 ? 0.0 : rint((c) * 255.0))))
704
705
706
707
708
709 struct node_t {
710 enum node_type_t type;
711 enum node_type_t sub_type;
712 enum node_type_t unit[NODE_UNIT_MAX];
713 unsigned long flags;
714 struct node_t * head;
715 struct node_t * tail;
716 struct node_t * parent;
717 struct node_t * parent2;
718 struct node_t * next;
719 struct node_t * previous;
720 struct node_t * left;
721 struct node_t * right;
722 struct node_t * select;
723 struct node_t ** list; /* list of nodes such as objects or variables */
724 long cnt; /* valid number of pointers in list */
725 long max; /* max. number of pointers in list before to reallocate */
726 char * string; /* identifiers and strings */
727 struct data_common_t * data; /* a pointer to some object data (see the data_..._t structs) */
728 long integer;
729 long integer2; /* in case of a range */
730 double floating_point;
731 double floating_point2;
732 unsigned long line; /* line # when this node was created */
733 const char * filename; /* filename where the node was read */
734 #if DEBUG
735 unsigned long serial; /* used in the node_print() function so the same node isn't printed more than once */
736 #endif
737 };
738
739 #define NODE_FLAG_SOFTLINK 0x00000001 /* if set, then left, right, select and list can't be cleaned up */
740
741
742
743 struct node_exec_status_t {
744 struct node_exec_status_t * parent;
745 struct node_t * obj; /* the object being executed */
746 enum node_unit_t unit;
747 int ref;
748 };
749
750
751
752 struct global_t {
753 unsigned long f_flags;
754 unsigned long f_show_steps;
755 double f_frame_rate;
756 const char * f_output_filename;
757 const char * f_output_encoding;
758 int f_version;
759 int f_minimum_version;
760 int f_maximum_version;
761 };
762
763 #define GLOBAL_FLAG_PROTECT 0x00000001
764 #define GLOBAL_FLAG_COMPRESS 0x00000002
765 #define GLOBAL_FLAG_USE_NETWORK 0x00000004
766
767
768
769
770
771 #define node_link(n, l, where) ((n)->where = (l), node_link_parent(n, l))
772 #define node_link_left(n, l) node_link(n, l, left)
773 #define node_link_right(n, l) node_link(n, l, right)
774 #define node_link_select(n, l) node_link(n, l, select)
775
776
777 extern int errcnt;
778 extern int warning_off;
779 extern const char * lex_filename;
780 extern int show_input_filenames;
781 extern int show_input_search;
782 extern int show_bounds;
783 extern int show_origin;
784 #if DEBUG
785 extern int debug_memory;
786 #endif
787
788
789 extern struct node_t * node_alloc(enum node_type_t type, enum node_type_t sub_type, unsigned long line);
790 extern void node_clean(struct node_t *n, const char *spaces);
791 extern void node_done_object(void);
792 extern int node_eval(struct node_t *expr, struct node_t *result, struct node_exec_status_t *status);
793 extern int node_execute(struct node_t *expr, struct node_t *result, struct node_exec_status_t *status);
794 extern struct node_t * node_find_block(struct node_t *expr);
795 extern struct node_t * node_find_object(struct node_t *n, const char *name);
796 extern void node_free(struct node_t *n);
797 extern void node_free_list(struct node_t *n);
798 extern struct node_t * node_init(struct node_t *n, enum node_type_t type, enum node_type_t sub_type);
799 extern void node_link_list(struct node_t *list, struct node_t *item);
800 extern void node_link_object(struct node_t *object);
801 extern void node_link_parent(struct node_t *parent, struct node_t *child);
802 extern void node_link_tail(struct node_t *p, struct node_t *q);
803 extern char * node_path(struct node_t *n, int include_empty);
804 extern void node_print_data(const struct data_common_t *data);
805 extern struct node_t * node_search_list(struct node_t *obj, const char *name);
806 extern int node_setup_objects(void);
807
808
809
810 #if DEBUG
811 extern void node_print(struct node_t *n);
812
813 extern void * sswf_alloc(size_t size, const char *name);
814 extern void * sswf_realloc(void *p, size_t size, const char *name);
815 extern void sswf_info(void);
816 extern void sswf_info_serial(void);
817
818
819 #define sswf_malloc(size, name) sswf_alloc(size, name)
820 #define sswf_remalloc(p, size, name) sswf_realloc(p, size, name)
821
822 #else
823 /* #if !DEBUG */
824 extern void * sswf_alloc(size_t size);
825 extern void * sswf_realloc(void *p, size_t size);
826
827 #define sswf_malloc(size, name) sswf_alloc(size)
828 #define sswf_remalloc(p, size, name) sswf_realloc(p, size)
829 #define sswf_info()
830
831 #endif
832
833 extern void sswf_free(void *p);
834 extern void sswf_clean(void *p);
835 extern char * sswf_strcat(const char *a, const char *b);
836 extern char * sswf_strcat3(const char *a, const char *b, const char *c);
837 extern char * sswf_strchild(const char *a, const char *b);
838 extern char * sswf_strdup(const char *string);
839
840
841 extern void sswf_read_actionscript(int yes);
842 extern void sswf_add_include(const char *path);
843 extern void sswf_set_default_include(int def);
844 extern int sswf_open_script(const char *filename);
845 extern void sswf_close_script(void);
846
847 extern int strcmp_action(const char *name, const char *pattern);
848 extern int save_data(const struct data_common_t *data, struct global_t *g);
849 extern int parse(void);
850 extern void set_var(const char *name, const char *value);
851
852
853 #ifdef __cplusplus
854 }
855 #endif
856 #endif
857