Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* Copyright (C) 2004 artofcode LLC.  All rights reserved.
2
 
3
  This software is provided AS-IS with no warranty, either express or
4
  implied.
5
 
6
  This software is distributed under license and may not be copied,
7
  modified or distributed except as expressly authorized under the terms
8
  of the license contained in the file LICENSE in this distribution.
9
 
10
  For more information about licensing, please refer to
11
  http://www.ghostscript.com/licensing/. For information on
12
  commercial licensing, go to http://www.artifex.com/licensing/ or
13
  contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
  San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
*/
16
 
17
/* $Id: gp_os2pr.c,v 1.1 2004/09/14 06:45:55 ghostgum Exp $ */
18
/* %printer% IODevice */
19
 
20
#define INCL_DOS
21
#define INCL_SPL
22
#define INCL_SPLDOSPRINT
23
#define INCL_SPLERRORS
24
#define INCL_BASE
25
#define INCL_ERRORS
26
#define INCL_WIN
27
#include <os2.h>
28
 
29
#include "errno_.h"
30
#include "stdio_.h"
31
#include "string_.h"
32
#include "gp.h"
33
#include "gscdefs.h"
34
#include "gserrors.h"
35
#include "gserror.h"
36
#include "gstypes.h"
37
#include "gsmemory.h"		/* for gxiodev.h */
38
#include "gxiodev.h"
39
 
40
/* The OS/2 printer IODevice */
41
 
42
/*
43
 * This allows an OS/2 printer to be specified as an 
44
 * output using
45
 *  -sOutputFile="%printer%AppleLas"
46
 * where "AppleLas" is the physical name of the queue.
47
 *
48
 * If you don't supply a printer name you will get
49
 *  Error: /undefinedfilename in --.outputpage-- 
50
 * If the printer name is invalid you will get
51
 *  Error: /invalidfileaccess in --.outputpage-- 
52
 *
53
 * This is implemented by writing to a temporary file
54
 * then copying it to the spooler.
55
 *
56
 * A better method would be to return a file pointer
57
 * to the write end of a pipe, and starting a thread
58
 * which reads the pipe and writes to an OS/2 printer.
59
 * This method didn't work properly on the second
60
 * thread within ghostscript.
61
 */
62
 
63
private iodev_proc_init(os2_printer_init);
64
private iodev_proc_fopen(os2_printer_fopen);
65
private iodev_proc_fclose(os2_printer_fclose);
66
const gx_io_device gs_iodev_printer = {
67
    "%printer%", "FileSystem",
68
    {os2_printer_init, iodev_no_open_device,
69
     NULL /*iodev_os_open_file */ , os2_printer_fopen, os2_printer_fclose,
70
     iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
71
     iodev_no_enumerate_files, NULL, NULL,
72
     iodev_no_get_params, iodev_no_put_params
73
    }
74
};
75
 
76
typedef struct os2_printer_s {
77
    char queue[gp_file_name_sizeof];
78
    char filename[gp_file_name_sizeof];
79
} os2_printer_t;
80
 
81
/* The file device procedures */
82
private int
83
os2_printer_init(gx_io_device * iodev, gs_memory_t * mem)
84
{
85
    /* state -> structure containing thread handle */
86
    iodev->state = gs_alloc_bytes(mem, sizeof(os2_printer_t), 
87
	"os2_printer_init");
88
    if (iodev->state == NULL)
89
        return_error(gs_error_VMerror);
90
    memset(iodev->state, 0, sizeof(os2_printer_t));
91
    return 0;
92
}
93
 
94
 
95
private int
96
os2_printer_fopen(gx_io_device * iodev, const char *fname, const char *access,
97
	   FILE ** pfile, char *rfname, uint rnamelen)
98
{
99
    os2_printer_t *pr = (os2_printer_t *)iodev->state;
100
    char driver_name[256];
101
 
102
    /* Make sure that printer exists. */
103
    if (pm_find_queue(fname, driver_name)) {
104
	/* error, list valid queue names */
105
	eprintf("Invalid queue name.  Use one of:\n");
106
	pm_find_queue(NULL, NULL);
107
	return_error(gs_error_undefinedfilename);
108
    }
109
 
110
    strncpy(pr->queue, fname, sizeof(pr->queue)-1);
111
 
112
    /* Create a temporary file */
113
    *pfile = gp_open_scratch_file("gs", pr->filename, access);
114
    if (*pfile == NULL)
115
	return_error(gs_fopen_errno_to_code(errno));
116
 
117
    return 0;
118
}
119
 
120
private int
121
os2_printer_fclose(gx_io_device * iodev, FILE * file)
122
{
123
    os2_printer_t *pr = (os2_printer_t *)iodev->state;
124
    fclose(file);
125
    pm_spool(pr->filename, pr->queue); 
126
    unlink(pr->filename);
127
    return 0;
128
}
129