zbseq.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* Copyright (C) 1990, 2000 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: zbseq.c,v 1.6 2002/02/21 22:24:54 giles Exp $ */
  14. /* Level 2 binary object sequence operators */
  15. #include "memory_.h"
  16. #include "ghost.h"
  17. #include "gxalloc.h" /* for names_array in allocator */
  18. #include "oper.h"
  19. #include "ialloc.h"
  20. #include "istruct.h"
  21. #include "btoken.h"
  22. #include "store.h"
  23. /*
  24. * Define the structure that holds the t_*array ref for the system or
  25. * user name table.
  26. */
  27. typedef struct names_array_ref_s {
  28. ref names;
  29. } names_array_ref_t;
  30. gs_private_st_ref_struct(st_names_array_ref, names_array_ref_t,
  31. "names_array_ref_t");
  32. /* Create a system or user name table (in the stable memory of mem). */
  33. int
  34. create_names_array(ref **ppnames, gs_memory_t *mem, client_name_t cname)
  35. {
  36. ref *pnames = (ref *)
  37. gs_alloc_struct(gs_memory_stable(mem), names_array_ref_t,
  38. &st_names_array_ref, cname);
  39. if (pnames == 0)
  40. return_error(e_VMerror);
  41. make_empty_array(pnames, a_readonly);
  42. *ppnames = pnames;
  43. return 0;
  44. }
  45. /* Initialize the binary token machinery. */
  46. private int
  47. zbseq_init(i_ctx_t *i_ctx_p)
  48. {
  49. /* Initialize a fake system name table. */
  50. /* PostScript code will install the real system name table. */
  51. ref *psystem_names = 0;
  52. int code = create_names_array(&psystem_names, imemory_global,
  53. "zbseq_init(system_names)");
  54. if (code < 0)
  55. return code;
  56. system_names_p = psystem_names;
  57. return 0;
  58. }
  59. /* <names> .installsystemnames - */
  60. private int
  61. zinstallsystemnames(i_ctx_t *i_ctx_p)
  62. {
  63. os_ptr op = osp;
  64. if (r_space(op) != avm_global || imemory_save_level(iimemory_global) != 0)
  65. return_error(e_invalidaccess);
  66. check_read_type(*op, t_shortarray);
  67. ref_assign_old(NULL, system_names_p, op, ".installsystemnames");
  68. pop(1);
  69. return 0;
  70. }
  71. /* - currentobjectformat <int> */
  72. private int
  73. zcurrentobjectformat(i_ctx_t *i_ctx_p)
  74. {
  75. os_ptr op = osp;
  76. push(1);
  77. *op = ref_binary_object_format;
  78. return 0;
  79. }
  80. /* <int> setobjectformat - */
  81. private int
  82. zsetobjectformat(i_ctx_t *i_ctx_p)
  83. {
  84. os_ptr op = osp;
  85. ref cont;
  86. check_type(*op, t_integer);
  87. if (op->value.intval < 0 || op->value.intval > 4)
  88. return_error(e_rangecheck);
  89. make_struct(&cont, avm_local, ref_binary_object_format_container);
  90. ref_assign_old(&cont, &ref_binary_object_format, op, "setobjectformat");
  91. pop(1);
  92. return 0;
  93. }
  94. /* <ref_offset> <char_offset> <obj> <string8> .bosobject */
  95. /* <ref_offset'> <char_offset'> <string8> */
  96. /*
  97. * This converts a single object to its binary object sequence
  98. * representation, doing the dirty work of printobject and writeobject.
  99. * (The main control is in PostScript code, so that we don't have to worry
  100. * about interrupts or callouts in the middle of writing the various data
  101. * items.) Note that this may or may not modify the 'unused' field.
  102. */
  103. private int
  104. zbosobject(i_ctx_t *i_ctx_p)
  105. {
  106. os_ptr op = osp;
  107. int code;
  108. check_type(op[-3], t_integer);
  109. check_type(op[-2], t_integer);
  110. check_write_type(*op, t_string);
  111. if (r_size(op) < 8)
  112. return_error(e_rangecheck);
  113. code = encode_binary_token(i_ctx_p, op - 1, &op[-3].value.intval,
  114. &op[-2].value.intval, op->value.bytes);
  115. if (code < 0)
  116. return code;
  117. op[-1] = *op;
  118. r_set_size(op - 1, 8);
  119. pop(1);
  120. return 0;
  121. }
  122. /* ------ Initialization procedure ------ */
  123. const op_def zbseq_l2_op_defs[] =
  124. {
  125. op_def_begin_level2(),
  126. {"1.installsystemnames", zinstallsystemnames},
  127. {"0currentobjectformat", zcurrentobjectformat},
  128. {"1setobjectformat", zsetobjectformat},
  129. {"4.bosobject", zbosobject},
  130. op_def_end(zbseq_init)
  131. };