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

« back to all changes in this revision

Viewing changes to base/gdevsco.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: gdevsco.c 8250 2007-09-25 13:31:24Z giles $ */
 
15
/* 17Jul91 - wb - based on gdevpcfb.c */
 
16
/* 31Jul91 - Rick Calder rick@rick.att.com - ifdefs for AT&T UNIX 4.0 2.1 */
 
17
/* 13Sep91 - wb - modify for gs24b2 */
 
18
/*  9Mar92 - wb - modify for gs24b4 */
 
19
/* generate SCO Xenix/Unix style memory mapped ioctl output */
 
20
#include "memory_.h"
 
21
#include "gx.h"
 
22
#include "gserrors.h"
 
23
#include "gxdevice.h"
 
24
#include "gdevpcfb.h"
 
25
#include <signal.h>
 
26
 
 
27
#ifdef M_XENIX
 
28
#include <sys/console.h>        /* SCO Xenix and SCO UNIX */
 
29
#ifndef CONSIO
 
30
#include <sys/machdep.h>        /* Xenix needs this also */
 
31
#endif
 
32
#else
 
33
#include <sys/kd.h>             /* AT&T SVR4 */
 
34
#endif
 
35
 
 
36
#if defined(__STDC__)
 
37
#include <stdlib.h>
 
38
#else
 
39
extern char *getenv(const char *);
 
40
#endif
 
41
 
 
42
#if defined(M_XENIX)
 
43
#include <prototypes.h>
 
44
#include <fcntl.h>
 
45
#else
 
46
extern int ioctl(int, int,...);
 
47
extern int open(const char *, int,...);
 
48
#endif
 
49
 
 
50
static int console_fd = -1;     /* file descriptor of console */
 
51
fb_ptr fb_addr;                 /* address of frame buffer for unix */
 
52
static int cur_mode = -1;       /* current video mode */
 
53
 
 
54
/* open the console */
 
55
/* possible files to open:
 
56
 * /dev/console = current system console
 
57
 * /dev/vga = vga monitor
 
58
 * /dev/tty = current terminal
 
59
 */
 
60
 
 
61
static void open_console(void);
 
62
 
 
63
static void
 
64
open_console()
 
65
{
 
66
    const char *dev;
 
67
 
 
68
    if (console_fd != -1)
 
69
        return;
 
70
    dev = getenv("GSDEVICE");
 
71
    if (dev == NULL || *dev == '\0')
 
72
        dev = "/dev/tty";
 
73
    console_fd = open(dev, 0);
 
74
    if (console_fd == -1) {
 
75
        ega_close((gx_device *) NULL);
 
76
        eprintf1("unable to map display '%s'\n", dev);
 
77
        perror("open_console");
 
78
        exit(1);
 
79
    }
 
80
}
 
81
 
 
82
#if defined(__GNUC__)
 
83
        /* Done with inline assembly in gdevpcfb.h */
 
84
#else
 
85
/* Output to a port */
 
86
void
 
87
outportb(uint port, byte data)
 
88
{
 
89
    int i;
 
90
    struct port_io_arg pio;
 
91
 
 
92
    if (console_fd == -1)
 
93
        open_console();
 
94
    pio.args[0].dir = OUT_ON_PORT;
 
95
    pio.args[0].port = port;
 
96
    pio.args[0].data = data;
 
97
    pio.args[1].port = 0;
 
98
    pio.args[2].port = 0;
 
99
    pio.args[3].port = 0;
 
100
    i = ioctl(console_fd, CONSIO, (long)(&pio));
 
101
    if (i == -1) {
 
102
        ega_close((gx_device *) NULL);
 
103
        eprintf("error setting device register\n");
 
104
        perror("outportb");
 
105
        exit(1);
 
106
    }
 
107
}
 
108
 
 
109
/* Output to 2 consecutive ports */
 
110
void
 
111
outport2(uint port, byte index, byte data)
 
112
{
 
113
    int i;
 
114
    struct port_io_arg pio;
 
115
 
 
116
    if (console_fd == -1)
 
117
        open_console();
 
118
    pio.args[0].dir = OUT_ON_PORT;
 
119
    pio.args[0].port = port;
 
120
    pio.args[0].data = index;
 
121
    pio.args[1].dir = OUT_ON_PORT;
 
122
    pio.args[1].port = port + 1;
 
123
    pio.args[1].data = data;
 
124
    pio.args[2].port = 0;
 
125
    pio.args[3].port = 0;
 
126
    i = ioctl(console_fd, CONSIO, (long)(&pio));
 
127
    if (i == -1) {
 
128
        ega_close((gx_device *) NULL);
 
129
        eprintf("error setting device register\n");
 
130
        perror("outport2");
 
131
        exit(1);
 
132
    }
 
133
}
 
134
#endif
 
135
 
 
136
/* interrupt signal handler */
 
137
/*  restore the video mode and exit */
 
138
static void
 
139
ega_int_handler(int sig)
 
140
{
 
141
    ega_close((gx_device *) NULL);
 
142
    eprintf("GS exiting...\n");
 
143
    exit(1);
 
144
}
 
