~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to psi/zstack.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: zstack.c 9778 2009-06-05 05:55:54Z alexcher $ */
 
14
/* $Id$ */
15
15
/* Operand stack operators */
16
16
#include "memory_.h"
17
17
#include "ghost.h"
66
66
 
67
67
    check_type(*op, t_integer);
68
68
    if ((ulong)op->value.intval >= (ulong)(op - osbot)) {
69
 
        /* Might be in an older stack block. */
70
 
        ref *elt;
 
69
        /* Might be in an older stack block. */
 
70
        ref *elt;
71
71
 
72
 
        if (op->value.intval < 0)
73
 
            return_error(e_rangecheck);
74
 
        elt = ref_stack_index(&o_stack, op->value.intval + 1);
75
 
        if (elt == 0)
76
 
            return_error(e_stackunderflow);
77
 
        ref_assign(op, elt);
78
 
        return 0;
 
72
        if (op->value.intval < 0)
 
73
            return_error(e_rangecheck);
 
74
        elt = ref_stack_index(&o_stack, op->value.intval + 1);
 
75
        if (elt == 0)
 
76
            return_error(e_stackunderflow);
 
77
        ref_assign(op, elt);
 
78
        return 0;
79
79
    }
80
80
    opn = op + ~(int)op->value.intval;
81
81
    ref_assign_inline(op, opn);
95
95
     * in fact, the only reason this operator exists.)
96
96
     */
97
97
    if (code == e_rangecheck && osp->value.intval >= 0)
98
 
        code = gs_note_error(e_stackunderflow);
 
98
        code = gs_note_error(e_stackunderflow);
99
99
    return code;
100
100
}
101
101
 
113
113
    check_type(*op1, t_integer);
114
114
    check_type(*op, t_integer);
115
115
    if ((uint) op1->value.intval > (uint)(op1 - osbot)) {
116
 
        /*
117
 
         * The data might span multiple stack blocks.
118
 
         * There are efficient ways to handle this situation,
119
 
         * but they're more complicated than seems worth implementing;
120
 
         * for now, do something very simple and inefficient.
121
 
         */
122
 
        int left, i;
123
 
 
124
 
        if (op1->value.intval < 0) 
125
 
            return_error(e_rangecheck);
126
 
        if (op1->value.intval + 2 > (int)ref_stack_count(&o_stack))
127
 
            return_error(e_stackunderflow);
128
 
        count = op1->value.intval;
129
 
        if (count <= 1) {
130
 
            pop(2);
131
 
            return 0;
132
 
        }
133
 
        mod = op->value.intval;
134
 
        if (mod >= count)
135
 
            mod %= count;
136
 
        else if (mod < 0) {
137
 
            mod %= count;
138
 
            if (mod < 0)
139
 
                mod += count;   /* can't assume % means mod! */
140
 
        }
141
 
        /* Use the chain rotation algorithm mentioned below. */
142
 
        for (i = 0, left = count; left; i++) {
143
 
            ref *elt = ref_stack_index(&o_stack, i + 2);
144
 
            ref save;
145
 
            int j, k;
146
 
            ref *next;
147
 
 
148
 
            save = *elt;
149
 
            for (j = i, left--;; j = k, elt = next, left--) {
150
 
                k = (j + mod) % count;
151
 
                if (k == i)
152
 
                    break;
153
 
                next = ref_stack_index(&o_stack, k + 2);
154
 
                ref_assign(elt, next);
155
 
            }
156
 
            *elt = save;
157
 
        }
158
 
        pop(2);
159
 
        return 0;
 
116
        /*
 
117
         * The data might span multiple stack blocks.
 
118
         * There are efficient ways to handle this situation,
 
119
         * but they're more complicated than seems worth implementing;
 
120
         * for now, do something very simple and inefficient.
 
121
         */
 
122
        int left, i;
 
123
 
 
124
        if (op1->value.intval < 0)
 
125
            return_error(e_rangecheck);
 
126
        if (op1->value.intval + 2 > (int)ref_stack_count(&o_stack))
 
127
            return_error(e_stackunderflow);
 
128
        count = op1->value.intval;
 
129
        if (count <= 1) {
 
130
            pop(2);
 
131
            return 0;
 
132
        }
 
133
        mod = op->value.intval;
 
134
        if (mod >= count)
 
135
            mod %= count;
 
136
        else if (mod < 0) {
 
137
            mod %= count;
 
138
            if (mod < 0)
 
139
                mod += count;   /* can't assume % means mod! */
 
140
        }
 
141
        /* Use the chain rotation algorithm mentioned below. */
 
142
        for (i = 0, left = count; left; i++) {
 
143
            ref *elt = ref_stack_index(&o_stack, i + 2);
 
144
            ref save;
 
145
            int j, k;
 
146
            ref *next;
 
147
 
 
148
            save = *elt;
 
149
            for (j = i, left--;; j = k, elt = next, left--) {
 
150
                k = (j + mod) % count;
 
151
                if (k == i)
 
152
                    break;
 
153
                next = ref_stack_index(&o_stack, k + 2);
 
154
                ref_assign(elt, next);
 
155
            }
 
156
            *elt = save;
 
157
        }
 
158
        pop(2);
 
159
        return 0;
160
160
    }
161
161
    count = op1->value.intval;
