~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to src/zstring.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2001-2006 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, modified
8
 
   or distributed except as expressly authorized under the terms of that
9
 
   license.  Refer to licensing information at http://www.artifex.com/
10
 
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11
 
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
 
*/
13
 
 
14
 
/* $Id: zstring.c 8250 2007-09-25 13:31:24Z giles $ */
15
 
/* String operators */
16
 
#include "memory_.h"
17
 
#include "ghost.h"
18
 
#include "gsutil.h"
19
 
#include "ialloc.h"
20
 
#include "iname.h"
21
 
#include "ivmspace.h"
22
 
#include "oper.h"
23
 
#include "store.h"
24
 
 
25
 
/* The generic operators (copy, get, put, getinterval, putinterval, */
26
 
/* length, and forall) are implemented in zgeneric.c. */
27
 
 
28
 
/* <int> .bytestring <bytestring> */
29
 
static int
30
 
zbytestring(i_ctx_t *i_ctx_p)
31
 
{
32
 
    os_ptr op = osp;
33
 
    byte *sbody;
34
 
    uint size;
35
 
 
36
 
    check_int_leu(*op, max_int);
37
 
    size = (uint)op->value.intval;
38
 
    sbody = ialloc_bytes(size, ".bytestring");
39
 
    if (sbody == 0)
40
 
        return_error(e_VMerror);
41
 
    make_astruct(op, a_all | icurrent_space, sbody);
42
 
    memset(sbody, 0, size);
43
 
    return 0;
44
 
}
45
 
 
46
 
/* <int> string <string> */
47
 
int
48
 
zstring(i_ctx_t *i_ctx_p)
49
 
{
50
 
    os_ptr op = osp;
51
 
    byte *sbody;
52
 
    uint size;
53
 
 
54
 
    check_type(*op, t_integer);
55
 
    if (op->value.intval < 0 ) 
56
 
        return_error(e_rangecheck);
57
 
    if (op->value.intval > max_string_size ) 
58
 
        return_error(e_limitcheck); /* to match Distiller */
59
 
    size = op->value.intval;
60
 
    sbody = ialloc_string(size, "string");
61
 
    if (sbody == 0)
62
 
        return_error(e_VMerror);
63
 
    make_string(op, a_all | icurrent_space, size, sbody);
64
 
    memset(sbody, 0, size);
65
 
    return 0;
66
 
}
67
 
 
68
 
/* <name> .namestring <string> */
69
 
static int
70
 
znamestring(i_ctx_t *i_ctx_p)
71
 
{
72
 
    os_ptr op = osp;
73
 
 
74
 
    check_type(*op, t_name);
75
 
    name_string_ref(imemory, op, op);
76
 
    return 0;
77
 
}
78
 
 
79
 
/* <string> <pattern> anchorsearch <post> <match> -true- */
80
 
/* <string> <pattern> anchorsearch <string> -false- */
81
 
static int
82
 
zanchorsearch(i_ctx_t *i_ctx_p)
83
 
{
84
 
    os_ptr op = osp;
85
 
    os_ptr op1 = op - 1;
86
 
    uint size = r_size(op);
87
 
 
88
 
    check_read_type(*op, t_string);
89
 
    check_read_type(*op1, t_string);
90
 
    if (size <= r_size(op1) && !memcmp(op1->value.bytes, op->value.bytes, size)) {
91
 
        os_ptr op0 = op;
92
 
 
93
 
        push(1);
94
 
        *op0 = *op1;
95
 
        r_set_size(op0, size);
96
 
        op1->value.bytes += size;
97
 
        r_dec_size(op1, size);
98
 
        make_true(op);
99
 
    } else
100
 
        make_false(op);
101
 
    return 0;
102
 
}
103
 
 
104
 
/* <string> <pattern> search <post> <match> <pre> -true- */
105
 
/* <string> <pattern> search <string> -false- */
106
 
static int
107
 
zsearch(i_ctx_t *i_ctx_p)
108
 
