%{
/*
* lexer.l
*
* (c) Copyright 1988-1994 Adobe Systems Incorporated.
* All rights reserved.
*
* Permission to use, copy, modify, distribute, and sublicense this software
* and its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notices appear in all copies and that
* both those copyright notices and this permission notice appear in
* supporting documentation and that the name of Adobe Systems Incorporated
* not be used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. No trademark license
* to use the Adobe trademarks is hereby granted. If the Adobe trademark
* "Display PostScript"(tm) is used to describe this software, its
* functionality or for any other purpose, such use shall be limited to a
* statement that this software works in conjunction with the Display
* PostScript system. Proper trademark attribution to reflect Adobe's
* ownership of the trademark shall be given whenever any such reference to
* the Display PostScript system is made.
*
* ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
* ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
* TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
* PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
*
* Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
* Incorporated which may be registered in certain jurisdictions
*
* Author: Adobe Systems Incorporated
*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "pswpriv.h"
#include "pswparser.h"
/* flex of EMX seems to be too old */
int yylineno = 1;
#endif
static int parens = 0; /* current paren balancing */
static char *sbody; /* cur pointer into string_temp */
static int curleng = 0; /* current scanned string length */
static int strlineno; /* start line of current string */
static int nonComment = true; /* are we outside C comments? */
static int newLine = true; /* are we starting a new line? */
static int hexstringerrs = 0; /* found an error in this hex string */
int errorCount = 0; /* number of non-fatal errors */
#ifdef PSWDEBUG
#else /* PSWDEBUG */
#define DEBUGP(x)
#endif /* PSWDEBUG */
#define YYLMAX 16384
/* ErrIntro prints a standard intro for error messages;
* change it if your system uses something else. We have many options:
*
* to match Macintosh: #define FMT "File \"%s\"; Line %d # "
* to match BSD cc: #define FMT "\"%s\", line %d: "
* to match gcc: #define FMT "%s:%d: "
* to match Mips cc: #define FMT "pswrap: Error: %s, line %d: "
*/
#define INTRO "# In function %s -\n"
#ifdef macintosh
#define FMT "File \"%s\"; Line %d # "
#else /* macintosh */
#define FMT "\"%s\", line %d: "
#endif /* macintosh */
{
if (! reportedPSWName && currentPSWName) {
reportedPSWName = 1;
}
errorCount++;
}
{
}
%}
%o 3500
%a 2500
DIGIT ([0-9])
SIGN ([+-])
W ([ \t\n\r])
%%
if (nonComment) {
newLine = false;
return PSNAME;
}
}
if (nonComment) {
return CNAME;
}
}
register int i = yyleng;
register unsigned char *c = (unsigned char *) yytext;
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
for (; i > 0; --i) *sbody++ = *c++;
}
^{W}*defineps { /* start of a wrap definition */
if (nonComment) {
return DEFINEPS;
} else ECHO;
}
if (nonComment){
if (newLine) {
newLine = false;
BEGIN 0;
return ENDPS;
} else {
return PSNAME;
}
}
}
if (nonComment) {
return CNAME;
}
}
register int i = yyleng;
register unsigned char *c = (unsigned char *) yytext;
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
for (; i > 0; --i) *sbody++ = *c++;
}
endps { /* BOGUS end of a wrap */
if (nonComment) {
} else ECHO;
}
%{
/* real definition stuff */
%}
nonComment = false;
}
nonComment = true;
}
if (nonComment) {
return '(';
}
}
if (nonComment) {
return ')';
}
}
<DEF>[|,;[\]*:] { /* special single chars */
if (nonComment) {
return (yytext[0]);
}
}
%{
/* formals type names */
%}
<DEF>"static" {
if (nonComment) {
return STATIC;
}
}
<DEF>"boolean" {
if (nonComment) {
return BOOLEAN;
}
}
<DEF>"char" {
if (nonComment) {
return CHAR;
}
}
<DEF>"int" {
if (nonComment) {
return INT;
}
}
<DEF>"short" {
if (nonComment) {
return SHORT;
}
}
<DEF>"long" {
if (nonComment) {
return LONG;
}
}
<DEF>"unsigned" {
if (nonComment) {
return UNSIGNED;
}
}
<DEF>"float" {
if (nonComment) {
return FLOAT;
}
}
<DEF>"double" {
if (nonComment) {
return DOUBLE;
}
}
<DEF>"userobject" {
if (nonComment) {
return USEROBJECT;
}
}
<DEF>"numstring" {
if (nonComment) {
return NUMSTRING;
}
}
<DEF>"DPSContext" {
if (nonComment) {
return PSCONTEXT;
}
}
%{
/* C format numbers in formals part */
%}
if (nonComment) {
return CINTEGER;
}
}
if (nonComment) {
/* I have no idea why the cast is needed in the next line,
but it seems to make the compiler happy on alpha */
return CINTEGER;
}
}
if (nonComment) {
/* See previous comment... */
return CINTEGER;
}
}
if (nonComment) {
return CNAME;
}
}
<DEF>{W}+ {
}
if (nonComment) {
yytext);
}
}
%{
/* body part - PostScript code */
%}
<PS>\%.* { /* a PS comment, ignore */
if (nonComment) {
newLine = false;
/* yylval = yytext; return PSCOMMENT; */
}
}
if (nonComment) {
newLine = false;
return PSINTEGER;
}
}
#define MAX_ULONG ((unsigned long) -1)
unsigned base = 0;
unsigned char *s = (unsigned char *) yytext;
register unsigned long x, limit;
register unsigned long i = 0;
if (nonComment) {
newLine = false;
while (*s != '#') {
base *= 10;
base += *s++ - '0';
if (base > 32) break;
}
else {
s++; /* skip # sign */
while (*s != '\0') {
i *= base;
if (isdigit(*s)) { x = *s - '0';}
else { x = (*s | 040) - ('a'-10);}
i += x;
s++;
}
}
return PSINTEGER;
error:;
return PSINTEGER;
}
}
/* a float */
if (nonComment) {
newLine = false;
return PSREAL;
}
}
if (nonComment) {
newLine = false;
parens=1;
sbody = string_temp;
curleng = 0;
*sbody = '\0';
}
}
%{
/* inside PS strings */
%}
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
parens++;
*sbody++ = '(';
}
if ((--parens) == 0) {
*sbody = '\0';
return PSSTRING;
}
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
*sbody++ = ')';
}
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
curleng += 4;
while (*sbody) {
sbody++;
}
}
}
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
*sbody++ = '\\';
*sbody++ = '\\';
curleng += 2;
}
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
switch (yytext[1]) {
case 'b':
*sbody++ = '\b';
break;
case 'f':
*sbody++ = '\f';
break;
case 'n':
*sbody++ = '\012';
break;
case 'r':
*sbody++ = '\015';
break;
case 't':
*sbody++ = '\t';
break;
default:
break;
}
curleng++;
}
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
*sbody++ = '\n';
}
<STR>[^()\\\n]+ { /* anything else */
register int i = yyleng;
register unsigned char *c = (unsigned char *) yytext;
stringerr(1);
*sbody = '\0';
return PSSTRING;
}
for (; i > 0; --i) *sbody++ = *c++;
}
%{
/* hexidecimal strings "< >" */
%}
if (nonComment) {
newLine = false;
sbody = string_temp;
*sbody = '\0';
curleng = 0;
hexstringerrs = 0;
}
}
<HEX>{W}+ { /* hex whitespace */
/* ignore */
}
stringerr(2);
*sbody = '\0';
return PSHEXSTRING;
}
}
*sbody = '\0';
return PSHEXSTRING;
}
if (hexstringerrs == 0) { /* only complain once per string */
}
}
%{
/* straight postscript */
%}
if (nonComment) {
newLine = false;
return PSNAME;
}
}
if (nonComment) {
newLine = false;
return PSNAME;
}
}
<PS>[\[\]\{\}] { /* PS self delimiter */
if (nonComment) {
newLine = false;
return (yytext[0]);
}
}
if (nonComment) {
newLine = false;
return PSBOOLEAN;
}
}
if (nonComment) {
newLine = false;
return PSLITNAME;
}
}
<PS>[^ <>\(\)\[\]\{\}\%\/\\\t\n\r]+ { /* executable name */
if (nonComment) {
newLine = false;
return PSNAME;
}
}
if (nonComment) {
newLine = false;
unput('/');
return PSNAME;
}
}
if (nonComment) {
return PSSUBNAME;
}
}
<SUB>[\[][^ \t\]]*[\]] { /* [index] */
if (nonComment) {
if (len == 2) {
}
else {
}
return PSINDEX;
}
}
<SUB>[\[][^\]]*[\]] { /* error */
if (nonComment) {
return PSINDEX;
}
}
<PS>[\)\>\\]+ { /* ERROR */
if (nonComment) {
newLine = false;
}
}
<PS>[ \t\r]+ { }
<PS>[\n]+ {
newLine = true;
}
[ \t]+ { /* passthru stuff */
ECHO;
}
\n {
outlineno++;
ECHO;
};
"/*" { /* C comments on */
nonComment = false;
ECHO;
}
"*/" { /* C comments off */
if (!nonComment) {
nonComment = true;
ECHO;
}
}
%%
int yywrap (void) {
return (0);
/* The following appears not to work with flex. As it is error
handling code, we just comment it out. */
#if !defined(FLEX_SCANNER)
}
#endif
return (1);
}
{
errorCount++;
return;
}