/* * QueryParser.c * * Routines for parsing and responding to PostScript queries. * * Written by: Ken McLeod, 2026-02-10 * Last update: 2026-02-16 * * This software is provided as-is, with no warranties expressed or implied, * under the terms of the BSD 2-Clause License. See separate "LICENSE" file. */ #include #include #include #include #include #include "QueryParser.h" int BuildResponseToPSQuery(char *data, int dataLen, char *resp, int respLen) { /* quick and dirty routine to parse features being requested * by the driver so we respond in the correct order. Input data * points to the query (i.e. the response to our last SendData) * with length dataLen. resp is a pointer to a buffer preallocated * for our response, which can be no larger than respLen bytes. */ int length = dataLen; int index, rspIdx = 0; if (!data || !dataLen || !resp || !respLen) { return 0; } for (index=0; index(index+3)) && (!memcmp("%%?",&data[index],3))) { index += 3; if ((length>(index+19+21)) && /* query prefix plus longest strlen */ (!memcmp("BeginFeatureQuery: ",&data[index],19))) { index += 19; /* feature query */ if (!memcmp("*LanguageLevel",&data[index],14)) { BlockMove("\"3\"\n",&resp[rspIdx],4); index += 14; rspIdx += 4; } else if (!memcmp("*PSVersion",&data[index],10)) { BlockMove("\"(3010.10 6) 5\"\n",&resp[rspIdx],16); index += 10; rspIdx += 16; } else if (!memcmp("*?Resolution",&data[index],12)) { BlockMove("600dpi\n",&resp[rspIdx],7); index += 12; rspIdx += 7; } else if (!memcmp("*TTRasterizer",&data[index],13)) { BlockMove("Type42\n",&resp[rspIdx],7); index += 13; rspIdx += 7; } else if (!memcmp("*DefaultColorSpace",&data[index],18)) { BlockMove("Gray\n",&resp[rspIdx],5); index += 18; rspIdx += 5; } else if (!memcmp("*LandscapeOrientation",&data[index],21)) { BlockMove("Minus90\n",&resp[rspIdx],8); index += 21; rspIdx += 8; } else if (!memcmp("*Product",&data[index],8)) { BlockMove("\"(Simple Spooler)\"\n",&resp[rspIdx],19); index += 8; rspIdx += 19; } } else if ((length>(index+16)) && (!memcmp("BeginFontQuery: ",&data[index],16))) { char *tokenEnd; int tokenLen; index += 16; /* font query */ tokenEnd = &data[index]; tokenLen = 0; while (index(index+12)) && (!memcmp("BeginQuery: ",&data[index],12))) { index += 12; /* query */ if (!memcmp("ADOSpooler",&data[index],10)) { /* this can return 0 or spooler */ BlockMove("0\n",&resp[rspIdx],2); index += 10; rspIdx += 2; } else if (!memcmp("ADOIsBinaryOK?",&data[index],14)) { BlockMove("False\n",&resp[rspIdx],6); index += 14; rspIdx += 6; } else if (!memcmp("RBIUAMListQuery",&data[index],15)) { /* LaserWriter 8.6.1 or later can use ASIP security protocol */ BlockMove("*\n",&resp[rspIdx],2); index += 15; rspIdx += 2; } } else if ((length>(index+19)) && (!memcmp("BeginProcSetQuery: ",&data[index],19))) { index += 19; /* proc set query */ BlockMove("unknown\n\r",&resp[rspIdx],9); rspIdx += 9; } else if ((length>(index+5)) && (!memcmp("Begin",&data[index],5))) { index += 5; /* everything else is unknown */ BlockMove("unknown\n\r",&resp[rspIdx],9); rspIdx += 9; } } /* found a query prefix '%%?' */ } /* end parse loop */ return rspIdx; }