{
109
 
    os_ptr op = osp;
110
 
    os_ptr op1 = op - 1;
111
 
    uint size = r_size(op);
112
 
    uint count;
113
 
    byte *pat;
114
 
    byte *ptr;
115
 
    byte ch;
116
 
 
117
 
    check_read_type(*op1, t_string);
118
 
    check_read_type(*op, t_string);
119
 
    if (size > r_size(op1)) {   /* can't match */
120
 
        make_false(op);
121
 
        return 0;
122
 
    }
123
 
    count = r_size(op1) - size;
124
 
    ptr = op1->value.bytes;
125
 
    if (size == 0)
126
 
        goto found;
127
 
    pat = op->value.bytes;
128
 
    ch = pat[0];
129
 
    do {
130
 
        if (*ptr == ch && (size == 1 || !memcmp(ptr, pat, size)))
131
 
            goto found;
132
 
        ptr++;
133
 
    }
134
 
    while (count--);
135
 
    /* No match */
136
 
    make_false(op);
137
 
    return 0;
138
 
found:
139
 
    op->tas.type_attrs = op1->tas.type_attrs;
140
 
    op->value.bytes = ptr;
141
 
    r_set_size(op, size);
142
 
    push(2);
143
 
    op[-1] = *op1;
144
 
    r_set_size(op - 1, ptr - op[-1].value.bytes);
145
 
    op1->value.bytes = ptr + size;
146
 
    r_set_size(op1, count);
147
 
    make_true(op);
148
 
    return 0;
149
 
}
150
 
 
151
 
/* <string> <charstring> .stringbreak <int|null> */
152
 
static int
153
 
zstringbreak(i_ctx_t *i_ctx_p)
154
 
{
155
 
    os_ptr op = osp;
156
 
    uint i, j;
157
 
 
158
 
    check_read_type(op[-1], t_string);
159
 
    check_read_type(*op, t_string);
160
 
    /* We can't use strpbrk here, because C doesn't allow nulls in strings. */
161
 
    for (i = 0; i < r_size(op - 1); ++i)
162
 
        for (j = 0; j < r_size(op); ++j)
163
 
            if (op[-1].value.const_bytes[i] == op->value.const_bytes[j]) {
164
 
                make_int(op - 1, i);
165
 
                goto done;
166
 
            }
167
 
    make_null(op - 1);
168
 
 done:
169
 
    pop(1);
170
 
    return 0;
171
 
}
172
 
 
173
 
/* <obj> <pattern> .stringmatch <bool> */
174
 
static int
175
 
zstringmatch(i_ctx_t *i_ctx_p)
176
 
{
177
 
    os_ptr op = osp;
178
 
    os_ptr op1 = op - 1;
179
 
    bool result;
180
 
 
181
 
    check_read_type(*op, t_string);
182
 
    switch (r_type(op1)) {
183
 
        case t_string:
184
 
            check_read(*op1);
185
 
            goto cmp;
186
 
        case t_name:
187
 
            name_string_ref(imemory, op1, op1); /* can't fail */
188
 
cmp:
189
 
            result = string_match(op1->value.const_bytes, r_size(op1),
190
 
                                  op->value.const_bytes, r_size(op),
191
 
                                  NULL);
192
 
            break;
193
 
        default:
194
 
            result = (r_size(op) == 1 && *op->value.bytes == '*');
195
 
    }
196
 
    make_bool(op1, result);
197
 
    pop(1);
198
 
    return 0;
199
 
}
200
 
 
201
 
/* ------ Initialization procedure ------ */
202
 
 
203
 
const op_def zstring_op_defs[] =
204
 
{
205
 
    {"1.bytestring", zbytestring},
206
 
    {"2anchorsearch", zanchorsearch},
207
 
    {"1.namestring", znamestring},
208
 
    {"2search", zsearch},
209
 
    {"1string", zstring},
210
 
    {"2.stringbreak", zstringbreak},
211
 
    {"2.stringmatch", zstringmatch},
212
 
    op_def_end(0)
213
 
};