#ifndef lint static char const yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; #endif #include #define YYBYACC 1 #define YYMAJOR 1 #define YYMINOR 9 #define YYLEX yylex() #define YYEMPTY -1 #define yyclearin (yychar=(YYEMPTY)) #define yyerrok (yyerrflag=0) #define YYRECOVERING (yyerrflag!=0) #if defined(c_plusplus) || defined(__cplusplus) #include #else extern char *getenv(); extern void *realloc(); #endif static int yygrowstack(); #define YYPREFIX "yy" #line 2 "parse.y" /* * Copyright 1988 by Siemens * All Rights Reserved * * Permission to use, copy, modify and distribute this software is * hereby granted, provided that this copyright notice appear in all * copies and that the copyright notice appear in supporting documentation. * * written 16-17 Mar 1988 by claus gittinger * * q & d hacked grammar for .bdf files. * */ /* * Modified by Mark Moraes @ the University of Toronto to make it handle * a larger subset of BDF. It now reads in all the font files in X.V11R3 * without complaints. Comments all get gathered in at the beginning * thanks to the kludgey way in which they're now stored -- fixes * welcome. */ #include #include #include "defs.h" #define MAXROWS 512 #define INC_COMMENTS 32 /* size in which comments array grows */ extern int lineno; /* counts lines in .bdf input file */ extern int stringMode; /* kludge in scan.l */ extern int minx, miny, maxx, maxy; static struct character *charp; /* current character */ static char *bits[MAXROWS]; /* that good for long characters ... */ static int nrows; static int npropCounted; #line 38 "parse.y" typedef union { int ival; char *sval; } YYSTYPE; #line 62 "parse.c" #define NEWLINE 257 #define DOT 258 #define STARTFONT 259 #define SIZE 260 #define FONTBOUNDINGBOX 261 #define STARTPROPERTIES 262 #define ENDPROPERTIES 263 #define CHARS 264 #define ENCODING 265 #define SWIDTH 266 #define DWIDTH 267 #define BBX 268 #define BITMAP 269 #define ENDCHAR 270 #define ENDFONT 271 #define FONT 272 #define PROPERTY 273 #define STARTCHAR 274 #define COMMENT 275 #define STRING 276 #define IDENTIFIER 277 #define NUMBER 278 #define YYERRCODE 256 const short yylhs[] = { -1, 0, 1, 3, 4, 4, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 14, 15, 13, 2, 16, 17, 17, 18, 19, 19, 21, 21, 21, 21, 22, 22, 23, 23, 24, 24, 25, 20, 26, 27, 27, 29, 28, }; const short yylen[] = { 2, 4, 2, 5, 1, 2, 1, 1, 1, 1, 1, 2, 2, 5, 6, 3, 3, 1, 2, 1, 1, 2, 2, 2, 3, 0, 2, 6, 1, 2, 1, 1, 1, 1, 3, 4, 3, 4, 3, 4, 6, 4, 2, 0, 3, 0, 0, }; const short yydefred[] = { 0, 0, 0, 0, 0, 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, 4, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 12, 11, 5, 0, 19, 0, 17, 20, 0, 24, 1, 0, 26, 0, 0, 16, 21, 0, 15, 18, 3, 0, 0, 0, 22, 0, 0, 0, 0, 0, 28, 30, 31, 32, 33, 13, 0, 0, 0, 0, 0, 45, 0, 29, 0, 14, 34, 0, 36, 0, 38, 0, 0, 42, 0, 43, 35, 37, 39, 0, 27, 0, 0, 0, 41, 40, 44, }; const short yydgoto[] = { 2, 3, 7, 4, 14, 15, 16, 17, 18, 19, 20, 21, 34, 47, 35, 36, 8, 25, 41, 58, 71, 59, 60, 61, 62, 63, 73, 90, 93, 82, }; const short yysindex[] = { -240, -274, 0, -253, -248, -238, -260, -246, 0, -252, -245, -243, -221, -220, -248, 0, 0, 0, 0, 0, 0, -241, -239, -219, -217, -233, -236, -235, -213, 0, 0, 0, -212, 0, -258, 0, 0, -211, 0, 0, -210, 0, -230, -229, 0, 0, -207, 0, 0, 0, -237, -206, -226, 0, -225, -224, -223, -222, -259, 0, 0, 0, 0, 0, 0, -200, -257, -256, -255, -218, 0, -209, 0, -199, 0, 0, -198, 0, -195, 0, -194, -214, 0, -192, 0, 0, 0, 0, -208, 0, -205, -191, -190, 0, 0, 0, }; const short yyrindex[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -202, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -197, 0, 0, 0, 0, 0, }; const short yygindex[] = { 0, 0, 0, 0, 0, 58, -18, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, }; #define YYTABLESIZE 75 const short yytable[] = { 75, 77, 79, 33, 5, 46, 54, 55, 56, 57, 70, 6, 9, 10, 11, 32, 33, 13, 23, 1, 22, 76, 78, 80, 12, 24, 26, 13, 54, 55, 56, 57, 32, 27, 13, 28, 29, 30, 38, 37, 39, 40, 42, 43, 44, 45, 49, 50, 51, 52, 53, 64, 65, 66, 67, 68, 69, 74, 84, 85, 81, 83, 86, 87, 88, 89, 94, 95, 2, 23, 91, 92, 31, 46, 48, 72, }; const short yycheck[] = { 257, 257, 257, 21, 278, 263, 265, 266, 267, 268, 269, 264, 260, 261, 262, 273, 34, 275, 278, 259, 258, 278, 278, 278, 272, 271, 278, 275, 265, 266, 267, 268, 273, 278, 275, 278, 257, 257, 257, 278, 257, 274, 278, 278, 257, 257, 257, 257, 278, 278, 257, 257, 278, 278, 278, 278, 278, 257, 257, 257, 278, 270, 257, 257, 278, 257, 257, 257, 264, 271, 278, 276, 14, 270, 34, 58, }; #define YYFINAL 2 #ifndef YYDEBUG #define YYDEBUG 0 #elif YYDEBUG #include #endif #define YYMAXTOKEN 278 #if YYDEBUG const char * const yyname[] = { "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"NEWLINE","DOT","STARTFONT", "SIZE","FONTBOUNDINGBOX","STARTPROPERTIES","ENDPROPERTIES","CHARS","ENCODING", "SWIDTH","DWIDTH","BBX","BITMAP","ENDCHAR","ENDFONT","FONT","PROPERTY", "STARTCHAR","COMMENT","STRING","IDENTIFIER","NUMBER", }; const char * const yyrule[] = { "$accept : file", "file : definitions characters ENDFONT NEWLINE", "definitions : startfont fontdefs", "startfont : STARTFONT NUMBER DOT NUMBER NEWLINE", "fontdefs : fontdef", "fontdefs : fontdefs fontdef", "fontdef : comment", "fontdef : font", "fontdef : size", "fontdef : boundingbox", "fontdef : properties", "comment : COMMENT NEWLINE", "font : FONT NEWLINE", "size : SIZE NUMBER NUMBER NUMBER NEWLINE", "boundingbox : FONTBOUNDINGBOX NUMBER NUMBER NUMBER NUMBER NEWLINE", "properties : startprop props endprop", "startprop : STARTPROPERTIES NUMBER NEWLINE", "props : prop", "props : props prop", "prop : comment", "prop : junk", "junk : PROPERTY NEWLINE", "endprop : ENDPROPERTIES NEWLINE", "characters : chars chardefs", "chars : CHARS NUMBER NEWLINE", "chardefs :", "chardefs : chardefs character", "character : STARTCHAR NEWLINE charprops bitmap ENDCHAR NEWLINE", "charprops : charprop", "charprops : charprops charprop", "charprop : encoding", "charprop : swidth", "charprop : dwidth", "charprop : bbx", "encoding : ENCODING NUMBER NEWLINE", "encoding : ENCODING NUMBER NUMBER NEWLINE", "swidth : SWIDTH NUMBER NEWLINE", "swidth : SWIDTH NUMBER NUMBER NEWLINE", "dwidth : DWIDTH NUMBER NEWLINE", "dwidth : DWIDTH NUMBER NUMBER NEWLINE", "bbx : BBX NUMBER NUMBER NUMBER NUMBER NEWLINE", "bitmap : bitmapstart NEWLINE numbers stringmodeoff", "bitmapstart : BITMAP stringmodeon", "numbers :", "numbers : numbers STRING NEWLINE", "stringmodeon :", "stringmodeoff :", }; #endif #ifdef YYSTACKSIZE #undef YYMAXDEPTH #define YYMAXDEPTH YYSTACKSIZE #else #ifdef YYMAXDEPTH #define YYSTACKSIZE YYMAXDEPTH #else #define YYSTACKSIZE 10000 #define YYMAXDEPTH 10000 #endif #endif #define YYINITSTACKSIZE 200 int yydebug; int yynerrs; int yyerrflag; int yychar; short *yyssp; YYSTYPE *yyvsp; YYSTYPE yyval; YYSTYPE yylval; short *yyss; short *yysslim; YYSTYPE *yyvs; int yystacksize; #line 310 "parse.y" yyerror(s) char *s; { fprintf(stderr, "parse error in line %d: %s\n", lineno, s); exit(1); } #line 267 "parse.c" /* allocate initial stack or double stack size, up to YYMAXDEPTH */ static int yygrowstack() { int newsize, i; short *newss; YYSTYPE *newvs; if ((newsize = yystacksize) == 0) newsize = YYINITSTACKSIZE; else if (newsize >= YYMAXDEPTH) return -1; else if ((newsize *= 2) > YYMAXDEPTH) newsize = YYMAXDEPTH; i = yyssp - yyss; if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL) return -1; yyss = newss; yyssp = newss + i; if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL) return -1; yyvs = newvs; yyvsp = newvs + i; yystacksize = newsize; yysslim = yyss + newsize - 1; return 0; } #define YYABORT goto yyabort #define YYREJECT goto yyabort #define YYACCEPT goto yyaccept #define YYERROR goto yyerrlab int yyparse() { register int yym, yyn, yystate; #if YYDEBUG register const char *yys; if ((yys = getenv("YYDEBUG"))) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; } #endif yynerrs = 0; yyerrflag = 0; yychar = (-1); if (yyss == NULL && yygrowstack()) goto yyoverflow; yyssp = yyss; yyvsp = yyvs; *yyssp = yystate = 0; yyloop: if ((yyn = yydefred[yystate])) goto yyreduce; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, yystate, yychar, yys); } #endif } if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { #if YYDEBUG if (yydebug) printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, yystate, yytable[yyn]); #endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; yychar = (-1); if (yyerrflag > 0) --yyerrflag; goto yyloop; } if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { yyn = yytable[yyn]; goto yyreduce; } if (yyerrflag) goto yyinrecovery; #if defined(lint) || defined(__GNUC__) goto yynewerror; #endif yynewerror: yyerror("syntax error"); #if defined(lint) || defined(__GNUC__) goto yyerrlab; #endif yyerrlab: ++yynerrs; yyinrecovery: if (yyerrflag < 3) { yyerrflag = 3; for (;;) { if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) { #if YYDEBUG if (yydebug) printf("%sdebug: state %d, error recovery shifting\ to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); #endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; goto yyloop; } else { #if YYDEBUG if (yydebug) printf("%sdebug: error recovery discarding state %d\n", YYPREFIX, *yyssp); #endif if (yyssp <= yyss) goto yyabort; --yyssp; --yyvsp; } } } else { if (yychar == 0) goto yyabort; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, error recovery discards token %d (%s)\n", YYPREFIX, yystate, yychar, yys); } #endif yychar = (-1); goto yyloop; } yyreduce: #if YYDEBUG if (yydebug) printf("%sdebug: state %d, reducing by rule %d (%s)\n", YYPREFIX, yystate, yyn, yyrule[yyn]); #endif yym = yylen[yyn]; yyval = yyvsp[1-yym]; switch (yyn) { case 1: #line 54 "parse.y" { struct character *charp; int i; /* * find max box for window size */ font.maxbbx.w = font.maxbbx.h = 0; for (i=0, charp=font.characters; ibbx.w > font.maxbbx.w) font.maxbbx.w = charp->bbx.w; if (charp->bbx.h > font.maxbbx.h) font.maxbbx.h = charp->bbx.h; } } break; case 3: #line 75 "parse.y" { font.rev = yyvsp[-3].ival; font.subrev = yyvsp[-1].ival; font.szcomments = INC_COMMENTS; font.ncomments = 0; font.comments = (char **) malloc(font.szcomments * sizeof(char *)); if (font.rev != 2 || font.subrev != 1) fprintf(stderr, "WARNING: font is not rev 2.1\n"); } break; case 11: #line 99 "parse.y" { if (font.ncomments == font.szcomments) { font.szcomments += INC_COMMENTS; font.comments = (char **) realloc( (char *) font.comments, font.szcomments * sizeof(char *)); } font.comments[font.ncomments++] = yyvsp[-1].sval; } break; case 12: #line 111 "parse.y" { font.fontname = yyvsp[-1].sval; } break; case 13: #line 117 "parse.y" { font.sizes[0] = yyvsp[-3].ival; font.sizes[1] = yyvsp[-2].ival; font.sizes[2] = yyvsp[-1].ival; } break; case 14: #line 125 "parse.y" { font.boundingbox.w = yyvsp[-4].ival; font.boundingbox.h = yyvsp[-3].ival; font.boundingbox.x = yyvsp[-2].ival; font.boundingbox.y = yyvsp[-1].ival; } break; case 16: #line 137 "parse.y" { font.nprops = yyvsp[-1].ival; font.props = (char **) malloc(font.nprops * sizeof(char *)); npropCounted = 0; } break; case 21: #line 154 "parse.y" { if (npropCounted < font.nprops) { font.props[npropCounted] = yyvsp[-1].sval; } npropCounted++; } break; case 22: #line 163 "parse.y" { if (font.nprops != npropCounted) fprintf(stderr, "Warning: STARTPROPERTIES said %d, counted %d properties, skipping excess\n", font.nprops, npropCounted); } break; case 24: #line 175 "parse.y" { font.nchars = yyvsp[-1].ival; font.characters = (struct character *) malloc(sizeof(struct character) * yyvsp[-1].ival); charp = font.characters; } break; case 27: #line 188 "parse.y" { charp->charId = yyvsp[-5].sval; charp++; } break; case 34: #line 205 "parse.y" { charp->encoding = yyvsp[-1].ival; charp->notadobe = 0; } break; case 35: #line 210 "parse.y" { if (yyvsp[-2].ival != -1) { fprintf(stderr, "Bad ENCODING syntax in line %d", lineno); } charp->notadobe = 1; charp->encoding = yyvsp[-1].ival; } break; case 36: #line 221 "parse.y" { charp->swidth[0] = yyvsp[-1].ival; charp->swidth[1] = 0; } break; case 37: #line 226 "parse.y" { charp->swidth[0] = yyvsp[-2].ival; charp->swidth[1] = yyvsp[-1].ival; } break; case 38: #line 233 "parse.y" { charp->dwidth[0] = yyvsp[-1].ival; charp->dwidth[1] = 0; } break; case 39: #line 238 "parse.y" { charp->dwidth[0] = yyvsp[-2].ival; charp->dwidth[1] = yyvsp[-1].ival; } break; case 40: #line 245 "parse.y" { int w, h; charp->bbx.w = yyvsp[-4].ival; charp->bbx.h = yyvsp[-3].ival; charp->bbx.x = yyvsp[-2].ival; charp->bbx.y = yyvsp[-1].ival; w = (charp->bbx.x < 0) ? charp->bbx.w : charp->bbx.x + charp->bbx.w; h = (charp->bbx.y < 0) ? charp->bbx.h : charp->bbx.y + charp->bbx.h; if (charp->bbx.x < minx) minx = charp->bbx.x; if (w > maxx) maxx = w; if (charp->bbx.y < miny) miny = charp->bbx.y; if (h > maxy) maxy = h; } break; case 41: #line 268 "parse.y" { int i; charp->nrows = nrows; charp->rows = (char **)malloc(sizeof(char *) * nrows); for (i=0; irows[i] = bits[i]; } break; case 42: #line 279 "parse.y" { nrows = 0; } break; case 44: #line 286 "parse.y" { if (nrows >= MAXROWS) { fprintf(stderr, "Too many rows. Max %d\n", MAXROWS); exit(1); } bits[nrows++] = yyvsp[-1].sval; } break; case 45: #line 297 "parse.y" { /* this is a kludge - sorry */ stringMode = 1; } break; case 46: #line 304 "parse.y" { stringMode = 0; } break; #line 655 "parse.c" } yyssp -= yym; yystate = *yyssp; yyvsp -= yym; yym = yylhs[yyn]; if (yystate == 0 && yym == 0) { #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state 0 to\ state %d\n", YYPREFIX, YYFINAL); #endif yystate = YYFINAL; *++yyssp = YYFINAL; *++yyvsp = yyval; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, YYFINAL, yychar, yys); } #endif } if (yychar == 0) goto yyaccept; goto yyloop; } if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yystate) yystate = yytable[yyn]; else yystate = yydgoto[yym]; #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state %d \ to state %d\n", YYPREFIX, *yyssp, yystate); #endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate; *++yyvsp = yyval; goto yyloop; yyoverflow: yyerror("yacc stack overflow"); yyabort: return (1); yyaccept: return (0); }