AmendHub

Download

thecloud

/

SimpleSpooler

/

QueryParser.c

 

(View History)

thecloud   Simple Spooler 0.1 release Latest amendment: 1 on 2026-07-29

1 /*
2 * QueryParser.c
3 *
4 * Routines for parsing and responding to PostScript queries.
5 *
6 * Written by: Ken McLeod, 2026-02-10
7 * Last update: 2026-02-16
8 *
9 * This software is provided as-is, with no warranties expressed or implied,
10 * under the terms of the BSD 2-Clause License. See separate "LICENSE" file.
11 */
12
13 #include <Types.h>
14 #include <Memory.h>
15 #include <OSUtils.h>
16 #include <Packages.h>
17 #include <String.h>
18 #include "QueryParser.h"
19
20
21 int BuildResponseToPSQuery(char *data, int dataLen, char *resp, int respLen)
22 {
23 /* quick and dirty routine to parse features being requested
24 * by the driver so we respond in the correct order. Input data
25 * points to the query (i.e. the response to our last SendData)
26 * with length dataLen. resp is a pointer to a buffer preallocated
27 * for our response, which can be no larger than respLen bytes.
28 */
29 int length = dataLen;
30 int index, rspIdx = 0;
31
32 if (!data || !dataLen || !resp || !respLen) {
33 return 0;
34 }
35 for (index=0; index<length; index++) {
36 if ((length>(index+3)) &&
37 (!memcmp("%%?",&data[index],3))) {
38 index += 3;
39 if ((length>(index+19+21)) && /* query prefix plus longest strlen */
40 (!memcmp("BeginFeatureQuery: ",&data[index],19))) {
41 index += 19;
42 /* feature query */
43 if (!memcmp("*LanguageLevel",&data[index],14)) {
44 BlockMove("\"3\"\n",&resp[rspIdx],4);
45 index += 14;
46 rspIdx += 4;
47 } else if (!memcmp("*PSVersion",&data[index],10)) {
48 BlockMove("\"(3010.10 6) 5\"\n",&resp[rspIdx],16);
49 index += 10;
50 rspIdx += 16;
51 } else if (!memcmp("*?Resolution",&data[index],12)) {
52 BlockMove("600dpi\n",&resp[rspIdx],7);
53 index += 12;
54 rspIdx += 7;
55 } else if (!memcmp("*TTRasterizer",&data[index],13)) {
56 BlockMove("Type42\n",&resp[rspIdx],7);
57 index += 13;
58 rspIdx += 7;
59 } else if (!memcmp("*DefaultColorSpace",&data[index],18)) {
60 BlockMove("Gray\n",&resp[rspIdx],5);
61 index += 18;
62 rspIdx += 5;
63 } else if (!memcmp("*LandscapeOrientation",&data[index],21)) {
64 BlockMove("Minus90\n",&resp[rspIdx],8);
65 index += 21;
66 rspIdx += 8;
67 } else if (!memcmp("*Product",&data[index],8)) {
68 BlockMove("\"(Simple Spooler)\"\n",&resp[rspIdx],19);
69 index += 8;
70 rspIdx += 19;
71 }
72
73 } else if ((length>(index+16)) &&
74 (!memcmp("BeginFontQuery: ",&data[index],16))) {
75 char *tokenEnd;
76 int tokenLen;
77 index += 16;
78 /* font query */
79 tokenEnd = &data[index];
80 tokenLen = 0;
81 while (index<length) {
82 tokenEnd++;
83 tokenLen++;
84 if (*tokenEnd == 0x20 || *tokenEnd == 0x0D || *tokenEnd == 0x0A) {
85 resp[rspIdx++] = '/';
86 BlockMove(&data[index],&resp[rspIdx],tokenLen);
87 rspIdx += tokenLen;
88 /* we want all fonts used to be supplied with the
89 * document, so we reply 'No' for each one specified.
90 */
91 BlockMove(":No\n\r",&resp[rspIdx],5);
92 rspIdx += 5;
93 if (*tokenEnd == 0x20) {
94 /* move forward to start of next token */
95 index += tokenLen+1;
96 tokenEnd = &data[index];
97 tokenLen = 0;
98 } else {
99 /* at end of font query line */
100 break;
101 }
102 }
103 }
104 BlockMove("*\n\r",&resp[rspIdx],3);
105 rspIdx += 3;
106
107 } else if ((length>(index+12)) &&
108 (!memcmp("BeginQuery: ",&data[index],12))) {
109 index += 12;
110 /* query */
111 if (!memcmp("ADOSpooler",&data[index],10)) {
112 /* this can return 0 or spooler */
113 BlockMove("0\n",&resp[rspIdx],2);
114 index += 10;
115 rspIdx += 2;
116 } else if (!memcmp("ADOIsBinaryOK?",&data[index],14)) {
117 BlockMove("False\n",&resp[rspIdx],6);
118 index += 14;
119 rspIdx += 6;
120 } else if (!memcmp("RBIUAMListQuery",&data[index],15)) {
121 /* LaserWriter 8.6.1 or later can use ASIP security protocol */
122 BlockMove("*\n",&resp[rspIdx],2);
123 index += 15;
124 rspIdx += 2;
125 }
126
127 } else if ((length>(index+19)) &&
128 (!memcmp("BeginProcSetQuery: ",&data[index],19))) {
129 index += 19;
130 /* proc set query */
131 BlockMove("unknown\n\r",&resp[rspIdx],9);
132 rspIdx += 9;
133
134 } else if ((length>(index+5)) &&
135 (!memcmp("Begin",&data[index],5))) {
136 index += 5;
137 /* everything else is unknown */
138 BlockMove("unknown\n\r",&resp[rspIdx],9);
139 rspIdx += 9;
140 }
141
142 } /* found a query prefix '%%?' */
143 } /* end parse loop */
144
145 return rspIdx;
146 }