iutil.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* Copyright (C) 1991, 1995, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: iutil.h,v 1.2 2000/09/19 19:00:46 lpd Exp $ */
  16. /* Interface to interpreter utilities */
  17. /* Requires imemory.h, ostack.h */
  18. #ifndef iutil_INCLUDED
  19. # define iutil_INCLUDED
  20. /* ------ Object utilities ------ */
  21. /* Copy refs from one place to another. */
  22. /* (If we are copying to the stack, we can just use memcpy.) */
  23. void refcpy_to_new(P4(ref * to, const ref * from, uint size,
  24. gs_dual_memory_t *dmem));
  25. int refcpy_to_old(P6(ref * aref, uint index, const ref * from, uint size,
  26. gs_dual_memory_t *dmem, client_name_t cname));
  27. /*
  28. * Fill an array with nulls.
  29. * For backward compatibility, we define the procedure with a new name.
  30. */
  31. void refset_null_new(P3(ref * to, uint size, uint new_mask));
  32. #define refset_null(to, size) refset_null_new(to, size, ialloc_new_mask)
  33. /* Compare two objects for equality. */
  34. bool obj_eq(P2(const ref *, const ref *));
  35. /* Compare two objects for identity. */
  36. /* (This is not a standard PostScript concept.) */
  37. bool obj_ident_eq(P2(const ref *, const ref *));
  38. /*
  39. * Set *pchars and *plen to point to the data of a name or string, and
  40. * return 0. If the object isn't a name or string, return e_typecheck.
  41. * If the object is a string without read access, return e_invalidaccess.
  42. */
  43. int obj_string_data(P3(const ref *op, const byte **pchars, uint *plen));
  44. /*
  45. * Create a printable representation of an object, a la cvs and =
  46. * (full_print = 0), == (full_print = 1), or === (full_print = 2). Return 0
  47. * if OK, 1 if the destination wasn't large enough, e_invalidaccess if the
  48. * object's contents weren't readable. If the return value is 0 or 1,
  49. * *prlen contains the amount of data returned. start_pos is the starting
  50. * output position -- the first start_pos bytes of output are discarded.
  51. *
  52. * The mem argument is only used for getting the type of structures,
  53. * not for allocating; if it is NULL and full_print != 0, structures will
  54. * print as --(struct)--.
  55. */
  56. #define CVP_MAX_STRING 200 /* strings are truncated here if full_print = 1 */
  57. int obj_cvp(P7(const ref * op, byte *str, uint len, uint * prlen,
  58. int full_print, uint start_pos, gs_memory_t *mem));
  59. /*
  60. * Create a printable representation of an object, a la cvs and =. Return 0
  61. * if OK, e_rangecheck if the destination wasn't large enough,
  62. * e_invalidaccess if the object's contents weren't readable. If pchars !=
  63. * NULL, then if the object was a string or name, store a pointer to its
  64. * characters in *pchars even if it was too large; otherwise, set *pchars =
  65. * str. In any case, store the length in *prlen.
  66. *
  67. * obj_cvs is different from obj_cvp in two respects: if the printed
  68. * representation is too large, it returns e_rangecheck rather than 1;
  69. * and it can return a pointer to the data for names and strings, like
  70. * obj_string_data.
  71. */
  72. int obj_cvs(P5(const ref * op, byte * str, uint len, uint * prlen,
  73. const byte ** pchars));
  74. /* Get an element from an array (packed or not). */
  75. int array_get(P3(const ref *, long, ref *));
  76. /* Get an element from a packed array. */
  77. /* (This works for ordinary arrays too.) */
  78. /* Source and destination are allowed to overlap if the source is packed, */
  79. /* or if they are identical. */
  80. void packed_get(P2(const ref_packed *, ref *));
  81. /* Check to make sure an interval contains no object references */
  82. /* to a space younger than a given one. */
  83. /* Return 0 or e_invalidaccess. */
  84. int refs_check_space(P3(const ref * refs, uint size, uint space));
  85. /* ------ String utilities ------ */
  86. /* Convert a C string to a string object. */
  87. int string_to_ref(P4(const char *, ref *, gs_ref_memory_t *, client_name_t));
  88. /* Convert a string object to a C string. */
  89. /* Return 0 iff the buffer can't be allocated. */
  90. char *ref_to_string(P3(const ref *, gs_memory_t *, client_name_t));
  91. /* ------ Operand utilities ------ */
  92. /* Get N numeric operands from the stack or an array. */
  93. int num_params(P3(const ref *, int, double *));
  94. /* float_params can lose accuracy for large integers. */
  95. int float_params(P3(const ref *, int, float *));
  96. /* Get a single real parameter. */
  97. /* The only possible error is e_typecheck. */
  98. int real_param(P2(const ref *, double *));
  99. /* float_param can lose accuracy for large integers. */
  100. int float_param(P2(const ref *, float *));
  101. /* Get an integer parameter in a given range. */
  102. int int_param(P3(const ref *, int, int *));
  103. /* Make real values on the stack. */
  104. /* Return e_limitcheck for infinities or double->float overflow. */
  105. int make_reals(P3(ref *, const double *, int));
  106. int make_floats(P3(ref *, const float *, int));
  107. /* Define the gs_matrix type if necessary. */
  108. #ifndef gs_matrix_DEFINED
  109. # define gs_matrix_DEFINED
  110. typedef struct gs_matrix_s gs_matrix;
  111. #endif
  112. /* Read a matrix operand. */
  113. int read_matrix(P2(const ref *, gs_matrix *));
  114. /* Write a matrix operand. */
  115. /* If dmem is NULL, the array is guaranteed newly allocated in imem. */
  116. /* If dmem is not NULL, imem is ignored. */
  117. int write_matrix_in(P4(ref *op, const gs_matrix *pmat, gs_dual_memory_t *dmem,
  118. gs_ref_memory_t *imem));
  119. #define write_matrix_new(op, pmat, imem)\
  120. write_matrix_in(op, pmat, NULL, imem)
  121. #define write_matrix(op, pmat)\
  122. write_matrix_in(op, pmat, idmemory, NULL)
  123. #endif /* iutil_INCLUDED */