cairo-script-private.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. /*
  2. * Copyright © 2008 Chris Wilson <chris@chris-wilson.co.uk>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it either under the terms of the GNU Lesser General Public
  6. * License version 2.1 as published by the Free Software Foundation
  7. * (the "LGPL") or, at your option, under the terms of the Mozilla
  8. * Public License Version 1.1 (the "MPL"). If you do not alter this
  9. * notice, a recipient may use your version of this file under either
  10. * the MPL or the LGPL.
  11. *
  12. * You should have received a copy of the LGPL along with this library
  13. * in the file COPYING-LGPL-2.1; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
  15. * You should have received a copy of the MPL along with this library
  16. * in the file COPYING-MPL-1.1
  17. *
  18. * The contents of this file are subject to the Mozilla Public License
  19. * Version 1.1 (the "License"); you may not use this file except in
  20. * compliance with the License. You may obtain a copy of the License at
  21. * http://www.mozilla.org/MPL/
  22. *
  23. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  24. * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  25. * the specific language governing rights and limitations.
  26. *
  27. * The Original Code is the cairo graphics library.
  28. *
  29. * The Initial Developer of the Original Code is Chris Wilson.
  30. *
  31. * Contributor(s):
  32. * Chris Wilson <chris@chris-wilson.co.uk>
  33. */
  34. #ifndef CAIRO_SCRIPT_PRIVATE_H
  35. #define CAIRO_SCRIPT_PRIVATE_H
  36. #ifdef HAVE_CONFIG_H
  37. #include "config.h"
  38. #endif
  39. #include "cairo-script-interpreter.h"
  40. #include <setjmp.h>
  41. #ifdef _MSC_VER
  42. #undef inline
  43. #define inline __inline
  44. #endif
  45. #ifndef FALSE
  46. #define FALSE 0
  47. #endif
  48. #ifndef TRUE
  49. #define TRUE (!FALSE)
  50. #endif
  51. #ifndef NULL
  52. #define NULL (void *) 0
  53. #endif
  54. #if HAVE_STDINT_H
  55. # include <stdint.h>
  56. #elif HAVE_INTTYPES_H
  57. # include <inttypes.h>
  58. #elif HAVE_SYS_INT_TYPES_H
  59. # include <sys/int_types.h>
  60. #elif defined(_MSC_VER)
  61. typedef __int8 int8_t;
  62. typedef unsigned __int8 uint8_t;
  63. typedef __int16 int16_t;
  64. typedef unsigned __int16 uint16_t;
  65. typedef __int32 int32_t;
  66. typedef unsigned __int32 uint32_t;
  67. typedef __int64 int64_t;
  68. typedef unsigned __int64 uint64_t;
  69. # ifndef HAVE_UINT64_T
  70. # define HAVE_UINT64_T 1
  71. # endif
  72. #else
  73. #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.)
  74. #endif
  75. #if HAVE_BYTESWAP_H
  76. # include <byteswap.h>
  77. #endif
  78. #ifndef bswap_16
  79. # define bswap_16(p) \
  80. (((((uint16_t)(p)) & 0x00ff) << 8) | \
  81. (((uint16_t)(p)) >> 8))
  82. #endif
  83. #ifndef bswap_32
  84. # define bswap_32(p) \
  85. (((((uint32_t)(p)) & 0x000000ff) << 24) | \
  86. ((((uint32_t)(p)) & 0x0000ff00) << 8) | \
  87. ((((uint32_t)(p)) & 0x00ff0000) >> 8) | \
  88. ((((uint32_t)(p))) >> 24))
  89. #endif
  90. #if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun)
  91. # define slim_hidden_proto(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) csi_private
  92. # define slim_hidden_proto_no_warn(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) csi_private_no_warn
  93. # define slim_hidden_def(name) slim_hidden_def1(name, slim_hidden_int_name(name))
  94. # define slim_hidden_int_name(name) INT_##name
  95. # define slim_hidden_proto1(name, internal) \
  96. extern __typeof (name) name \
  97. __asm__ (slim_hidden_asmname (internal))
  98. # define slim_hidden_def1(name, internal) \
  99. extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name)) \
  100. __attribute__((__alias__(slim_hidden_asmname(internal))))
  101. # define slim_hidden_ulp slim_hidden_ulp1(__USER_LABEL_PREFIX__)
  102. # define slim_hidden_ulp1(x) slim_hidden_ulp2(x)
  103. # define slim_hidden_ulp2(x) #x
  104. # define slim_hidden_asmname(name) slim_hidden_asmname1(name)
  105. # define slim_hidden_asmname1(name) slim_hidden_ulp #name
  106. #else
  107. # define slim_hidden_proto(name) int _csi_dummy_prototype(void)
  108. # define slim_hidden_proto_no_warn(name) int _csi_dummy_prototype(void)
  109. # define slim_hidden_def(name) int _csi_dummy_prototype(void)
  110. #endif
  111. #if __GNUC__ >= 3
  112. #define csi_pure __attribute__((pure))
  113. #define csi_const __attribute__((const))
  114. #else
  115. #define csi_pure
  116. #define csi_const
  117. #endif
  118. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  119. #define _CSI_BOOLEAN_EXPR(expr) \
  120. __extension__ ({ \
  121. int _csi_boolean_var_; \
  122. if (expr) \
  123. _csi_boolean_var_ = 1; \
  124. else \
  125. _csi_boolean_var_ = 0; \
  126. _csi_boolean_var_; \
  127. })
  128. #define _csi_likely(expr) (__builtin_expect (_CSI_BOOLEAN_EXPR(expr), 1))
  129. #define _csi_unlikely(expr) (__builtin_expect (_CSI_BOOLEAN_EXPR(expr), 0))
  130. #else
  131. #define _csi_likely(expr) (expr)
  132. #define _csi_unlikely(expr) (expr)
  133. #endif
  134. #ifdef __GNUC__
  135. #ifndef offsetof
  136. #define offsetof(type, member) \
  137. ((char *) &((type *) 0)->member - (char *) 0)
  138. #endif
  139. #define csi_container_of(ptr, type, member) ({ \
  140. const typeof(((type *) 0)->member) *mptr__ = (ptr); \
  141. (type *) ((char *) mptr__ - offsetof (type, member)); \
  142. })
  143. #else
  144. #define csi_container_of(ptr, type, member) \
  145. (type *)((char *) (ptr) - (char *) &((type *)0)->member)
  146. #endif
  147. /* slim_internal.h */
  148. #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
  149. #define csi_private_no_warn __attribute__((__visibility__("hidden")))
  150. #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
  151. #define csi_private_no_warn __hidden
  152. #else /* not gcc >= 3.3 and not Sun Studio >= 8 */
  153. #define csi_private_no_warn
  154. #endif
  155. #undef ARRAY_LENGTH
  156. #define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
  157. #ifndef WARN_UNUSED_RESULT
  158. #define WARN_UNUSED_RESULT
  159. #endif
  160. /* Add attribute(warn_unused_result) if supported */
  161. #define csi_warn WARN_UNUSED_RESULT
  162. #define csi_private csi_private_no_warn csi_warn
  163. #define CSI_BITSWAP8(c) ((((c) * 0x0802LU & 0x22110LU) | ((c) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16)
  164. #ifdef WORDS_BIGENDIAN
  165. #define CSI_BITSWAP8_IF_LITTLE_ENDIAN(c) (c)
  166. #else
  167. #define CSI_BITSWAP8_IF_LITTLE_ENDIAN(c) CSI_BITSWAP8(c)
  168. #endif
  169. typedef enum _csi_status {
  170. CSI_STATUS_SUCCESS = CAIRO_STATUS_SUCCESS,
  171. CSI_STATUS_NO_MEMORY = CAIRO_STATUS_NO_MEMORY,
  172. CSI_STATUS_INVALID_RESTORE = CAIRO_STATUS_INVALID_RESTORE,
  173. CSI_STATUS_INVALID_POP_GROUP = CAIRO_STATUS_INVALID_POP_GROUP,
  174. CSI_STATUS_NO_CURRENT_POINT = CAIRO_STATUS_NO_CURRENT_POINT,
  175. CSI_STATUS_INVALID_MATRIX = CAIRO_STATUS_INVALID_MATRIX,
  176. CSI_STATUS_INVALID_STATUS = CAIRO_STATUS_INVALID_STATUS,
  177. CSI_STATUS_NULL_POINTER = CAIRO_STATUS_NULL_POINTER,
  178. CSI_STATUS_INVALID_STRING = CAIRO_STATUS_INVALID_STRING,
  179. CSI_STATUS_INVALID_PATH_DATA = CAIRO_STATUS_INVALID_PATH_DATA,
  180. CSI_STATUS_READ_ERROR = CAIRO_STATUS_READ_ERROR,
  181. CSI_STATUS_WRITE_ERROR = CAIRO_STATUS_WRITE_ERROR,
  182. CSI_STATUS_SURFACE_FINISHED = CAIRO_STATUS_SURFACE_FINISHED,
  183. CSI_STATUS_SURFACE_TYPE_MISMATCH = CAIRO_STATUS_SURFACE_TYPE_MISMATCH,
  184. CSI_STATUS_PATTERN_TYPE_MISMATCH = CAIRO_STATUS_PATTERN_TYPE_MISMATCH,
  185. CSI_STATUS_INVALID_CONTENT = CAIRO_STATUS_INVALID_CONTENT,
  186. CSI_STATUS_INVALID_FORMAT = CAIRO_STATUS_INVALID_FORMAT,
  187. CSI_STATUS_INVALID_VISUAL = CAIRO_STATUS_INVALID_VISUAL,
  188. CSI_STATUS_FILE_NOT_FOUND = CAIRO_STATUS_FILE_NOT_FOUND,
  189. CSI_STATUS_INVALID_DASH = CAIRO_STATUS_INVALID_DASH,
  190. CSI_STATUS_INVALID_DSC_COMMENT = CAIRO_STATUS_INVALID_DSC_COMMENT,
  191. CSI_STATUS_INVALID_INDEX = CAIRO_STATUS_INVALID_INDEX,
  192. CSI_STATUS_CLIP_NOT_REPRESENTABLE = CAIRO_STATUS_CLIP_NOT_REPRESENTABLE,
  193. CSI_STATUS_TEMP_FILE_ERROR = CAIRO_STATUS_TEMP_FILE_ERROR,
  194. CSI_STATUS_INVALID_STRIDE = CAIRO_STATUS_INVALID_STRIDE,
  195. CSI_STATUS_FONT_TYPE_MISMATCH = CAIRO_STATUS_FONT_TYPE_MISMATCH,
  196. CSI_STATUS_USER_FONT_IMMUTABLE = CAIRO_STATUS_USER_FONT_IMMUTABLE,
  197. CSI_STATUS_USER_FONT_ERROR = CAIRO_STATUS_USER_FONT_ERROR,
  198. CSI_STATUS_NEGATIVE_COUNT = CAIRO_STATUS_NEGATIVE_COUNT,
  199. CSI_STATUS_INVALID_CLUSTERS = CAIRO_STATUS_INVALID_CLUSTERS,
  200. CSI_STATUS_INVALID_SLANT = CAIRO_STATUS_INVALID_SLANT,
  201. CSI_STATUS_INVALID_WEIGHT = CAIRO_STATUS_INVALID_WEIGHT,
  202. /* cairo-script-interpreter specific errors */
  203. CSI_STATUS_INVALID_SCRIPT,
  204. CSI_STATUS_SCRIPT_INVALID_TYPE,
  205. CSI_STATUS_SCRIPT_INVALID_INDEX,
  206. CSI_STATUS_SCRIPT_UNDEFINED_NAME,
  207. CSI_STATUS_INTERPRETER_FINISHED,
  208. _CSI_STATUS_SCRIPT_LAST_ERROR,
  209. CSI_INT_STATUS_UNSUPPORTED
  210. } csi_status_t;
  211. typedef enum {
  212. CSI_OBJECT_TYPE_NULL = 0,
  213. /* atomics */
  214. CSI_OBJECT_TYPE_BOOLEAN,
  215. CSI_OBJECT_TYPE_INTEGER,
  216. CSI_OBJECT_TYPE_MARK,
  217. CSI_OBJECT_TYPE_NAME,
  218. CSI_OBJECT_TYPE_OPERATOR,
  219. CSI_OBJECT_TYPE_REAL,
  220. /* compound */
  221. CSI_OBJECT_TYPE_ARRAY = 0x8,
  222. CSI_OBJECT_TYPE_DICTIONARY,
  223. CSI_OBJECT_TYPE_FILE,
  224. CSI_OBJECT_TYPE_MATRIX,
  225. CSI_OBJECT_TYPE_STRING,
  226. /* cairo */
  227. CSI_OBJECT_TYPE_CONTEXT = 0x10,
  228. CSI_OBJECT_TYPE_FONT,
  229. CSI_OBJECT_TYPE_PATTERN,
  230. CSI_OBJECT_TYPE_SCALED_FONT,
  231. CSI_OBJECT_TYPE_SURFACE
  232. } csi_object_type_t;
  233. #define CSI_OBJECT_IS_ATOM(OBJ) (((OBJ)->type & CSI_OBJECT_TYPE_MASK) < 0x08)
  234. #define CSI_OBJECT_IS_COMPOUND(OBJ) ((OBJ)->type & 0x08)
  235. #define CSI_OBJECT_IS_CAIRO(OBJ) ((OBJ)->type & 0x10)
  236. enum { /* attributes */
  237. CSI_OBJECT_ATTR_EXECUTABLE = 1 << 6,
  238. CSI_OBJECT_ATTR_WRITABLE = 1 << 7
  239. };
  240. #define CSI_OBJECT_ATTR_MASK (CSI_OBJECT_ATTR_EXECUTABLE | \
  241. CSI_OBJECT_ATTR_WRITABLE)
  242. #define CSI_OBJECT_TYPE_MASK (~CSI_OBJECT_ATTR_MASK)
  243. typedef struct _cairo_script_interpreter csi_t;
  244. typedef cairo_bool_t csi_boolean_t;
  245. typedef csi_status_t (*csi_operator_t) (csi_t *);
  246. typedef float csi_real_t;
  247. typedef long csi_integer_t;
  248. typedef long csi_name_t;
  249. typedef struct _csi_array csi_array_t;
  250. typedef struct _csi_buffer csi_buffer_t;
  251. typedef struct _csi_compound_object csi_compound_object_t;
  252. typedef struct _csi_dictionary csi_dictionary_t;
  253. typedef struct _csi_file csi_file_t;
  254. typedef struct _csi_hash_entry csi_hash_entry_t;
  255. typedef struct _csi_hash_table csi_hash_table_t;
  256. typedef struct _csi_hash_table_arrangement csi_hash_table_arrangement_t;
  257. typedef struct _csi_list csi_list_t;
  258. typedef struct _csi_matrix csi_matrix_t;
  259. typedef struct _csi_object csi_object_t;
  260. typedef struct _csi_scanner csi_scanner_t;
  261. typedef struct _csi_stack csi_stack_t;
  262. typedef struct _csi_string csi_string_t;
  263. typedef cairo_bool_t
  264. (*csi_hash_predicate_func_t) (void *entry);
  265. typedef void
  266. (*csi_hash_callback_func_t) (void *entry,
  267. void *closure);
  268. typedef cairo_bool_t
  269. (*csi_hash_keys_equal_func_t) (const void *key_a, const void *key_b);
  270. struct _csi_object {
  271. csi_object_type_t type;
  272. union {
  273. cairo_t *cr;
  274. cairo_font_face_t *font_face;
  275. cairo_pattern_t *pattern;
  276. cairo_scaled_font_t *scaled_font;
  277. cairo_surface_t *surface;
  278. csi_array_t *array;
  279. csi_boolean_t boolean;
  280. csi_compound_object_t *object;
  281. csi_dictionary_t *dictionary;
  282. csi_file_t *file;
  283. csi_integer_t integer;
  284. csi_matrix_t *matrix;
  285. csi_operator_t op;
  286. csi_name_t name;
  287. csi_real_t real;
  288. csi_string_t *string;
  289. void *ptr;
  290. } datum;
  291. };
  292. struct _csi_compound_object {
  293. csi_object_type_t type;
  294. unsigned int ref;
  295. };
  296. struct _csi_hash_entry {
  297. unsigned long hash;
  298. };
  299. struct _csi_hash_table_arrangement {
  300. unsigned long high_water_mark;
  301. unsigned long size;
  302. unsigned long rehash;
  303. };
  304. struct _csi_hash_table {
  305. csi_hash_keys_equal_func_t keys_equal;
  306. const csi_hash_table_arrangement_t *arrangement;
  307. csi_hash_entry_t **entries;
  308. unsigned long live_entries;
  309. unsigned long used_entries;
  310. unsigned long iterating; /* Iterating, no insert, no resize */
  311. };
  312. /* simple, embedded doubly-linked links */
  313. struct _csi_list {
  314. struct _csi_list *next, *prev;
  315. };
  316. struct _csi_buffer {
  317. char *base, *ptr, *end;
  318. unsigned int size;
  319. };
  320. struct _csi_stack {
  321. csi_object_t *objects;
  322. csi_integer_t len;
  323. csi_integer_t size;
  324. };
  325. struct _csi_array {
  326. csi_compound_object_t base;
  327. csi_stack_t stack;
  328. };
  329. typedef struct _csi_dictionary_entry {
  330. csi_hash_entry_t hash_entry;
  331. csi_object_t value;
  332. } csi_dictionary_entry_t;
  333. struct _csi_dictionary {
  334. csi_compound_object_t base;
  335. csi_hash_table_t hash_table;
  336. };
  337. struct _csi_matrix {
  338. csi_compound_object_t base;
  339. cairo_matrix_t matrix;
  340. };
  341. struct _csi_string {
  342. csi_compound_object_t base;
  343. csi_integer_t len;
  344. csi_integer_t deflate;
  345. enum {
  346. NONE,
  347. ZLIB,
  348. LZO,
  349. } method;
  350. char *string;
  351. };
  352. typedef struct _csi_filter_funcs {
  353. int (*filter_getc) (csi_file_t *);
  354. void (*filter_putc) (csi_file_t *, int);
  355. int (*filter_read) (csi_file_t *, uint8_t *, int);
  356. void (*filter_destroy) (csi_t *, void *);
  357. } csi_filter_funcs_t;
  358. struct _csi_file {
  359. csi_compound_object_t base;
  360. enum {
  361. STDIO,
  362. BYTES,
  363. PROCEDURE,
  364. FILTER
  365. } type;
  366. unsigned int flags;
  367. void *src;
  368. void *data;
  369. uint8_t *bp;
  370. int rem;
  371. const csi_filter_funcs_t *filter;
  372. };
  373. union _csi_union_object {
  374. void *ptr[2];
  375. csi_stack_t stack;
  376. csi_array_t arry;
  377. csi_dictionary_t dictionary;
  378. csi_matrix_t matrix;
  379. csi_string_t string;
  380. csi_file_t file;
  381. csi_object_t object;
  382. };
  383. struct _csi_scanner {
  384. jmp_buf jump_buffer;
  385. int depth;
  386. int bind;
  387. csi_status_t (*push) (csi_t *ctx, csi_object_t *obj);
  388. csi_status_t (*execute) (csi_t *ctx, csi_object_t *obj);
  389. void *closure;
  390. csi_buffer_t buffer;
  391. csi_stack_t procedure_stack;
  392. csi_object_t build_procedure;
  393. unsigned int accumulator;
  394. unsigned int accumulator_count;
  395. unsigned int line_number;
  396. };
  397. typedef cairo_script_interpreter_hooks_t csi_hooks_t;
  398. typedef struct _csi_chunk {
  399. struct _csi_chunk *next;
  400. int rem;
  401. char *ptr;
  402. } csi_chunk_t;
  403. struct _cairo_script_interpreter {
  404. int ref_count;
  405. csi_status_t status;
  406. unsigned int finished : 1;
  407. csi_hooks_t hooks;
  408. csi_hash_table_t strings;
  409. csi_stack_t ostack;
  410. csi_stack_t dstack;
  411. csi_scanner_t scanner;
  412. csi_chunk_t *perm_chunk;
  413. struct {
  414. csi_chunk_t *chunk;
  415. void *free_list;
  416. } slabs[16];
  417. csi_array_t *free_array;
  418. csi_dictionary_t *free_dictionary;
  419. csi_string_t *free_string;
  420. csi_operator_t opcode[256];
  421. /* caches of live data */
  422. csi_list_t *_images;
  423. csi_list_t *_faces;
  424. };
  425. typedef struct _csi_operator_def {
  426. const char *name;
  427. csi_operator_t op;
  428. } csi_operator_def_t;
  429. typedef struct _csi_integer_constant_def {
  430. const char *name;
  431. csi_integer_t value;
  432. } csi_integer_constant_def_t;
  433. typedef struct _csi_real_constant_def {
  434. const char *name;
  435. csi_real_t value;
  436. } csi_real_constant_def_t;
  437. /* cairo-script-file.c */
  438. csi_private csi_status_t
  439. csi_file_new (csi_t *ctx,
  440. csi_object_t *obj,
  441. const char *path, const char *mode);
  442. csi_private csi_status_t
  443. csi_file_new_for_stream (csi_t *ctx,
  444. csi_object_t *obj,
  445. FILE *stream);
  446. csi_private csi_status_t
  447. csi_file_new_for_bytes (csi_t *ctx,
  448. csi_object_t *obj,
  449. const char *bytes,
  450. unsigned int length);
  451. csi_private csi_status_t
  452. csi_file_new_from_string (csi_t *ctx,
  453. csi_object_t *obj,
  454. csi_string_t *src);
  455. csi_private csi_status_t
  456. csi_file_new_ascii85_decode (csi_t *ctx,
  457. csi_object_t *obj,
  458. csi_dictionary_t *dict,
  459. csi_object_t *src);
  460. csi_private csi_status_t
  461. csi_file_new_deflate_decode (csi_t *ctx,
  462. csi_object_t *obj,
  463. csi_dictionary_t *dict,
  464. csi_object_t *src);
  465. csi_private csi_status_t
  466. _csi_file_execute (csi_t *ctx, csi_file_t *obj);
  467. csi_private int
  468. csi_file_getc (csi_file_t *obj);
  469. csi_private int
  470. csi_file_read (csi_file_t *obj, void *buf, int len);
  471. csi_private void
  472. csi_file_putc (csi_file_t *obj, int c);
  473. csi_private void
  474. csi_file_flush (csi_file_t *obj);
  475. csi_private void
  476. csi_file_close (csi_t *ctx, csi_file_t *obj);
  477. csi_private void
  478. _csi_file_free (csi_t *ctx, csi_file_t *obj);
  479. csi_private csi_status_t
  480. _csi_file_as_string (csi_t *ctx,
  481. csi_file_t *file,
  482. csi_object_t *obj);
  483. /* cairo-script-hash.c */
  484. csi_private csi_status_t
  485. _csi_hash_table_init (csi_hash_table_t *hash_table,
  486. csi_hash_keys_equal_func_t keys_equal);
  487. csi_private void
  488. _csi_hash_table_fini (csi_hash_table_t *hash_table);
  489. csi_private void *
  490. _csi_hash_table_lookup (csi_hash_table_t *hash_table,
  491. csi_hash_entry_t *key);
  492. csi_private csi_status_t
  493. _csi_hash_table_insert (csi_hash_table_t *hash_table,
  494. csi_hash_entry_t *entry);
  495. csi_private void
  496. _csi_hash_table_remove (csi_hash_table_t *hash_table,
  497. csi_hash_entry_t *key);
  498. csi_private void
  499. _csi_hash_table_foreach (csi_hash_table_t *hash_table,
  500. csi_hash_callback_func_t hash_callback,
  501. void *closure);
  502. /* cairo-script-interpreter.c */
  503. csi_private void *
  504. _csi_alloc (csi_t *ctx, int size);
  505. csi_private void *
  506. _csi_alloc0 (csi_t *ctx, int size);
  507. csi_private void *
  508. _csi_realloc (csi_t *ctx, void *ptr, int size);
  509. csi_private void
  510. _csi_free (csi_t *ctx, void *ptr);
  511. csi_private void *
  512. _csi_slab_alloc (csi_t *ctx, int size);
  513. csi_private void *
  514. _csi_perm_alloc (csi_t *ctx, int size);
  515. csi_private void
  516. _csi_slab_free (csi_t *ctx, void *ptr, int size);
  517. csi_private csi_status_t
  518. csi_push_ostack (csi_t *ctx, csi_object_t *obj);
  519. csi_private csi_status_t
  520. _csi_name_define (csi_t *ctx, csi_name_t name, csi_object_t *obj);
  521. csi_private csi_status_t
  522. _csi_name_lookup (csi_t *ctx, csi_name_t name, csi_object_t *obj);
  523. csi_private csi_status_t
  524. _csi_name_undefine (csi_t *ctx, csi_name_t name);
  525. csi_private csi_status_t
  526. _csi_intern_string (csi_t *ctx, const char **str_inout, int len);
  527. csi_private csi_status_t
  528. _csi_error (csi_status_t status);
  529. /* cairo-script-objects.c */
  530. csi_private csi_status_t
  531. csi_array_new (csi_t *ctx,
  532. csi_integer_t initial_size,
  533. csi_object_t *obj);
  534. csi_private csi_status_t
  535. _csi_array_execute (csi_t *ctx, csi_array_t *array);
  536. csi_private csi_status_t
  537. csi_array_get (csi_t *ctx,
  538. csi_array_t *array,
  539. long elem,
  540. csi_object_t *value);
  541. csi_private csi_status_t
  542. csi_array_put (csi_t *ctx,
  543. csi_array_t *array,
  544. csi_integer_t elem,
  545. csi_object_t *value);
  546. csi_private csi_status_t
  547. csi_array_append (csi_t *ctx,
  548. csi_array_t *array,
  549. csi_object_t *obj);
  550. csi_private void
  551. csi_array_free (csi_t *ctx, csi_array_t *array);
  552. static inline void
  553. csi_boolean_new (csi_object_t *obj,
  554. csi_boolean_t v)
  555. {
  556. obj->type = CSI_OBJECT_TYPE_BOOLEAN;
  557. obj->datum.boolean = v;
  558. }
  559. csi_private csi_status_t
  560. csi_dictionary_new (csi_t *ctx,
  561. csi_object_t *obj);
  562. csi_private csi_status_t
  563. csi_dictionary_put (csi_t *ctx,
  564. csi_dictionary_t *dict,
  565. csi_name_t name,
  566. csi_object_t *value);
  567. csi_private csi_status_t
  568. csi_dictionary_get (csi_t *ctx,
  569. csi_dictionary_t *dict,
  570. csi_name_t name,
  571. csi_object_t *value);
  572. csi_private csi_boolean_t
  573. csi_dictionary_has (csi_dictionary_t *dict,
  574. csi_name_t name);
  575. csi_private void
  576. csi_dictionary_remove (csi_t *ctx,
  577. csi_dictionary_t *dict,
  578. csi_name_t name);
  579. csi_private void
  580. csi_dictionary_free (csi_t *ctx,
  581. csi_dictionary_t *dict);
  582. static inline void
  583. csi_integer_new (csi_object_t *obj,
  584. csi_integer_t v)
  585. {
  586. obj->type = CSI_OBJECT_TYPE_INTEGER;
  587. obj->datum.integer = v;
  588. }
  589. csi_private csi_status_t
  590. csi_matrix_new (csi_t *ctx,
  591. csi_object_t *obj);
  592. csi_private csi_status_t
  593. csi_matrix_new_from_array (csi_t *ctx,
  594. csi_object_t *obj,
  595. csi_array_t *array);
  596. csi_private csi_status_t
  597. csi_matrix_new_from_matrix (csi_t *ctx,
  598. csi_object_t *obj,
  599. const cairo_matrix_t *m);
  600. csi_private csi_status_t
  601. csi_matrix_new_from_values (csi_t *ctx,
  602. csi_object_t *obj,
  603. double v[6]);
  604. csi_private void
  605. csi_matrix_free (csi_t *ctx,
  606. csi_matrix_t *obj);
  607. csi_private csi_status_t
  608. csi_name_new (csi_t *ctx,
  609. csi_object_t *obj,
  610. const char *str,
  611. int len);
  612. csi_private csi_status_t
  613. csi_name_new_static (csi_t *ctx,
  614. csi_object_t *obj,
  615. const char *str);
  616. static inline void
  617. csi_operator_new (csi_object_t *obj,
  618. csi_operator_t op)
  619. {
  620. obj->type = CSI_OBJECT_TYPE_OPERATOR | CSI_OBJECT_ATTR_EXECUTABLE;
  621. obj->datum.op = op;
  622. }
  623. static inline void
  624. csi_real_new (csi_object_t *obj,
  625. csi_real_t v)
  626. {
  627. obj->type = CSI_OBJECT_TYPE_REAL;
  628. obj->datum.real = v;
  629. }
  630. csi_private csi_status_t
  631. csi_string_new (csi_t *ctx,
  632. csi_object_t *obj,
  633. const char *str,
  634. int len);
  635. csi_private csi_status_t
  636. csi_string_deflate_new (csi_t *ctx,
  637. csi_object_t *obj,
  638. void *bytes,
  639. int in_len,
  640. int out_len);
  641. csi_private csi_status_t
  642. csi_string_new_from_bytes (csi_t *ctx,
  643. csi_object_t *obj,
  644. char *bytes,
  645. unsigned int len);
  646. csi_private void
  647. csi_string_free (csi_t *ctx, csi_string_t *string);
  648. csi_private csi_status_t
  649. csi_object_execute (csi_t *ctx, csi_object_t *obj);
  650. csi_private csi_object_t *
  651. csi_object_reference (csi_object_t *obj);
  652. csi_private void
  653. csi_object_free (csi_t *ctx,
  654. csi_object_t *obj);
  655. csi_private csi_status_t
  656. csi_object_as_file (csi_t *ctx,
  657. csi_object_t *src,
  658. csi_object_t *file);
  659. csi_private csi_boolean_t
  660. csi_object_eq (csi_object_t *a,
  661. csi_object_t *b);
  662. csi_private csi_status_t
  663. csi_object_compare (csi_object_t *a,
  664. csi_object_t *b,
  665. int *out_cmp);
  666. /* cairo-script-operators.c */
  667. csi_private const csi_operator_def_t *
  668. _csi_operators (void);
  669. csi_private const csi_integer_constant_def_t *
  670. _csi_integer_constants (void);
  671. csi_private const csi_real_constant_def_t *
  672. _csi_real_constants (void);
  673. /* cairo-script-scanner.c */
  674. csi_private csi_status_t
  675. _csi_scanner_init (csi_t *ctx, csi_scanner_t *scanner);
  676. csi_private csi_status_t
  677. _csi_scan_file (csi_t *ctx, csi_file_t *src);
  678. csi_private csi_status_t
  679. _csi_translate_file (csi_t *ctx,
  680. csi_file_t *file,
  681. cairo_write_func_t write_func,
  682. void *closure);
  683. csi_private void
  684. _csi_scanner_fini (csi_t *ctx, csi_scanner_t *scanner);
  685. csi_private csi_boolean_t
  686. _csi_parse_number (csi_object_t *obj, const char *s, int len);
  687. /* cairo-script-stack.c */
  688. csi_private csi_status_t
  689. _csi_stack_init (csi_t *ctx, csi_stack_t *stack, csi_integer_t size);
  690. csi_private void
  691. _csi_stack_fini (csi_t *ctx, csi_stack_t *stack);
  692. csi_private csi_status_t
  693. _csi_stack_roll (csi_t *ctx,
  694. csi_stack_t *stack,
  695. csi_integer_t mod,
  696. csi_integer_t n);
  697. csi_private csi_status_t
  698. _csi_stack_grow (csi_t *ctx, csi_stack_t *stack, csi_integer_t cnt);
  699. csi_private csi_status_t
  700. _csi_stack_push_internal (csi_t *ctx, csi_stack_t *stack,
  701. const csi_object_t *obj);
  702. csi_private csi_object_t *
  703. _csi_stack_peek (csi_stack_t *stack, csi_integer_t i);
  704. csi_private void
  705. _csi_stack_pop (csi_t *ctx, csi_stack_t *stack, csi_integer_t count);
  706. csi_private csi_status_t
  707. _csi_stack_exch (csi_stack_t *stack);
  708. static inline csi_object_type_t
  709. csi_object_get_type (const csi_object_t *obj)
  710. {
  711. return obj->type & CSI_OBJECT_TYPE_MASK;
  712. }
  713. static inline csi_boolean_t
  714. csi_object_is_procedure (const csi_object_t *obj)
  715. {
  716. return obj->type == (CSI_OBJECT_TYPE_ARRAY | CSI_OBJECT_ATTR_EXECUTABLE);
  717. }
  718. static inline csi_boolean_t
  719. csi_object_is_number (const csi_object_t *obj)
  720. {
  721. int type = csi_object_get_type (obj);
  722. switch (type) {
  723. case CSI_OBJECT_TYPE_BOOLEAN:
  724. case CSI_OBJECT_TYPE_INTEGER:
  725. case CSI_OBJECT_TYPE_REAL:
  726. return 1;
  727. default:
  728. return 0;
  729. }
  730. }
  731. static inline double
  732. csi_number_get_value (const csi_object_t *obj)
  733. {
  734. int type = csi_object_get_type (obj);
  735. switch (type) {
  736. case CSI_OBJECT_TYPE_BOOLEAN: return obj->datum.boolean;
  737. case CSI_OBJECT_TYPE_INTEGER: return obj->datum.integer;
  738. case CSI_OBJECT_TYPE_REAL: return obj->datum.real;
  739. default: return 0.;
  740. }
  741. }
  742. csi_status_t
  743. _csi_stack_push (csi_t *ctx, csi_stack_t *stack,
  744. const csi_object_t *obj);
  745. static inline csi_boolean_t
  746. _csi_check_ostack (csi_t *ctx, csi_integer_t count)
  747. {
  748. return ctx->ostack.len >= count;
  749. }
  750. static inline csi_object_t *
  751. _csi_peek_ostack (csi_t *ctx, csi_integer_t i)
  752. {
  753. return &ctx->ostack.objects[ctx->ostack.len - i -1];
  754. }
  755. static inline void
  756. _csi_pop_ostack (csi_t *ctx, csi_integer_t count)
  757. {
  758. do
  759. csi_object_free (ctx, &ctx->ostack.objects[--ctx->ostack.len]);
  760. while (--count);
  761. }
  762. static inline csi_status_t
  763. _csi_push_ostack_copy (csi_t *ctx, csi_object_t *obj)
  764. {
  765. return _csi_stack_push (ctx, &ctx->ostack, csi_object_reference (obj));
  766. }
  767. static inline csi_status_t
  768. _csi_push_ostack (csi_t *ctx, csi_object_t *obj)
  769. {
  770. return _csi_stack_push (ctx, &ctx->ostack, obj);
  771. }
  772. static inline csi_status_t
  773. _csi_push_ostack_boolean (csi_t *ctx, csi_boolean_t v)
  774. {
  775. csi_object_t obj;
  776. obj.type = CSI_OBJECT_TYPE_BOOLEAN;
  777. obj.datum.boolean = v;
  778. return _csi_stack_push (ctx, &ctx->ostack, &obj);
  779. }
  780. static inline csi_status_t
  781. _csi_push_ostack_integer (csi_t *ctx, csi_integer_t v)
  782. {
  783. csi_object_t obj;
  784. obj.type = CSI_OBJECT_TYPE_INTEGER;
  785. obj.datum.integer = v;
  786. return _csi_stack_push (ctx, &ctx->ostack, &obj);
  787. }
  788. static inline csi_status_t
  789. _csi_push_ostack_mark (csi_t *ctx)
  790. {
  791. csi_object_t obj;
  792. obj.type = CSI_OBJECT_TYPE_MARK;
  793. return _csi_stack_push (ctx, &ctx->ostack, &obj);
  794. }
  795. static inline csi_status_t
  796. _csi_push_ostack_null (csi_t *ctx)
  797. {
  798. csi_object_t obj;
  799. obj.type = CSI_OBJECT_TYPE_NULL;
  800. return _csi_stack_push (ctx, &ctx->ostack, &obj);
  801. }
  802. static inline csi_status_t
  803. _csi_push_ostack_real (csi_t *ctx, csi_real_t v)
  804. {
  805. csi_object_t obj;
  806. obj.type = CSI_OBJECT_TYPE_REAL;
  807. obj.datum.real = v;
  808. return _csi_stack_push (ctx, &ctx->ostack, &obj);
  809. }
  810. slim_hidden_proto_no_warn (cairo_script_interpreter_destroy);
  811. slim_hidden_proto_no_warn (cairo_script_interpreter_reference);
  812. #endif /* CAIRO_SCRIPT_PRIVATE_H */