1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
|
/*************************************************************
Copyright (C) 1990, 1991, 1993 Andy C. Hung, all rights reserved.
PUBLIC DOMAIN LICENSE: Stanford University Portable Video Research
Group. If you use this software, you agree to the following: This
program package is purely experimental, and is licensed "as is".
Permission is granted to use, modify, and distribute this program
without charge for any purpose, provided this license/ disclaimer
notice appears in the copies. No warranty or maintenance is given,
either expressed or implied. In no event shall the author(s) be
liable to you or a third party for any special, incidental,
consequential, or other damages, arising out of the use or inability
to use the program for any purpose (or the loss of data), even if we
have been advised of such possibilities. Any public reference or
advertisement of this source code should refer to it as the Portable
Video Research Group (PVRG) code, and not by any author(s) (or
Stanford University) name.
*************************************************************/
%option yylineno
%{
/*LABEL lexer.c */
/*
* flex command was run this way:
*
* $ lex -olexer.c lexer.l
*/
/* We do not care of interactive mode */
#define YY_NEVER_INTERACTIVE 1
#define YY_NO_UNPUT 1
/* Do not include unistd.h in generated source. */
#define YY_NO_UNISTD_H
/* Skip declaring this function. It is a macro. */
#define YY_SKIP_YYWRAP
/* Redefine the yywrap so that we don't have
to worry about lex library */
# define yywrap() (1)
static char *ReservedWords[] = { /* Token names */
"COMPONENT",
"SCAN",
"QUANTIZATION",
"DCSPEC",
"ACCUSTOM",
"DCCUSTOM",
"PRINTSCAN",
"PRINTFRAME",
"PRINTIMAGE",
"OPENSCAN",
"ACSPEC",
"WRITESCAN",
"WRITEFRAME",
"WRITESOI",
"WRITEQUANTIZATION",
"WRITERESYNC",
"WRITEHUFFMAN",
"FREQUENCY",
"ACSEND",
"DCSEND",
"QSEND",
"STREAMNAME",
"IMAGEHEIGHT",
"IMAGEWIDTH",
"RESYNC",
"BUFFER",
"OPENSTREAM",
"CLOSESTREAM",
"FRAMEHEIGHT",
"FRAMEWIDTH",
"CLOSESCAN",
"WRITEEOI",
"ECHO",
"WRITESPECIAL",
"WRITEDIRECT",
"LUMINANCEDEFAULT",
"CHROMINANCEDEFAULT",
"ENABLE",
"SCANDNL",
"WRITEDNL",
"AUTO",
"EMPTY",
""};
#define R_COMPONENT 1 /* Token values mapped to token names */
#define R_SCAN 2
#define R_QUANTIZATION 3
#define R_DCSPEC 4
#define R_ACCUSTOM 5
#define R_DCCUSTOM 6
#define R_PRINTSCAN 7
#define R_PRINTFRAME 8
#define R_PRINTIMAGE 9
#define R_OPENSCAN 10
#define R_ACSPEC 11
#define R_WRITESCAN 12
#define R_WRITEFRAME 13
#define R_WRITESOI 14
#define R_WRITEQUANTIZATION 15
#define R_WRITERESYNC 16
#define R_WRITEHUFFMAN 17
#define R_FREQUENCY 18
#define R_ACSEND 19
#define R_DCSEND 20
#define R_QSEND 21
#define R_STREAMNAME 22
#define R_IMAGEHEIGHT 23
#define R_IMAGEWIDTH 24
#define R_RESYNC 25
#define R_BUFFER 26
#define R_OPENSTREAM 27
#define R_CLOSESTREAM 28
#define R_FRAMEHEIGHT 29
#define R_FRAMEWIDTH 30
#define R_CLOSESCAN 31
#define R_WRITEEOI 32
#define R_ECHO 33
#define R_WRITESPECIAL 34
#define R_WRITEDIRECT 35
#define R_LUMINANCEDEFAULT 36
#define R_CHROMINANCEDEFAULT 37
#define R_ENABLE 38
#define R_SCANDNL 39
#define R_WRITEDNL 40
#define R_AUTO 41
#define R_EMPTY 42
#define R_INTEGER 1000 /* Special TYPES for tokens */
#define R_LBRACKET 1001
#define R_RBRACKET 1002
#define R_ID 1003
#define R_STRING 1004
int CommentDepth = 0; /* depth of comment nesting */
int yyint=0; /* Return value for integers */
int LexDebug=0; /* Status of lex debugging */
#define PRIME 211
#define EOS '\0'
#define MakeStructure(S) (S *) malloc(sizeof(S))
#define InsertLink(link,list){\
if(!list){list=link;}else{link->next=list;list=link;}}
#define LINK struct link_def
struct id { /* Default id structure */
char *name; /* Key */
int tokentype; /* Token type */
int count; /* Count of # references */
};
LINK { /* A link for the hash buckets */
struct id *lid; /* Current id */
LINK *next; /* Pointer to next id */
};
/*PUBLIC*/
extern void initparser();
extern void parser();
static int hashpjw();
static LINK * MakeLink();
static struct id * enter();
static int getint();
static char * getstr();
/*PRIVATE*/
/*NOPROTO*/
%}
Delim [ \t\n]
WhiteSpace {Delim}+
Letter [a-zA-Z]
Digit [0-9]
HexDigit ({Digit}|[a-fA-F])
OctalDigit [0-7]
Id {Letter}({Letter}|{Digit})*
DecInteger {Digit}+
HexInteger 0[xX]{HexDigit}+
OctInteger 0[oO]{OctalDigit}+
HexInteger2 {HexDigit}+[Hh]
OctInteger2 {OctalDigit}+[BCObco]
CharInteger '([^\\]|\\([\n^\n]|{OctalDigit}{1,3}))'
ScaleFactor E[-+]?{Digit}+
Real1 ({Digit}+"."{Digit}*({ScaleFactor})?)
Real2 ({Digit}*"."{Digit}+({ScaleFactor})?)
Real3 ({Digit}+{ScaleFactor})
Real {Real1}|{Real2}|{Real3}
Operator (\+|=|\-|#|\*|\<|\>|\/|:=|\<\>|\&|\<=|\.|\>=|\,|\.\.|;|:|\(|\)|\[|\]|\{|\}|\^|\||~)
String \"([^\"]|\\\")*\"
%S NORMAL COMMENT
%%
<NORMAL>{WhiteSpace} {}
<NORMAL>{Id} {struct id *temp; temp = enter(0,yytext,yyleng);
if (LexDebug)
{
printf("%s : %s (%d)\n",
yytext,
((temp->tokentype) ? "RESERVED" : "IDENTIFIER"),
temp->count);
}
if (temp->tokentype)
{
return(temp->tokentype);
}
else
{
return(R_ID);
}
}
<NORMAL>{Real} {if (LexDebug)
{
printf("%s : %s\n", yytext, "REAL");
}
}
<NORMAL>{DecInteger} {if (LexDebug)
{
printf("%s : %s\n", yytext, "INTEGER");
}
yyint = atoi(yytext);
return(R_INTEGER);}
<NORMAL>{HexInteger} {if (LexDebug)
{
printf("%s : %s\n", yytext, "(HEX)INTEGER");
}
yyint = strtol(yytext+2,NULL,16);
return(R_INTEGER);}
<NORMAL>{HexInteger2} {if (LexDebug)
{
printf("%s : %s\n", yytext, "(HEX)INTEGER");
}
yyint = strtol(yytext,NULL,16);
return(R_INTEGER);}
<NORMAL>{OctInteger} {if (LexDebug)
{
printf("%s : %s\n", yytext, "(OCT)INTEGER");
}
yyint = strtol(yytext+2,NULL,8);
return(R_INTEGER);}
<NORMAL>{OctInteger2} {if (LexDebug)
{
printf("%s : %s\n", yytext, "(OCT)INTEGER");
}
yyint = strtol(yytext,NULL,8);
return(R_INTEGER);}
<NORMAL>{CharInteger} {if (LexDebug)
{
printf("%s : %s\n", yytext, "(CHAR)INTEGER");
}
if (yyleng>4)
{
yyint = strtol(yytext+2,NULL,8);
}
else
{
if (*(yytext+1)=='\\')
{
switch(*(yytext+2))
{
case '0':
yyint=0;
break;
case 'b':
yyint = 0x8;
break;
case 'i':
yyint = 0x9;
break;
case 'n':
yyint = 0xa;
break;
case 'v':
yyint = 0xb;
break;
case 'f':
yyint = 0xc;
break;
case 'r':
yyint = 0xd;
break;
default:
yyint=(*yytext+2);
break;
}
}
else
{
yyint = *(yytext+1);
}
}
return(R_INTEGER);}
<NORMAL>\[ {if (LexDebug)
{
printf("%s : %s\n", yytext, "LBRACKET");
}
return(R_LBRACKET);}
<NORMAL>\] {if (LexDebug)
{
printf("%s : %s\n", yytext, "RBRACKET");
}
return(R_RBRACKET);}
<NORMAL>{Operator} {if (LexDebug)
{
printf("%s : %s\n", yytext, "OPERATOR");
}
}
<NORMAL>{String} {if (LexDebug)
{
printf("%s : %s\n", yytext, "STRING");
}
return(R_STRING);}
<NORMAL,COMMENT>"/*" {CommentDepth++; BEGIN COMMENT;}
<COMMENT>"*/" {CommentDepth--;if(!CommentDepth) BEGIN NORMAL;}
<NORMAL>. {
/* None of the above rules applicable, so
it's a bad symbol. */
printf("Bad input char '%c' on line %d\n",
yytext[0],
yylineno);
}
<COMMENT>.|\n {} /*Everything's AOK */
%%
/*PROTO*/
LINK *HashTable[PRIME]; /* My little hash table */
/*START*/
/*BFUNC
initparser() is used to place the Reserved Words into the hash table.
It must be called before the parser command is called.
EFUNC*/
void initparser()
{
char i,**sptr;
BEGIN NORMAL;
for(i=1,sptr=ReservedWords;**sptr!='\0';i++,sptr++)
{ /* Add Reserved Words */
enter(i,*sptr,strlen(*sptr)); /* Put reserved words in */
} /* hash table */
}
#undef BEGIN
#undef MakeStructure
#include "globals.h"
#include "stream.h"
#include "tables.h"
extern FRAME *CFrame;
extern IMAGE *CImage;
extern SCAN *CScan;
extern int ErrorValue;
/*BFUNC
hashpjw() returns a hash value for a string input.
EFUNC*/
static int hashpjw(s)
char *s;
{
BEGIN("hashpjw")
char *p;
unsigned int g, h;
h=0;
for(p=s;*p!=EOS;p++) /* Taken from Aho Sethi Ullman Compilers book. */
{
h = (h << 4) + *p;
if ((g = h&0xf0000000))
{
h = h ^(g >> 24);
h = h ^ g;
}
}
return(h % PRIME);
}
/*BFUNC
MakeLink() is used to construct a link object. The link
is used for the hash table construct.
EFUNC*/
static LINK *MakeLink(tokentype,str,len)
int tokentype;
char *str;
int len;
{
BEGIN("MakeLink")
LINK *temp;
if (!(temp = MakeStructure(LINK))) /* Make link */
{
WHEREAMI();
printf("Cannot make a LINK.\n");
exit(ERROR_MEMORY);
}
if (!(temp->lid = MakeStructure(struct id))) /* Make id */
{
printf("Cannot make an id.\n");
exit(ERROR_MEMORY);
}
temp->next = NULL; /* Set fields */
if (!(temp->lid->name =(char *)calloc(len+1,sizeof(char))))
{
printf("Cannot make a string space for the link.\n");
exit(ERROR_MEMORY);
}
strcpy(temp->lid->name,str); /* Copy key */
temp->lid->tokentype = tokentype;
temp->lid->count = 1;
return(temp);
}
/*BFUNC
enter() is used to enter a Reserved Word or ID into the hash table.
EFUNC*/
static struct id *enter(tokentype,str,len)
int tokentype;
char *str;
int len;
{
BEGIN("enter")
int hashnum;
LINK *temp,*current;
char *ptr;
for(ptr=str;*ptr!='\0';ptr++) /* All capitals is fine */
{
if ((*ptr>='a') && (*ptr<='z'))
{
*ptr = *ptr - ('a'-'A');
}
}
hashnum = hashpjw(str); /* Check if in hash table */
for(temp=NULL,current=HashTable[hashnum];
current!= NULL;
current=current->next)
{
if (strcmp(str,current->lid->name) == 0)
{
temp=current;
break;
}
}
if (temp) /* Yes, found ID then return */
{
temp->lid->count++;
return(temp->lid);
}
else /* Else make our own ID and return that*/
{
temp = MakeLink(tokentype,str,len);
InsertLink(temp,HashTable[hashnum]);
return(temp->lid);
}
}
/*BFUNC
getint() takes an integer from the input.
EFUNC*/
static int getint()
{
BEGIN("getint")
int type;
if ((type=yylex())!=R_INTEGER)
{
printf("Bad input, not integer, '%s' on line %d\n",
yytext,
yylineno);
return(0);
}
return(yyint);
}
/*BFUNC
getstr() gets a string from the input. It copies the string to
temporary storage before it returns the pointer.
EFUNC*/
static char *getstr()
{
BEGIN("getstr")
char *tmp,*ptr,*bptr;
int i,accum,flag;
if (yylex() != R_STRING) /* Check if string */
{
printf("String expected.\n");
if (!(tmp=(char *) malloc(sizeof(char))))
{
WHEREAMI();
printf("Cannot allocate for null string.\n");
exit(ERROR_MEMORY);
}
*tmp='\0';
return(tmp);
}
if (!(tmp=(char *)calloc(strlen(yytext)+1,sizeof(char)))) /* Make space */
{
WHEREAMI();
printf("Cannot allocate %d string space.\n",yyleng);
exit(ERROR_MEMORY);
}
for(bptr=yytext+1,ptr=tmp;*bptr!='"';bptr++,ptr++) /* Copy to string */
{
if (*bptr=='\\')
{
bptr++;
for(flag=0,accum=0,i=0;i<3;i++) /* Octal character lookahead */
{
if ((*bptr>='0')&&(*bptr<='7'))
{
accum = (accum<<3)+(*bptr-'0');
bptr++;
flag=1;
}
else
{
break;
}
}
if (flag)
{
bptr--;
*ptr=accum;
}
else /* Do conversions, if necessary */
{
switch(*(bptr))
{
case '0':
*ptr = 0;
break;
case 'b':
*ptr = 0x8;
break;
case 'i':
*ptr = 0x9;
break;
case 'n':
*ptr = 0xa;
break;
case 'v':
*ptr = 0xb;
break;
case 'f':
*ptr = 0xc;
break;
case 'r':
*ptr = 0xd;
break;
default:
*ptr=(*bptr);
}
}
}
else
{
*ptr = (*bptr);
}
}
*ptr='\0';
return(tmp);
}
/*BFUNC
parser() handles all of the parsing required for the Command
Interpreter. It is basically a while statement with a very large case
statement for every input. The Command Interpreter is essentially
driven by the keywords. All unmatched values such as integers,
strings, and brackets, are ignored.
EFUNC*/
#define ARRAYBEGIN if (ntoken==R_LBRACKET)\
{\
arrayflag=1;\
ntoken=yylex();\
}\
if (ntoken!=R_INTEGER)\
{\
WHEREAMI();\
printf("Expected integer.\n");\
break;\
}\
while(1)\
{
#define ARRAYEND if (arrayflag)\
{\
if ((ntoken=yylex())==R_RBRACKET) break;\
else if (ntoken!=R_INTEGER)\
{\
WHEREAMI();\
printf("Expected integer or right bracket.\n");\
break;\
}\
}\
else break;\
}
void parser()
{
BEGIN("parser")
int i,dest,value,token,ntoken,arrayflag;
int accum;
int Start,End;
int *ptr,*ptr2;
while((token=yylex())) /* The code handling is simple enough. */
{ /* just read the code and documentation */
ErrorValue=0; /* book... */
arrayflag=0;
switch(token)
{
case R_ECHO:
printf("%s\n",getstr());
break;
case R_PRINTIMAGE:
PrintImage();
break;
case R_PRINTFRAME:
PrintFrame();
break;
case R_PRINTSCAN:
PrintScan();
break;
case R_COMPONENT:
ntoken=yylex();
ARRAYBEGIN;
dest = yyint;
InBounds(dest,0,MAXIMUM_COMPONENTS-1,"Bad component reference");
if (ErrorValue) break;
if (yylex()!=R_LBRACKET)
{
WHEREAMI();
printf("Expected left bracket.\n");
break;
}
CFrame->ComponentFileName[dest] = getstr();
value=getint();
InBounds(value,0,MAXIMUM_HORIZONTAL_FREQUENCY,
"Bad horizontal frequency");
if (ErrorValue) break;
CFrame->hf[dest]=value;
value=getint();
InBounds(value,0,MAXIMUM_VERTICAL_FREQUENCY,
"Bad vertical frequency");
if (ErrorValue) break;
CFrame->vf[dest]=value;
value=getint();
InBounds(value,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
CFrame->tq[dest]=value;
CFrame->cn[CFrame->GlobalNumberComponents++]=dest;/*Know to use it*/
if (yylex()!=R_RBRACKET)
{
WHEREAMI();
printf("Expected right bracket.\n");
break;
}
ARRAYEND;
break;
case R_SCAN:
CScan->NumberComponents=0;
ntoken=yylex();
ARRAYBEGIN;
if (CScan->NumberComponents>=MAXIMUM_SOURCES)
{
WHEREAMI();
printf("Exceeded number of sources per scan.\n");
break;
}
InBounds(yyint,0,MAXIMUM_COMPONENTS-1,"Bad component reference");
if (ErrorValue) break;
for(i=0;i<CFrame->GlobalNumberComponents;i++) /* Check there */
if (CFrame->cn[i]==yyint) break;
if (i==CFrame->GlobalNumberComponents)
{
WHEREAMI();
printf("Scan index not defined in frame yet.\n");
break;
}
CScan->ci[CScan->NumberComponents] = yyint;
if (yylex()!=R_LBRACKET)
{
WHEREAMI();
printf("Expected left bracket.\n");
break;
}
value=getint();
InBounds(value,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
CScan->td[CScan->NumberComponents]=value;
value=getint();
InBounds(value,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
CScan->ta[CScan->NumberComponents]=value;
CScan->NumberComponents++;
if (yylex()!=R_RBRACKET)
{
WHEREAMI();
printf("Expected right bracket.\n");
break;
}
ARRAYEND;
break;
case R_QUANTIZATION:
ntoken=yylex();
ARRAYBEGIN;
dest = yyint;
InBounds(dest,0,MAXIMUM_DEVICES-1,
"Bad quantization reference.");
if (ErrorValue) break;
ntoken=yylex();
if (ntoken==R_LUMINANCEDEFAULT)
{
CImage->QuantizationMatrices[dest]=LuminanceQuantization;
break;
}
else if (ntoken==R_CHROMINANCEDEFAULT)
{
CImage->QuantizationMatrices[dest]=ChrominanceQuantization;
break;
}
else if (ntoken!=R_LBRACKET)
{
WHEREAMI();
printf("Expected left bracket.\n");
break;
}
CImage->NumberQuantizationMatrices =
MAX(CImage->NumberQuantizationMatrices,(dest+1));
if (!(ptr=(int *)calloc(64,sizeof(int))))
{
WHEREAMI();
printf("Cannot allocate quantization matrix.\n");
exit(ERROR_MEMORY);
}
CImage->NumberQuantizationMatrices =
MAX(CImage->NumberQuantizationMatrices,(dest+1));
CImage->QuantizationMatrices[dest]=ptr;
for(i=0;i<64;i++)
{
ptr[i]=16;
}
for(i=0;i<65;i++,ptr++) /* One additional to force r-bracket */
{
if ((ntoken=yylex())!=R_INTEGER) break;
InBounds(yyint,1,65535,"Integer out of bounds");
if (ErrorValue) yyint=16;
*ptr = yyint;
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected integer or right bracket.\n");
break;
}
ARRAYEND;
break;
case R_ACSEND:
ntoken=yylex();
if (ntoken==R_EMPTY)
{
CScan->NumberACTablesSend = 0;
break;
}
ARRAYBEGIN;
if (CScan->NumberACTablesSend>=MAXIMUM_DEVICES)
{
WHEREAMI();
printf("AC Huffman queue full.\n");
break;
}
InBounds(yyint,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
CScan->sa[CScan->NumberACTablesSend++] = yyint;
ARRAYEND;
break;
case R_DCSEND:
ntoken=yylex();
if (ntoken==R_EMPTY)
{
CScan->NumberDCTablesSend = 0;
break;
}
ARRAYBEGIN;
if (CScan->NumberDCTablesSend>=MAXIMUM_DEVICES)
{
WHEREAMI();
printf("DC Huffman queue full.\n");
break;
}
InBounds(yyint,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
CScan->sd[CScan->NumberDCTablesSend++] = yyint;
ARRAYEND;
break;
case R_QSEND:
ntoken=yylex();
if (ntoken==R_EMPTY)
{
CScan->NumberQTablesSend = 0;
break;
}
ARRAYBEGIN;
if (CScan->NumberQTablesSend>=MAXIMUM_DEVICES)
{
WHEREAMI();
printf("Quantization queue full.\n");
break;
}
InBounds(yyint,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
CScan->sq[CScan->NumberQTablesSend++] = yyint;
ARRAYEND;
break;
case R_STREAMNAME:
CImage->StreamFileName = getstr();
break;
case R_IMAGEWIDTH:
value=getint();
InBounds(value,0,MAXIMUM_IMAGE_WIDTH,"Bad image width");
CFrame->GlobalWidth = value;
break;
case R_IMAGEHEIGHT:
value=getint();
InBounds(value,0,MAXIMUM_IMAGE_HEIGHT,"Bad image height");
CFrame->GlobalHeight = value;
break;
case R_SCANDNL:
ntoken=yylex();
switch(ntoken)
{
case R_AUTO:
CFrame->InsertDnl= -2;
break;
case R_ENABLE:
CFrame->InsertDnl= -1;
break;
case R_INTEGER:
CFrame->InsertDnl = yyint;
break;
default:
WHEREAMI();
printf("Expected integer.\n");
break;
}
break;
case R_FRAMEWIDTH:
ntoken=yylex();
ARRAYBEGIN;
dest = yyint;
InBounds(dest,0,MAXIMUM_COMPONENTS-1,"Bad component destination");
if (ErrorValue) break;
value=getint();
InBounds(value,0,MAXIMUM_IMAGE_WIDTH,"Bad frame width");
if (ErrorValue) break;
CFrame->Width[dest] = value;
ARRAYEND;
break;
case R_FRAMEHEIGHT:
ntoken=yylex();
ARRAYBEGIN;
dest = yyint;
InBounds(dest,0,MAXIMUM_COMPONENTS-1,"Bad component destination");
if (ErrorValue) break;
value=getint();
InBounds(value,0,MAXIMUM_IMAGE_HEIGHT,"Bad frame height");
if (ErrorValue) break;
CFrame->Height[dest] = value;
ARRAYEND;
break;
case R_RESYNC:
value = getint();
InBounds(value,0,MAXIMUM_RESYNC_INTERVAL,"Bad resync interval");
if (ErrorValue) break;
CFrame->ResyncInterval = value;
break;
case R_BUFFER:
value = getint();
InBounds(value,MINIMUM_BUFFERSIZE,
MAXIMUM_BUFFERSIZE,"Bad buffersize");
if (ErrorValue) break;
CFrame->BufferSize = value;
break;
case R_OPENSCAN:
CheckValidity();
CheckBaseline();
ConfirmFileSize();
MakeIob(IOB_BLOCK,O_RDONLY,1);
break;
case R_CLOSESCAN:
for(i=0;i<CScan->NumberComponents;i++) /* Close all components */
{
InstallIob(i);
CloseIob();
}
break;
case R_OPENSTREAM:
if (CImage->StreamFileName)
{
swopen(CImage->StreamFileName,0); /* Index 0 open */
}
else
{
printf("StreamFileName: Null. Failed\n");
}
break;
case R_CLOSESTREAM:
swclose();
break;
case R_FREQUENCY:
JpegFrequencyScan();
break;
case R_WRITESPECIAL:
ntoken=yylex();
ARRAYBEGIN;
value = yyint;
swbytealign();
bputc(0xFF); /* Marker */
bputc(value&0xff);
Start = swtell();
bputw(0);
if (yylex()!=R_LBRACKET)
{
WHEREAMI();
printf("Expected left bracket.\n");
End = swtell();
swseek(Start);
bputw((End-Start) >> 3);
swseek(End);
break;
}
while((ntoken=yylex())==R_INTEGER)
{
bputc(yyint&0xff);
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected integer or right bracket.\n");
End = swtell();
swseek(Start);
bputw((End-Start) >> 3);
swseek(End);
break;
}
End = swtell();
swseek(Start);
bputw((End-Start) >> 3);
swseek(End);
ARRAYEND;
break;
case R_WRITEDIRECT:
swbytealign();
if (yylex()!=R_LBRACKET)
{
WHEREAMI();
printf("Expected left bracket.\n");
break;
}
while((ntoken=yylex())==R_INTEGER)
{
bputc(yyint&0xff);
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected integer or right bracket.\n");
break;
}
break;
case R_WRITESCAN:
JpegEncodeScan();
break;
case R_WRITEFRAME:
MakeConsistentFrameSize(); /* Do it here when everything defined */
WriteSof();
break;
case R_WRITESOI:
WriteSoi();
break;
case R_WRITEEOI:
WriteEoi();
break;
case R_WRITEQUANTIZATION:
WriteDqt();
break;
case R_WRITERESYNC:
WriteDri();
break;
case R_WRITEDNL:
WriteDnl();
break;
case R_WRITEHUFFMAN:
WriteDht();
break;
case R_ACCUSTOM:
ntoken=yylex();
ARRAYBEGIN;
dest = yyint;
InBounds(dest,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
if (yylex()!=R_LBRACKET)
{
WHEREAMI();
printf("Expected left bracket.\n");
break;
}
MakeXhuff();
MakeEhuff();
if (!(ptr=(int *)calloc(257,sizeof(int))))
{
WHEREAMI();
printf("Out of custom frequency space.\n");
exit(ERROR_MEMORY);
}
for(i=0;i<257;i++)
{
ptr[i]=0;
}
while((ntoken=yylex())==R_INTEGER)
{
InBounds(yyint,0,MAXIMUM_SOURCES-1,"Bad frequency reference");
if(ErrorValue) yyint=0;
AddFrequency(ptr,CScan->ACFrequency[yyint]);
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected right bracket.\n");
break;
}
MakeHuffman(ptr);
SetACHuffman(dest);
CImage->NumberACTables =
MAX(CImage->NumberACTables,(dest+1));
ARRAYEND;
break;
case R_DCCUSTOM:
ntoken=yylex();
ARRAYBEGIN;
dest = yyint;
InBounds(dest,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
if (yylex()!=R_LBRACKET)
{
WHEREAMI();
printf("Expected left bracket.\n");
break;
}
MakeXhuff();
MakeEhuff();
if (!(ptr=(int *)calloc(257,sizeof(int))))
{
WHEREAMI();
printf("Out of custom frequency space.\n");
exit(ERROR_MEMORY);
}
for(i=0;i<257;i++)
{
ptr[i]=0;
}
while((ntoken=yylex())==R_INTEGER)
{
InBounds(yyint,0,MAXIMUM_SOURCES-1,"Bad frequency reference");
if(ErrorValue) yyint=0;
AddFrequency(ptr,CScan->DCFrequency[yyint]);
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected right bracket.\n");
break;
}
MakeHuffman(ptr);
SetDCHuffman(dest);
CImage->NumberDCTables =
MAX(CImage->NumberDCTables,(dest+1));
ARRAYEND;
break;
case R_ACSPEC:
ntoken=yylex();
ARRAYBEGIN;
dest = yyint;
InBounds(dest,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
MakeXhuff();
MakeEhuff();
if ((ntoken=yylex())==R_LBRACKET)
{
if (!(ptr=(int *)calloc(38,sizeof(int)))) /* Get bits */
{
WHEREAMI();
printf("Out of custom bits space.\n");
exit(ERROR_MEMORY);
}
for(i=0;i<32;i++)
{
ptr[i]=0;
}
for(accum=0,i=0;i<17;i++) /* First index is bitlength of 1. */
{ /* One additional to force r-bracket. */
ntoken=yylex();
if (ntoken==R_INTEGER)
{
accum+=yyint;
ptr[i]=yyint;
}
else break;
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected integer or right bracket.\n");
break;
}
if (yylex()!=R_LBRACKET) /* Get values */
{
WHEREAMI();
printf("Expected left bracket.\n");
break;
}
if (!(ptr2=(int *)calloc(257,sizeof(int))))
{
WHEREAMI();
printf("Out of custom Huffman value space.\n");
exit(ERROR_MEMORY);
}
for(i=0;i<257;i++)
{
ptr2[i]=0;
}
for(i=0;i<257;i++) /* One additinal to force r-bracket */
{
ntoken=yylex();
if (ntoken==R_INTEGER)
{
ptr2[i]=yyint;
}
else break;
}
if (i!=accum)
{
WHEREAMI();
printf("Number of bitlengths != number of values.");
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected integer or right bracket.\n");
break;
}
SpecifiedHuffman(ptr,ptr2);
}
else if (ntoken==R_CHROMINANCEDEFAULT)
{
SpecifiedHuffman(ChrominanceACBits,ChrominanceACValues);
}
else if (ntoken==R_LUMINANCEDEFAULT)
{
SpecifiedHuffman(LuminanceACBits,LuminanceACValues);
}
else
{
WHEREAMI();
printf("Expected left bracket or ACDEFAULT.\n");
break;
}
SetACHuffman(dest);
CImage->NumberACTables =
MAX(CImage->NumberACTables,(dest+1));
ARRAYEND;
break;
case R_DCSPEC:
ntoken=yylex();
ARRAYBEGIN;
dest = yyint;
InBounds(dest,0,MAXIMUM_DEVICES-1,"Bad device reference");
if (ErrorValue) break;
MakeXhuff();
MakeEhuff();
if ((ntoken=yylex())==R_LBRACKET)
{
if (!(ptr=(int *)calloc(38,sizeof(int)))) /* Get bits */
{
WHEREAMI();
printf("Out of custom bits space.\n");
exit(ERROR_MEMORY);
}
for(i=0;i<32;i++)
{
ptr[i]=0;
}
for(accum=0,i=0;i<17;i++) /* First index is bitlength of 1. */
{ /* 0-16 to force right bracket. */
ntoken=yylex();
if (ntoken==R_INTEGER)
{
accum+=yyint;
ptr[i]=yyint;
}
else break;
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected integer or right bracket.\n");
break;
}
if (yylex()!=R_LBRACKET) /* Get values */
{
WHEREAMI();
printf("Expected left bracket.\n");
break;
}
if (!(ptr2=(int *)calloc(257,sizeof(int))))
{
WHEREAMI();
printf("Out of custom Huffman value space.\n");
exit(ERROR_MEMORY);
}
for(i=0;i<257;i++)
{
ptr2[i]=0;
}
for(i=0;i<257;i++) /*One additional to force r-bracket.*/
{
ntoken=yylex();
if (ntoken==R_INTEGER)
{
ptr2[i]=yyint;
}
else break;
}
if (i!=accum)
{
WHEREAMI();
printf("Number of bitlengths != number of values.");
}
if (ntoken!=R_RBRACKET)
{
WHEREAMI();
printf("Expected integer or right bracket.\n");
break;
}
SpecifiedHuffman(ptr,ptr2);
}
else if (ntoken==R_CHROMINANCEDEFAULT)
{
SpecifiedHuffman(ChrominanceDCBits,ChrominanceDCValues);
}
else if (ntoken==R_LUMINANCEDEFAULT)
{
SpecifiedHuffman(LuminanceDCBits,LuminanceDCValues);
}
else
{
WHEREAMI();
printf("Expected left bracket or DCDEFAULT.\n");
break;
}
SetDCHuffman(dest);
CImage->NumberDCTables =
MAX(CImage->NumberDCTables,(dest+1));
ARRAYEND;
break;
}
}
}
/*NOPROTO*/
/*END*/
|