145
 
 
146
/*
 
147
 * FIXME to make this work, the SIGCONT handler must restore the
 
148
 * the video state, including all the registers.
 
149
 * For now, I made the SIGSTOP handler exit just call the SIGINT handler
 
150
 */
 
151
 
 
152
#ifdef  SIGTSTP
 
153
/* user tried to stop us.  restore video and stop */
 
154
static void
 
155
ega_tstp_handler(int sig)
 
156
{
 
157
#if 1
 
158
    ega_int_handler(sig);
 
159
#else
 
160
    /* Preferable, but sco does not restore the monitor corretly */
 
161
    signal(SIGTSTP, ega_tstp_handler);
 
162
    ega_close((gx_device *) NULL);
 
163
    eprintf("GS stopping...\n");
 
164
    signal(SIGSTOP, SIG_DFL);
 
165
    kill(getpid(), SIGSTOP);
 
166
#endif
 
167
}
 
168
#endif /* SIGTSTP */
 
169
 
 
170
#ifdef  SIGCONT
 
171
/* we were unstopped.  reopen video */
 
172
static void
 
173
ega_cont_handler(int sig)
 
174
{
 
175
#if 1
 
176
    ega_int_handler(sig);
 
177
#else
 
178
    signal(SIGCONT, ega_cont_handler);
 
179
    ega_set_mode(cur_mode);
 
180
#endif
 
181
}
 
182
#endif /* SIGCONT */
 
183
 
 
184
/* ------ Internal routines ------ */
 
185
 
 
186
/* Catch signals so we can restore the video mode on exit. */
 
187
void
 
188
pcfb_set_signals(gx_device * dev)
 
189
{
 
190
    signal(SIGINT, ega_int_handler);
 
191
    signal(SIGTERM, ega_int_handler);
 
192
#ifdef  SIGTSTP
 
193
    signal(SIGTSTP, ega_tstp_handler);
 
194
#endif
 
195
#ifdef  SIGCONT
 
196
    signal(SIGCONT, ega_cont_handler);
 
197
#endif
 
198
}
 
199
 
 
200
/* Read the device mode */
 
201
void
 
202
pcfb_get_state(pcfb_bios_state * pbs)
 
203
{
 
204
    int mode;
 
205
 
 
206
    open_console();
 
207
    mode = ioctl(console_fd, CONS_CURRENT, 0L);
 
208
    if (mode == -1) {
 
209
#ifdef __linux__
 
210
        mode = M_ENH_C80x25;
 
211
#else
 
212
        ega_close((gx_device *) NULL);
 
213
        eprintf("unable to get current console mode\n");
 
214
        perror("pcfb_get_state");
 
215
        exit(1);
 
216
#endif
 
217
    }
 
218
    pbs->display_mode =
 
219
        (mode == M_ENH_CG640 || mode == M_CG640x350 ? 0x10 :
 
220
#ifdef M_VGA12
 
221
         mode == M_VGA12 ? 0x12 :
 
222
#endif
 
223
         0x03);
 
224
}
 
225
 
 
226
/* Set the device mode */
 
227
void
 
228
pcfb_set_mode(int mode)
 
229
{
 
230
    int i, mode1;
 
231
 
 
232
    open_console();
 
233
    cur_mode = mode;
 
234
    mode1 = -1;
 
235
    if (mode == 0x10)
 
236
        mode = SW_ENH_CG640;
 
237
#ifdef SW_VGA12
 
238
    else if (mode == 0x12)
 
239
        mode = SW_VGA12;
 
240
#endif
 
241
    else if (mode == 0x03) {
 
242
#ifdef SW_VGA80x25
 
243
        mode = SW_VGA80x25;
 
244
        mode1 = SW_ENHC80x25;
 
245
#else
 
246
        mode = SW_ENHC80x25;
 
247
#endif
 
248
    } else {
 
249
        eprintf1("can not set to video mode %d\n", mode);
 
250
        exit(1);
 
251
    }
 
252
    i = ioctl(console_fd, mode, 0L);
 
253
    if (i == -1 && mode1 != -1)
 
254
        i = ioctl(console_fd, mode1, 0L);
 
255
    if (i == -1) {
 
256
        ega_close((gx_device *) NULL);
 
257
        eprintf("unable to set console mode\n");
 
258
        perror("pcfb_set_mode");
 
259
        exit(1);
 
260
    }
 
261
#ifdef VGA_IOPRIVL
 
262
    if (ioctl(console_fd, VGA_IOPRIVL, 1) == -1) {
 
263
        ega_close((gx_device *) NULL);
 
264
        eprintf("unable to get I/O privilege\n");
 
265
        perror("pcfb_set_mode");
 
266
        exit(1);
 
267
    }
 
268
#endif
 
269
    i = ioctl(console_fd, MAPCONS, 0L);
 
270
    if (i == -1) {
 
271
        ega_close((gx_device *) NULL);
 
272
        eprintf("unable to map console adaptor's display memory\n");
 
273
        perror("pcfb_set_mode");
 
274
        exit(1);
 
275
    }
 
276
    fb_addr = (fb_ptr) (i);
 
277
}
 
278
 
 
279
/* Restore the device state */
 
280
void
 
281
pcfb_set_state(const pcfb_bios_state * pbs)
 
282
{
 
283
    pcfb_set_mode(pbs->display_mode);
 
284
}