-
Notifications
You must be signed in to change notification settings - Fork 13
/
ps-printer-app.c
154 lines (131 loc) · 4.26 KB
/
ps-printer-app.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// PostScript Printer Application based on PAPPL and libpappl-retrofit
//
// Copyright © 2020 by Till Kamppeter.
// Copyright © 2020 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
//
//
// Include necessary headers...
//
#include <pappl-retrofit.h>
//
// Constants...
//
// Name and version
#define SYSTEM_NAME "PostScript Printer Application"
#define SYSTEM_PACKAGE_NAME "ps-printer-app"
#ifndef SYSTEM_VERSION_STR
# define SYSTEM_VERSION_STR "1.0"
#endif
#ifndef SYSTEM_VERSION_ARR_0
# define SYSTEM_VERSION_ARR_0 1
#endif
#ifndef SYSTEM_VERSION_ARR_1
# define SYSTEM_VERSION_ARR_1 0
#endif
#ifndef SYSTEM_VERSION_ARR_2
# define SYSTEM_VERSION_ARR_2 0
#endif
#ifndef SYSTEM_VERSION_ARR_3
# define SYSTEM_VERSION_ARR_3 0
#endif
#define SYSTEM_WEB_IF_FOOTER "Copyright © 2020 by Till Kamppeter. Provided under the terms of the <a href=\"https://www.apache.org/licenses/LICENSE-2.0\">Apache License 2.0</a>."
// Test page
#define TESTPAGE "testpage.pdf"
//
// 'ps_autoadd()' - Auto-add PostScript printers.
//
const char * // O - Driver name or `NULL` for none
ps_autoadd(const char *device_info, // I - Device name (unused)
const char *device_uri, // I - Device URI (unused)
const char *device_id, // I - IEEE-1284 device ID
void *data) // I - Global data
{
pr_printer_app_global_data_t *global_data =
(pr_printer_app_global_data_t *)data;
const char *ret = NULL; // Return value
char *p;
(void)device_info;
(void)device_uri;
if (device_id == NULL || global_data == NULL)
return (NULL);
// Look at the COMMAND SET (CMD) key for the list of printer languages...
//
// There are several printers for which PostScript is available in an
// add-on module, so there are printers with the same model name but
// with and without PostScript support. So we auto-add printers only
// if their device ID explicitly tells that they do PostScript
// We only make an exception on device IDs which do not inform about
// the printer's PDLs at all (no "CMD:" or "COMMAND SET:" fields)
// allowing them always. This is because some backends do not
// obtain the device ID from the printer but obtain make and model
// by another method and make an artificial device ID from them.
if ((strncmp(device_id, "CMD:", 4) &&
strncmp(device_id, "COMMAND SET:", 12) &&
strstr(device_id, ";CMD:") == NULL &&
strstr(device_id, ";COMMAND SET:") == NULL) ||
prSupportsPostScript(device_id))
{
// Printer supports PostScript, so find the best-matching PPD file
ret = prBestMatchingPPD(device_id, global_data);
if (strcmp(ret, "generic") == 0 && !prSupportsPostScript(device_id))
ret = NULL;
}
else
// Printer does not support PostScript, it is not supported by this
// Printer Application
ret = NULL;
return (ret);
}
//
// 'main()' - Main entry for the ps-printer-app.
//
int
main(int argc, // I - Number of command-line arguments
char *argv[]) // I - Command-line arguments
{
cups_array_t *spooling_conversions,
*stream_formats;
int ret;
// Array of spooling conversions, most desirables first
spooling_conversions = cupsArrayNew(NULL, NULL);
cupsArrayAdd(spooling_conversions, (void *)&PR_CONVERT_PS_TO_PS);
cupsArrayAdd(spooling_conversions, (void *)&PR_CONVERT_PDF_TO_PS);
// Array of stream formats, most desirables first
stream_formats = cupsArrayNew(NULL, NULL);
cupsArrayAdd(stream_formats, (void *)&PR_STREAM_POSTSCRIPT);
// Configuration record of the PostScript Printer Application
pr_printer_app_config_t printer_app_config =
{
SYSTEM_NAME,
SYSTEM_PACKAGE_NAME,
SYSTEM_VERSION_STR,
{
SYSTEM_VERSION_ARR_0,
SYSTEM_VERSION_ARR_1,
SYSTEM_VERSION_ARR_2,
SYSTEM_VERSION_ARR_3
},
SYSTEM_WEB_IF_FOOTER,
PR_COPTIONS_QUERY_PS_DEFAULTS |
PR_COPTIONS_WEB_ADD_PPDS |
PR_COPTIONS_NO_PAPPL_BACKENDS |
PR_COPTIONS_CUPS_BACKENDS,
ps_autoadd,
prIdentify,
prTestPage,
prSetupAddPPDFilesPage,
prSetupDeviceSettingsPage,
spooling_conversions,
stream_formats,
"",
"snmp,dnssd,usb",
TESTPAGE,
NULL,
NULL
};
return (prRetroFitPrinterApp(&printer_app_config, argc, argv));
}