162
162
    if (count <= 1) {
163
 
        pop(2);
164
 
        return 0;
 
163
        pop(2);
 
164
        return 0;
165
165
    }
166
166
    mod = op->value.intval;
167
167
    /*
173
173
     * in *either* direction.
174
174
     */
175
175
    switch (mod) {
176
 
        case 1:         /* common special case */
177
 
            pop(2);
178
 
            op -= 2;
179
 
            {
180
 
                ref top;
181
 
 
182
 
                ref_assign_inline(&top, op);
183
 
                for (from = op, n = count; --n; from--)
184
 
                    ref_assign_inline(from, from - 1);
185
 
                ref_assign_inline(from, &top);
186
 
            }
187
 
            return 0;
188
 
        case -1:                /* common special case */
189
 
            pop(2);
190
 
            op -= 2;
191
 
            {
192
 
                ref bot;
193
 
 
194
 
                to = op - count + 1;
195
 
                ref_assign_inline(&bot, to);
196
 
                for (n = count; --n; to++)
197
 
                    ref_assign(to, to + 1);
198
 
                ref_assign_inline(to, &bot);
199
 
            }
200
 
            return 0;
 
176
        case 1:         /* common special case */
 
177
            pop(2);
 
178
            op -= 2;
 
179
            {
 
180
                ref top;
 
181
 
 
182
                ref_assign_inline(&top, op);
 
183
                for (from = op, n = count; --n; from--)
 
184
                    ref_assign_inline(from, from - 1);
 
185
                ref_assign_inline(from, &top);
 
186
            }
 
187
            return 0;
 
188
        case -1:                /* common special case */
 
189
            pop(2);
 
190
            op -= 2;
 
191
            {
 
192
                ref bot;
 
193
 
 
194
                to = op - count + 1;
 
195
                ref_assign_inline(&bot, to);
 
196
                for (n = count; --n; to++)
 
197
                    ref_assign(to, to + 1);
 
198
                ref_assign_inline(to, &bot);
 
199
            }
 
200
            return 0;
201
201
    }
202
202
    if (mod < 0) {
203
 
        mod += count;
204
 
        if (mod < 0) {
205
 
            mod %= count;
206
 
            if (mod < 0)
207
 
                mod += count;   /* can't assume % means mod! */
208
 
        }
 
203
        mod += count;
 
204
        if (mod < 0) {
 
205
            mod %= count;
 
206
            if (mod < 0)
 
207
                mod += count;   /* can't assume % means mod! */
 
208
        }
209
209
    } else if (mod >= count)
210
 
        mod %= count;
 
210
        mod %= count;
211
211
    if (mod <= count >> 1) {
212
 
        /* Move everything up, then top elements down. */
213
 
        if (mod >= ostop - op) {
214
 
            o_stack.requested = mod;
215
 
            return_error(e_stackoverflow);
216
 
        }
217
 
        pop(2);
218
 
        op -= 2;
219
 
        for (to = op + mod, from = op, n = count; n--; to--, from--)
220
 
            ref_assign(to, from);
221
 
        memcpy((char *)(from + 1), (char *)(op + 1), mod * sizeof(ref));
 
212
        /* Move everything up, then top elements down. */
 
213
        if (mod >= ostop - op) {
 
214
            o_stack.requested = mod;
 
215
            return_error(e_stackoverflow);
 
216
        }
 
217
        pop(2);
 
218
        op -= 2;
 
219
        for (to = op + mod, from = op, n = count; n--; to--, from--)
 
220
            ref_assign(to, from);
 
221
        memcpy((char *)(from + 1), (char *)(op + 1), mod * sizeof(ref));
222
222
    } else {
223
 
        /* Move bottom elements up, then everything down. */
224
 
        mod = count - mod;
225
 
        if (mod >= ostop - op) {
226
 
            o_stack.requested = mod;
227
 
            return_error(e_stackoverflow);
228
 
        }
229
 
        pop(2);
230
 
        op -= 2;
231
 
        to = op - count + 1;
232
 
        memcpy((char *)(op + 1), (char *)to, mod * sizeof(ref));
233
 
        for (from = to + mod, n = count; n--; to++, from++)
234
 
            ref_assign(to, from);
 
223
        /* Move bottom elements up, then everything down. */
 
224
        mod = count - mod;
 
225
        if (mod >= ostop - op) {
 
226
            o_stack.requested = mod;
 
227
            return_error(e_stackoverflow);
 
228
        }
 
229
        pop(2);
 
230
        op -= 2;
 
231
        to = op - count + 1;
 
232
        memcpy((char *)(op + 1), (char *)to, mod * sizeof(ref));
 
233
        for (from = to + mod, n = count; n--; to++, from++)
 
234
            ref_assign(to, from);
235
235
    }
236
236
    return 0;
237
237
}
275
275
    uint count = ref_stack_counttomark(&o_stack);
276
276
 
277
277
    if (count == 0)
278
 
        return_error(e_unmatchedmark);
 
278
        return_error(e_unmatchedmark);
279
279
    ref_stack_pop(&o_stack, count);
280
280
    return 0;
281
281
}
289
289
    uint count = ref_stack_counttomark(&o_stack);
290
290
 
291
291
    if (count == 0)
292
 
        return_error(e_unmatchedmark);
 
292
        return_error(e_unmatchedmark);
293
293
    push(1);
294
294
    make_int(op, count - 1);
295
295
    return 0;