Coverage Report

Created: 2022-10-31 07:00

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