| 1 |
/* |
| 2 |
* |
| 3 |
* Test pattern generator for Gimp-Print |
| 4 |
* |
| 5 |
* Copyright 2001 Robert Krawitz <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify it |
| 8 |
* under the terms of the GNU General Public License as published by the Free |
| 9 |
* Software Foundation; either version 2 of the License, or (at your option) |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, but |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 |
* for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
%{ |
| 22 |
|
| 23 |
#ifdef HAVE_CONFIG_H |
| 24 |
#include <config.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <string.h> |
| 28 |
#include <stdio.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include "testpattern.h" |
| 31 |
|
| 32 |
#pragma GCC diagnostic ignored "-Wredundant-decls" |
| 33 |
#pragma GCC diagnostic ignored "-Wunused-function" |
| 34 |
|
| 35 |
#define YY_NO_UNPUT |
| 36 |
|
| 37 |
int mylineno = 1; |
| 38 |
|
| 39 |
extern YYSTYPE yylval; |
| 40 |
|
| 41 |
static char * |
| 42 |
c_strstrip(char *s) |
| 43 |
{ |
| 44 |
size_t len = strlen(s); |
| 45 |
if (len >= 2 && ((s[0] == '"' && s[len - 1] == '"') || |
| 46 |
(s[0] == '\'' && s[len - 1] == '\''))) |
| 47 |
{ |
| 48 |
char *sn = malloc(len - 1); |
| 49 |
memcpy(sn, s + 1, len - 2); |
| 50 |
sn[len - 2] = '\0'; |
| 51 |
return sn; |
| 52 |
} |
| 53 |
else |
| 54 |
return stp_strdup(s); |
| 55 |
} |
| 56 |
|
| 57 |
#define DBG(x) \ |
| 58 |
do \ |
| 59 |
{ \ |
| 60 |
if (getenv("STP_TESTPATTERN_DEBUG")) \ |
| 61 |
fprintf(stderr, "'%s' => %s\n", yytext, #x); \ |
| 62 |
} \ |
| 63 |
while (0) |
| 64 |
|
| 65 |
|
| 66 |
%} |
| 67 |
|
| 68 |
%option noyywrap |
| 69 |
|
| 70 |
ldigit [1-9] |
| 71 |
digit [0-9] |
| 72 |
odigit [0-7] |
| 73 |
xdigit [0-9a-fA-F] |
| 74 |
integer ([-+]?(0|{ldigit}{digit}*))|(0{odigit}*)|(0[xX]{xdigit}+) |
| 75 |
float [-+]?{digit}+(\.{digit}+)?([eE][-+]?{digit}+)? |
| 76 |
string ([\"][^\"]*[\"])|([a-zA-Z0-9_][-a-zA-Z0-9_]*)|([\'][^\']*[\']) |
| 77 |
ws [ \t]+ |
| 78 |
color ((l_)?(cyan|magenta|yellow|black))|(l_l_black)|(d_yellow) |
| 79 |
|
| 80 |
%% |
| 81 |
|
| 82 |
gamma DBG(GAMMA); return GAMMA; |
| 83 |
level DBG(LEVEL); return LEVEL; |
| 84 |
steps DBG(STEPS); return STEPS; |
| 85 |
ink_limit DBG(INK_LIMIT); return INK_LIMIT; |
| 86 |
printer DBG(PRINTER); return PRINTER; |
| 87 |
parameter DBG(PARAMETER); return PARAMETER; |
| 88 |
parameter_int DBG(PARAMETER_INT); return PARAMETER_INT; |
| 89 |
parameter_bool DBG(PARAMETER_BOOL); return PARAMETER_BOOL; |
| 90 |
parameter_string DBG(PARAMETER); return PARAMETER; |
| 91 |
parameter_float DBG(PARAMETER_FLOAT); return PARAMETER_FLOAT; |
| 92 |
parameter_curve DBG(PARAMETER_CURVE); return PARAMETER_CURVE; |
| 93 |
density DBG(DENSITY); return DENSITY; |
| 94 |
top DBG(TOP); return TOP; |
| 95 |
left DBG(LEFT); return LEFT; |
| 96 |
size_mode DBG(SIZE_MODE); return SIZE_MODE; |
| 97 |
relative DBG(RELATIVE); return RELATIVE; |
| 98 |
pt DBG(PT); return PT; |
| 99 |
in DBG(IN); return IN; |
| 100 |
mm DBG(MM); return MM; |
| 101 |
hsize DBG(HSIZE); return HSIZE; |
| 102 |
vsize DBG(VSIZE); return VSIZE; |
| 103 |
blackline DBG(BLACKLINE); return BLACKLINE; |
| 104 |
colorline DBG(COLORLINE); return COLORLINE; |
| 105 |
pattern DBG(PATTERN); return PATTERN; |
| 106 |
xpattern DBG(XPATTERN); return XPATTERN; |
| 107 |
image DBG(IMAGE); return IMAGE; |
| 108 |
extended DBG(EXTENDED); return EXTENDED; |
| 109 |
grid DBG(GRID); return GRID; |
| 110 |
channel DBG(CHANNEL); return CHANNEL; |
| 111 |
page_size DBG(PAGESIZE); return PAGESIZE; |
| 112 |
; DBG(SEMI); return SEMI; |
| 113 |
mode DBG(MODE); return MODE; |
| 114 |
cmyk yylval.ival = CMYK;DBG(CMYK); return CMYK; |
| 115 |
kcmy yylval.ival = CMYK;DBG(KCMY); return KCMY; |
| 116 |
rgb yylval.ival = RGB;DBG(RGB); return RGB; |
| 117 |
cmy yylval.ival = RGB;DBG(CMY); return CMY; |
| 118 |
grey yylval.ival = GRAY;DBG(GRAY); return GRAY; |
| 119 |
gray yylval.ival = GRAY;DBG(GRAY); return GRAY; |
| 120 |
white yylval.ival = WHITE;DBG(WHITE); return WHITE; |
| 121 |
output DBG(OUTPUT); return OUTPUT; |
| 122 |
message DBG(MESSAGE); return MESSAGE; |
| 123 |
noscale DBG(NOSCALE); return NOSCALE; |
| 124 |
round DBG(ROUND); return ROUND; |
| 125 |
start_job DBG(START_JOB); return START_JOB; |
| 126 |
end_job DBG(END_JOB); return END_JOB; |
| 127 |
end DBG(END); return END; |
| 128 |
|
| 129 |
{color} yylval.sval = yytext;DBG(COLOR); return COLOR; |
| 130 |
{integer} yylval.ival = strtol(yytext, NULL, 0); yylval.dval = (double) yylval.ival; DBG(tINT); return tINT; |
| 131 |
{float} yylval.dval = strtod(yytext, NULL); DBG(tDOUBLE); return tDOUBLE; |
| 132 |
{string} yylval.sval = c_strstrip(yytext); DBG(tSTRING); return tSTRING; |
| 133 |
{ws} DBG(whitespace); /* Skip blanks/tabs */ |
| 134 |
#[^\n]* DBG(comment); /* Skip comments */ |
| 135 |
\n DBG(newline); mylineno++; |