home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
gdead.berkeley.edu
/
gdead.berkeley.edu.tar
/
gdead.berkeley.edu
/
pub
/
cad-tools
/
ciftomann.tar
/
CD
/
parser.h
< prev
next >
Wrap
C/C++ Source or Header
|
1988-01-28
|
7KB
|
243 lines
/*
* parser.h
*
* Copyright -C- 1981 Kenneth H. Keller, Giles C. Billingsley
* sccsid "%W% %G%"
*
* KIC is a graphics editor that was developed by the integrated
* circuits group of the Electronics Research Laboratory and the
* Department of Electrical Engineering and Computer Sciences at
* the University of California, Berkeley, California. The program
* KIC is available free of charge to any interested party.
* The sale, resale, or use of this program for profit without the
* express written consent of the Department of Electrical Engineering
* and Computer Sciences, University of California, Berkeley, California,
* is forbidden.
*/
/*
* Fast CIF parser's data structures.
*
*/
#include "macros.h"
#include <stdio.h>
/*
* 24*80+1=1921 characters of string.
*/
#define PSTRINGSIZE 1921
/*
* Status of parse when parser returns.
*/
char PStatus[80*3+1];
/*
* CIF file desc.
*/
FILE *PCIFFileDesc;
/*
* string for input line buffering
*/
char PString[PSTRINGSIZE];
/*
* Global token variables.
*/
int PChar;
int PInt;
int PReturned;
/*
* Ousterhout's path package.
*/
FILE *POpen();
/*
* Values routines return.
*/
#define PSUCCEEDED 1 /* successful return */
#define PFAILED 2 /* parser failed */
#define PNOTAPPLICABLE 3 /* parser failed due to syntax */
/*
* Arguments to handle an EOF in PCharacter and PInteger
*/
#define PFAILONEOF 1
#define PDONTFAILONEOF 2
/*
* Arguments to specify characters to be ignored by PWhiteSpace
*/
#define PSTRIPWHITESPACE1 1 /* strip blanks, tabs, commas, or */
/* new lines. */
#define PSTRIPWHITESPACE2 2 /* strip everything but upper case, */
/* hyphens, digits, parens, and ;'s. */
#define PSTRIPWHITESPACE3 3 /* strip everything but digits, */
/* hyphens, parens, and ;'s. */
#define PLEAVEWHITESPACE 4
#define PCharacter(Returned,WhiteSpaceControl,EOFControl){ \
/* PWhiteSpace returns either PSUCCEEDED or PFAILED */ \
PWhiteSpace(Returned,WhiteSpaceControl,EOFControl); \
if(Returned != PFAILED){ \
PChar = getc(PCIFFileDesc); \
if(PChar == EOF){ \
if(EOFControl != PDONTFAILONEOF) { \
PErrorEOF(); \
Returned = PFAILED; \
} \
} \
} \
}
#define PWhiteSpace(Returned,WhiteSpaceControl,EOFControl){ \
Returned = PSUCCEEDED; \
if(WhiteSpaceControl == PSTRIPWHITESPACE1){ \
while((PChar = getc(PCIFFileDesc)) == ' ' Or PChar == '\t' Or \
PChar == '\n' Or PChar == ','){ \
if(PChar == EOF){ \
if(EOFControl != PDONTFAILONEOF){ \
PErrorEOF(); \
Returned = PFAILED; \
} \
break; \
} \
} \
ungetc((char)PChar,PCIFFileDesc); \
} \
elif(WhiteSpaceControl == PSTRIPWHITESPACE2){ \
while((PChar = getc(PCIFFileDesc)) != '-' And PChar != '(' \
And PChar != ')' And (PChar < 'A' Or PChar > 'Z') \
And (PChar < '0' Or PChar > '9') And PChar != ';'){ \
if(PChar == EOF){ \
if(EOFControl != PDONTFAILONEOF) { \
PErrorEOF(); \
Returned = PFAILED; \
} \
break; \
} \
} \
ungetc((char)PChar,PCIFFileDesc); \
} \
elif(WhiteSpaceControl == PSTRIPWHITESPACE3){ \
while((PChar = getc(PCIFFileDesc)) != '-' And PChar != '(' \
And PChar != ')' And (PChar< '0' Or PChar > '9') And \
PChar != ';'){ \
if(PChar == EOF){ \
if(EOFControl != PDONTFAILONEOF){ \
PErrorEOF(); \
Returned = PFAILED; \
} \
break; \
} \
} \
ungetc((char)PChar,PCIFFileDesc); \
} \
}
#define PWhiteSpace1(Returned,EOFControl){ \
Returned = PSUCCEEDED; \
while((PChar = getc(PCIFFileDesc)) == ' ' Or PChar == '\t' Or \
PChar == '\n' Or PChar == ','){ \
if(PChar == EOF){ \
if(EOFControl != PDONTFAILONEOF){ \
PErrorEOF(); \
Returned = PFAILED; \
} \
break; \
} \
} \
ungetc((char)PChar,PCIFFileDesc); \
}
#define PWhiteSpace2(Returned,EOFControl){ \
Returned = PSUCCEEDED; \
while((PChar = getc(PCIFFileDesc)) != '-' And PChar != '(' \
And PChar != ')' And (PChar < 'A' Or PChar > 'Z') \
And (PChar < '0' Or PChar > '9') And PChar != ';'){ \
if(PChar == EOF){ \
if(EOFControl != PDONTFAILONEOF) { \
PErrorEOF(); \
Returned = PFAILED; \
} \
break; \
} \
} \
ungetc((char)PChar,PCIFFileDesc); \
}
#define PWhiteSpace3(Returned,EOFControl){ \
Returned = PSUCCEEDED; \
while((PChar = getc(PCIFFileDesc)) != '-' And PChar != '(' \
And PChar != ')' And (PChar< '0' Or PChar > '9') And \
PChar != ';'){ \
if(PChar == EOF){ \
if(EOFControl != PDONTFAILONEOF){ \
PErrorEOF(); \
Returned = PFAILED; \
} \
break; \
} \
} \
ungetc((char)PChar,PCIFFileDesc); \
}
#define PLookAhead(Returned, WhiteSpaceControl, For){ \
/* PCharaceter will return either PSUCCEEDED or PFAILED */ \
PCharacter(Returned,WhiteSpaceControl,PFAILONEOF); \
if(PChar != For && Returned != PFAILED){ \
ungetc((char)PChar,PCIFFileDesc); \
} \
}
#define PLookForSemi(Returned){ \
/* PWhiteSpace returns either PSUCCEEDED or PFAILED */ \
PWhiteSpace3(Returned,PFAILONEOF); \
if(Returned != PFAILED){ \
PChar = getc(PCIFFileDesc); \
if(PChar == EOF){ \
PErrorEOF(); \
Returned = PFAILED; \
} \
elif(PChar != ';'){ \
ungetc((char)PChar,PCIFFileDesc); \
} \
} \
}
#define PInteger(Returned,EOFControl) { \
loop{ \
PWhiteSpace3(PReturned,EOFControl); \
if(PReturned == PFAILED){ \
Returned = PFAILED; \
break; \
} \
if((PChar >= '0' And PChar <= '9') Or \
(PChar == '-' Or PChar == '+')) { \
/* read integer */ \
if((fscanf(PCIFFileDesc,"%d",&PInt)) == EOF){ \
if(EOFControl != PDONTFAILONEOF){ \
PChar = EOF; \
PErrorEOF(); \
Returned = PFAILED; \
} \
} \
Returned = PSUCCEEDED; \
break; \
} \
/* drop unwanted characters */ \
PCharacter(PReturned,PSTRIPWHITESPACE1,EOFControl); \
if(PReturned == PFAILED){ \
Returned = PFAILED; \
break; \
} \
} \
}